Linux provides different tools to copy directories entirely. The most popular and well known tool is
cp . In this tutorial we will look how to copy Linux directories entirely or specific contents.
Copy Only Directory
In this first example we will copy only directory. We can just provide the source directory and destination directory names to the
cp command. In this example we will try to copy single directory. As we can see we get an error like below.
$ cp backup newbackup
Copy Entire Directory Recursively
Now here is the real scenario. We will copy our directory named
backup with new named
newbackup . We will use
-r option which makes copy operation recursively. Recursive means sub directories and files will be copied too.
$ cp -r backup newbackup
Copy Special Files
During recursive copy operation special files content will not copied by default. We can copy special file contents with
-b option like below.
$ cp -r -b backup newbackup
During copy operation there will be no sign about current operation. We can made this copy operation verbose where copied files will be printed to the shell. We will use
-v command like below.
$ cp -r -v newbackup oldbackup