Reputation: 105
How to copy a directory under a new name, lets say, to make a backup of the directory.
For an example, imagine, there is a folder called 'root'.
inside it, a folder called, 'test' exists, and there are some files and folders existing under the folder 'test'. The present working directory of bash is 'root'
What I want to be done is
Can this be done with a single command? If so, how?
The only way I can think of is creating a new directory named 'test.bak' & copy everything to it, but it takes two commands.
Thank you.
Upvotes: 1
Views: 473
Reputation:
Yes you can. You can use the recursive
- combined with the parent
parameter;
$ cp -RP test test.bak
When with the terminal inside the root
folder.
And when in the parent folder of the root
folder;
$ cp -RP root/test root/test.bak
Or with an absolute path, or in this case, a placeholder call from the user's home folder;
$ cp -RP ~/Desktop/root/test ~/Desktop/root/test.bak
Upvotes: 1