Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Standard Behavior' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Standard Behavior
Authored by: forman on Nov 16, '05 07:09:21AM
This is the standard behavior of all command-line utilities, whose behavior varies depending on whether a directory or the contents of a directory are specified. You'll see the same behavior for programs such as mv, scp, rsync, etc.

The brief rule is this: without a trailing slash, the source directory itself is selected; with the trailing slash, the contents of that directory are selected.

Michael.

[ Reply to This | # ]
Standard Behavior
Authored by: signal15 on Nov 16, '05 07:13:10AM

I agree, this is standard (and useful) behavior. In fact, I think it actually is documented somewhere, I seem to remember reading this in some man pages years and years ago. cp has worked like this since at least 1990. :)



[ Reply to This | # ]
Standard Behavior
Authored by: owsla on Nov 16, '05 07:21:42AM

Frankly, if I wanted the files IN the directory, I would do something like:

cp mydirectory/* newdirectory/

Silently deciding that for me if I didn't specify the * is cruel.

That's interesting that non-GNU cp has been like this since 1990. I definitely think the rest of the Unix world should switch over.



[ Reply to This | # ]
Standard Behavior
Authored by: forman on Nov 16, '05 08:03:36AM
Your proposal of eliminating the directory-contents specifier "/" and instead choosing files in a directory manually using syntax such as mydirectory/* has the problem of omitting dot files.

Given that this behavior is a long-standing documented feature, this is not a software problem rather it is a user problem. The point of the parent post is to teach folks a command-line nuance, not call for the rewriting of dozens of applications to conform to the limitations of inexperienced users. Learn the trick and move on. :)

Michael.

[ Reply to This | # ]
Standard Behavior
Authored by: owsla on Nov 16, '05 10:18:10AM

Experience or inexperience isn't the issue ... it's GNU-style vs BSD-style. I've spent eight years in GNU-style environments. The first time BSD cp did this to me was really unnerving.

I just wish there was a way to change the behavior. Installing GNU cp is counter-productive on Tiger (unlike on Panther) because only the Apple-supplied cp has the resource fork patches.



[ Reply to This | # ]
Gnu inconsistent
Authored by: SOX on Nov 16, '05 10:48:01AM

GNU sometimes ignores the slash and sometimes uses the slash to have such behavious. Compare cp and rsync on GNU and you will see what I mean. At least the BSD pattern is consisent. THat said I never did like that confusion over what / does. I have to re-read the rsync manpage every time I use it!



[ Reply to This | # ]
Gnu inconsistent
Authored by: 3oz on Nov 18, '05 07:25:59AM

rsync is not written by the GNU Free Software Foundation. It is licensed with the GPL. GNU bundles many of the basic command line programs like 'cd, cp, mkdir, rm....' but rsync is written by Andrew Tridgell, the same guy that started the Samba project.



[ Reply to This | # ]
UTSL
Authored by: hayne on Nov 16, '05 11:12:43AM
Installing GNU cp is counter-productive on Tiger (unlike on Panther) because only the Apple-supplied cp has the resource fork patches.
Of course you could submit the appropriate patches to the GNU project or the Fink project (or just patch your own version of /sw/bin/cp) The Apple source code for 'cp' is available from www.opensource.apple.com (cp.c is under "file_cmds").
The code that handles the copying of resource forks is in copyfile.c (which is in "Libc")

[ Reply to This | # ]