• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

cp -r without destination directory?

oniq

Banned
I'm sure its right in front of me, but where do the files go if you do a cp -r /blah/blah/* without a destination directory? :\
 
cp (and mv) use the last path as the target.

mv onedir twodir threedir

will move onedir and twodir into threedir/

When you glob using *, it expands into multiple paths, each for a file or directory that matches that pattern. Whichever comes last will be seen by cp as the target to copy to.

(the important thing here is that cp does not expand the glob; your shell does that. cp gets whatever results came from that.)

btw, generally, -R is more proper than -r.
 
Eh.. sitting in front of the computer for long hours?

I didn't even know that -r was a valid option. Gnu cp seems to treat -R and -r the same, but all 3 of the BSDs' man pages do not list -r as an option; instead they say this near the bottom:

Historic versions of the cp utility had a -r option. This implementation
supports that option, however, its use is strongly discouraged, as it
does not correctly copy special files, symbolic links or fifo's.

edit: and here's a simple example of how you can see that the shell expands filenames, not cp:

% echo *.c
blobmodule.c mlist.c mlist2.c mlist3.c mlist4.c mlist5.c

Now if I take out the echo, I can just type the glob, and the shell will then try to execute whatever the first word in the command is:

% *.c
bash: blobmodule.c: command not found
 
Back
Top