[max@localhost ~]$ mkdir aaa
[max@localhost ~]$ cd aaa
[max@localhost aaa]$ touch 1 2 3
[max@localhost aaa]$ mkdir bbb
[max@localhost aaa]$ touch 3 4 5
[max@localhost aaa]$ cd
This is The content of directory aaa
[max@localhost ~]$ ls -l aaa/
total 4
-rw-rw-r-- 1 max max 0 Oct 19 17:29 1
-rw-rw-r-- 1 max max 0 Oct 19 17:29 2
-rw-rw-r-- 1 max max 0 Oct 19 17:29 3
-rw-rw-r-- 1 max max 0 Oct 19 17:29 4
-rw-rw-r-- 1 max max 0 Oct 19 17:29 5
drwxrwxr-x 2 max max 4096 Oct 19 17:29 bbb
To copy any directory use cp -r
or cp -R
or cp --recursive
command
Here -r
, -R
, --recursive
means copy directories recursively
[max@localhost ~]$ cp -r aaa/ ccc/
[max@localhost ~]$ cd ccc/
[max@localhost ccc]$ ls -l
total 4
-rw-rw-r-- 1 max max 0 Oct 19 17:30 1
-rw-rw-r-- 1 max max 0 Oct 19 17:30 2
-rw-rw-r-- 1 max max 0 Oct 19 17:30 3
-rw-rw-r-- 1 max max 0 Oct 19 17:30 4
-rw-rw-r-- 1 max max 0 Oct 19 17:30 5
drwxrwxr-x 2 max max 4096 Oct 19 17:30 bbb
Here content of directory aaa
is copied to directory ccc
including files and sub directory contents.
are you saying that the above case is what you want to happen, or what is currently happening? Can you rephrase / reformat your question to make this more clear? – Will Palmer – 2012-09-30T20:57:34.187
I want to copy ./work to ./backup, so it will be ./backup/work. I could only come up with the command above, at it moves not "work", but its subfolders, so it looks like ./backup/d1 ("d1" is a subfolder in "work") – None – 2012-09-30T21:07:04.417
In that case, I think that @Petr Baudis's answer is the one you want. – Will Palmer – 2012-09-30T21:08:55.247