To copy a folder and its contents on a Linux system using the command line, you can use the cp
command with the -r
option. The -r
option stands for "recursive" and allows the cp
command to copy directories and their contents recursively.
For example, to copy a folder source
and its contents to a new folder destination
, you can use the following command:
cp -r source destination
This will create a new folder destination
and copy the contents of the source
folder into it.
You can also specify a path as the destination to copy the folder to a specific location. For example, to copy the source
folder to the /path/to/destination
directory, you can use the following command:
cp -r source /path/to/destination
You can use the -p
option to preserve the file permissions and ownership when copying the folder and its contents:
cp -rp source destination
You can use the -v
option to display verbose output, showing the files as they are copied:
cp -rv source destination
You can use the --help
option to display a list of available options for the cp
command.
Keep in mind that you will need to have appropriate permissions to access the source folder and to create the destination folder, and to copy the files to the destination. You may need to use the sudo
command to gain sufficient privileges.