Linux Copy File Command [ cp Command Examples ]

Linux Copy File Command [ cp Command Examples ]

The cp command is a Linux command used to copy files and directories. It is a standard command that is included with most Linux distributions.

To copy a file, you can use the following syntax:

re‮ ref‬to:lautturi.com
cp source destination

For example, to copy a file file1.txt to a new file file2.txt, you can use the following command:

cp file1.txt file2.txt

You can also copy a file to a different directory by specifying the destination as a directory path:

cp file1.txt /path/to/destination

To copy multiple files at once, you can specify the source files as a list:

cp file1.txt file2.txt file3.txt /path/to/destination

To copy a directory, you can use the -r option to copy the directory and its contents recursively:

cp -r source destination

For example, to copy a directory dir1 to a new directory dir2, you can use the following command:

cp -r dir1 dir2

You can also use the -p option to preserve the file permissions and ownership when copying a file or directory:

cp -p source destination

You can use the -v option to display verbose output, showing the files as they are copied:

cp -v source destination

You can use the --help option to display a list of available options for the cp command.

Created Time:2017-10-16 14:38:52  Author:lautturi