I want to copy a directory into another directory.
For example, cp -r dir1 dir2 copies the contents of dir1 into dir2. I want to copy dir1 itself into dir2 so that if I ls dir2 it will output dir1 and not whatever was inside of dir1.
Just do as you did:
cp -r dir1 dir2
and you will have dir1 (with its content as well) inside dir2. Try if you don't believe ;-).
The command that would copy content of dir1 into dir2 is:
cp -r dir1/* dir2
cp -r System\ Volume\ Information test only copies the contents, but if I manually type it out as cp -r "System Volume Information" test then it copies the directory itself and not just the contents. Look at the manual for cp (also mv):
cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... If you do cp a b then if b does not exist you get cp -T a b, but if b exists and is a directory you get cp -t b a, else error.
mkdir empty cd empty mkdir a touch a/a-file cp -r a b #this creates b a copy of a cp -r a b #this time it makes a copy of a called a in b (b/a) mkdir empty cd empty mkdir a touch a/a-file cp -r -T a b #this creates b, a copy of a cp -r -T a b #updates b (no effect in this case) mkdir empty cd empty mkdir a touch a/a-file mkdir b cp -r -t b a #copy a into b cp -r -t b a #updates a/b (no effect in this case) Also, make sure that the first argument (the directory you want to copy) doesn't end with a forward-slash character /. Some versions of cp (for example on MacOS) treat it as /* and copy just the contents of the directory in such case, not the whole directory. And the forward-slash is usually added when you auto-complete the directory name using the Tab key.
Copy the whole directory dir1 into the directory dir2:
cp -r dir1 dir2 Copy the contents of the directory dir1 into the directory dir2:
cp -r dir1/ dir2 It's equivalent to:
cp -r dir1/* dir2