The cp
command is a Linux command for copying files and directories. Here are some examples of how to use the cp
command:
$ cp file.txt /path/to/destination/directory
This will copy the file file.txt
to the destination directory /path/to/destination/directory
.
$ cp file.txt /path/to/destination/directory/new_file_name.txt
This will copy the file file.txt
to the destination directory /path/to/destination/directory
and rename it to new_file_name.txt
.
$ cp file1.txt file2.txt file3.txt /path/to/destination/directory
This will copy the files file1.txt
, file2.txt
, and file3.txt
to the destination directory /path/to/destination/directory
.
$ cp -r source_directory /path/to/destination/directory
This will copy the directory source_directory
and all of its contents to the destination directory /path/to/destination/directory
. The -r
option tells the cp
command to copy directories recursively.
$ cp -p file.txt /path/to/destination/directory
This will copy the file file.txt
to the destination directory /path/to/destination/directory
and preserve its permissions. The -p
option tells the cp
command to preserve the file's permissions.
$ cp -f file.txt /path/to/destination/directory
This will copy the file file.txt
to the destination directory /path/to/destination/directory
and overwrite an existing file with the same name if it exists. The -f
option tells the cp
command to force the copy operation and overwrite any existing files.
These are just a few examples of how to use the cp
command. There are many other options and features that you can use with the cp
command. You can use the cp --help
command to see a complete list of options and usage examples.