The Linux cp command is mainly used to copy files or directories.
Syntax
Cp [options] source dest
Or
Cp [options] source... directory
Parameter description:
- -A: This option is usually used when copying a directory. It retains the link and file attributes and copies all contents in the directory. The function is equal to the dpR parameter combination.
- -D: The link is retained during replication. The link mentioned here is equivalent to a shortcut in Windows.
- -F: overwrite the existing target file without prompting.
- -I: in contrast to the-f option, a prompt is displayed before overwriting the target file, asking the user to confirm whether to overwrite the file. The target file will be overwritten when "y" is answered.
- -P: in addition to copying the file content, it also copies the modification time and access permissions to the new file.
- -R: if the source file is a directory file, all subdirectories and files under the directory will be copied.
- -L: generate a link file without copying a file.
Instance
Run the command "cp" to copy all files under the current directory "test/" to the new directory "newtest". Run the following command:
$ Cp-r test/newtest
Note: When you use this command to copy a directory, you must use the "-r" or "-R" parameter ".