Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In the man page for cp, what is the difference between copying to DEST and DIRECTORY?

cp copies a SOURCE to a DEST and SOURCES to a DIRECTORY.

   SYNOPSIS

   cp [OPTION]... [-T] SOURCE DEST
   cp [OPTION]... SOURCE... DIRECTORY
share|improve this question
add comment

2 Answers

With DEST it is assuming you are naming the file name and path (and therefore directory) of the destination file. With DIRECTORY you are just listing which directory the destination file will be in, while preserving the SOURCE name.

share|improve this answer
add comment

If SOURCE is just one file, the difference depends on what the command finds: If there is a directory DEST, SOURCE is copied into it, preserving the name. If it does not exist or is a file, DEST is interpreted as new name to use, eventually overriding DEST if it is a file.

If you have multiple SOURCES, DEST can only be a directory, since copying multiple files into one dest file would only preserve the last copied file and be rather useless for almost all cases.

A copy command:

cp s1 s2 s3 d1 d2 d3 

would look as if it would make some sense, since an even number of names could match s1 -> d1, s2 -> d2 ... , but think of shell expansion:

cp * 

could result in different interpretation, depending on the number of files matched by *. So if you use multiple files, the last is always assumed to be a directory. If it doesn't exist, you get an error message.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.