cp command on Linux (copy files)
The most common options are:
- -d: Preserves links when copying files;
- -p: Preserves all file attribute information, such as file owner, group, permissions, and date;
- -R: Copy files recursively. Useful for copying files and directories below the specified directory;
- -a: Does the same as the combined “-dpr” options;
- -f: Forces the copy by writing over the destination;
- -i: Ask the user before copying each file over the destination location;
- -v: Shows the name of each file copied.
Examples:
Copy file1 to file2 in the same directory:
Copy file1 to the /tmp directory:
Copy file1 located in the /tmp directory to the local directory. The symbol “.” (dot) specifies the directory as local:
Copy the entire contents of the /var/log directory, including all subdirectories to the “loglocal” directory: