cp file1 somewhere
if somewhere is a directory, cp copies file1 into the directory, leaving its name unchanged. You get a new file whoseis somewhere/file1. A few commands, for example, mv and ln, have the same behavior.
Of course, this version of the command looks the same as a "regular" cp command. This leads to a common frustration: what if the directory somewhere doesn't exist? Maybe you forgot to create it; maybe you misspelled the name. cp doesn't know that you really meant a directory, so it just copies file1 into a new file, somewhere, in the current directory. There are plenty of situations in which this can be plenty confusing, and even (if you're unlucky) lead to errors.
There's an easy safeguard, though. If you're copying files into a
directory, add a slash and dot (
/.) after the directory's
This makes a pathname to thein the directory somewhere-which is a link to the directory itself. If the directory named somewhere doesn't exist, you'll get an error message:
cp file1 somewhere/.cp: somewhere/.: No such file or directory