The cp command in Linux and Unix-like systems stands for “copy.” It is used to create a copy of a file or directory.
Here is the basic syntax for the cp command:
cp [options] source destination
source is the file or directory that you want to copy. destination is the file or directory where you want to create the copy. Here are some examples of the cp command in action:
1. To copy a file called “file1.txt” from the current directory to a directory called “backup”:
$ cp file1.txt backup/
2. To copy a directory called “directory1” and all of its contents to a directory called “backup”:
$ cp -r directory1 backup/
Note: The -r option is used to copy the directory and all of its contents recursively.
3. To copy a file called “file1.txt” and give it a new name “file2.txt”:
$ cp file1.txt file2.txt
4. To copy a file and preserve its permissions, timestamps, and ownership.
$ cp -p file1.txt file2.txt
Note: The -p option is used to preserve the file attributes of the original file.
5. To copy multiple files and directories at once
$ cp file1.txt file2.txt backup/dir1 backup/dir2 backup/
In all the above examples, cp command is used to copy the file or directory from source to destination.