I have a directory, let's say, "work": ~/work/
This directory has some sub-folders (d1, d2...) in it and files in these sub-folders. I want to make a backup copy in the same folder, so it would be like: ~/backup/work/
However, when I use
cp -r ./work ./backup
the folder "work" is not copied, only its subfoders (so now it's ~/backup/d1 ~/backup/d2...)
Any idea how to make it work? I'm quite new to shell, so I'm missing something :)
Tell me more
×
Super User is a question and answer site for
computer enthusiasts and power users. It's 100% free, no registration required.
|
|
|||||||||
|
migrated from stackoverflow.com Oct 1 '12 at 4:27
|
cp will not create leading directories; when it sees a path that does not exist, it will assume that it shall be the new name of the directory being copied. Try copying into a directory that already exists: |
|||
|
|
Try
|
|||
|
or
|
|||
|
[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 [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 Here [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 |
|||
|
|