English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Linux cp Command

Linux Command Manual

The Linux cp (full English name: copy file) 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 directories, it retains links, file attributes, and copies all contents under the directory. Its function is equivalent to the combination of dpR parameters.
  • -d: Keep links when copying. The links referred to here are similar to shortcuts in the Windows system.
  • -f: Overwrite existing target files without prompting.
  • -i: With-f option is the opposite, it prompts the user to confirm whether to overwrite before overwriting the target file, and when the user answers "y", the target file will be overwritten.
  • -p: In addition to copying the content of the file, the modification time and access permissions are also copied to the new file.
  • -r: If the given source file is a directory file, then all subdirectories and files under it will be copied.
  • -l: Do not copy files, only generate link files.

Online Examples

Use the cp command to copy the current directory test/ to copy all files under to the new directory newtest Enter the following command:

$ cp --r test/ newtest          

Note: When using this command to copy directories, the parameter must be used -r or -R .

Linux Command Manual