How to copy the contents of a directory to another directory using Terminal on Ubuntu/Linux machine?
Use the cp
command to copy files from one directory to another directory on a Ubuntu/Linux machine.
The word cp
stands for Copy.
cp -a source/. dest/
The option -a
copy files recursively, preserving the file attributes like timestamps.
The period symbol .
after the source directory path will copy all the files and folders, including the hidden files.
Use the below command to copy the contents of a directory to another directory, in the current working directory.
cp -a assets/. backup/
Use the below command to copy the contents of a directory to another directory from anywhere on the machine, using the absolute path.
cp -a /var/www/assets/. /var/www/backup/
This command does the same thing as the earlier command, the only difference is the usage of an absolute path in this command.
Use relative and absolute paths as needed.
In the below example, the command will copy the contents of the source directory (identified using its relative path from the current working directory) to the destination directory (identified using its absolute path).
cp -a assets/. /var/www/backup/