Hi Bob,
On 2014-03-11 23:58, Bob Proulx wrote:
Filipus Klutiero wrote:
Subject: cp does not copy directories by default
Are you requesting that cp be changed to yes copy directories by default?
Note that cp has never copied directories by default and therefore
cannot now after 40 years of current behavior be changed to do so.
I am not. As you say, I fail to see how the default could be changed reasonably
at this time. What can be done now is to warn about the default, or at least to
prevent misleading users into thinking that directories will be copied by
default.
According to cp(1)'s manpage:
cp - copy files and directories
SYNOPSIS
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
All of those are correct, if terse. I could see suggesting upstream
to add one additional line to make the synopsis more explicit.
cp [OPTION]... [-T] SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... -t DIRECTORY SOURCE...
cp [-R|-a|-r] [OPTION]... DIRECTORY... DIRECTORY
But to my reading though this:
cp [-R|-a|-r] [OPTION]... DIRECTORY... DIRECTORY
Collapses into this:
cp [OPTION]... SOURCE... DIRECTORY
Since [-R|-a|-r] are OPTION and DIRECTORY is SOURCE. And therefore
seem redundant to me.
Right. It could be
cp [-R|-a|-r] [OPTION]... FILE... DIRECTORY
cp [OPTION]... REGULAR-FILE... DIRECTORY
But then, there are more file types than regular files and directories, so that
probably wouldn't be perfect.
I didn't mean to blame the synopsis, it was just part of the relevant part of the manpage. The
problematic parts are the NAME section ("copy files*and directories*") and the
description "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY."
For the full documentation you would need to refer to the info pages.
The info page says this behavior more explicitly.
However, cp has a very particular default behavior with regard to
directories, which are not copied as the info documentation
acknowledges:
By default, `cp' does not copy directories. However, the `-R',
`-a', and `-r' options cause `cp' to copy recursively by descending
into source directories and copying files to corresponding
destination directories.
I am not sure if other file types are also treated specially, but at
least these are not explicitely mentioned in the manpage.
The GNU Project designates the info pages as the full primary
documentation. Many people do not like this but unless someone wants
to fork or rewrite all of the utilities that is the way it is
upstream. The Coreutils project creates man pages as quick reference
documents so that they are not entirely missing. It creates them from
the online --help output.
The challenge for the 'cp --help' online documentation is to keep them
short and concise yet accurately display the required information.
This is then turned into the man page.
I understand the resources challenge. Sometimes vagueness is the only solution.
In the end, we know that most people will use the manpage. cp's manpage may be
incomplete or vague, but it can't afford to mislead readers on a behavior as
fundamental as the treatment of directories.
Note here is the POSIX online documentation on the cp command.
http://pubs.opengroup.org/onlinepubs/009695399/utilities/cp.html
Thanks, this is very interesting. First, the NAME just says "copy files" rather than "copy files and
directories". Some may equate "copy files" with "copy all files", but I do not consider the
POSIX NAME misleading.
Then, the synopsis treats -R as a different form, as you discussed. This has
the advantage of allowing a separate description for the 2 forms.
I have no strong opinion on which approach is preferable. Either 2 forms and 2
descriptions or keeping 1 form with a different description. As long as 1 - we
don't say that cp copies SOURCE to DEST, when SOURCE can't be a directory
without options, or 2 - we add right after a big warning about directories like
the info documentation's.
I would have thought this is an upstream bug, but I didn't manage to
see how the upstream manpage reads
(
http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=man/cp.x;h=b26225fc977e61c31bd5dda9b0d719a64601d528;hb=HEAD
).
Sorry but I didn't understand what you were asking there. That isn't
the man page. That is just the title.
Yes, I just meant that's where I unsuccessfully looked trying to see how the
upstream manpage was.
See this reference for the usage function starting at line 151. This
is the source to the man page.
http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=blob;f=src/cp.c;hb=HEAD
This allows to confirm that the issue is upstream.
Thank you very much
Bob
--
Filipus Klutiero
http://www.philippecloutier.com