Home >Operation and Maintenance >Linux Operation and Maintenance >What is the difference between the parameters r and R of cp in linux?

What is the difference between the parameters r and R of cp in linux?

WBOY
WBOYOriginal
2022-08-11 18:00:209317browse

Difference: 1. "cp -r" copies both files and folders in the current directory, while "cp -R" only copies files in the current directory and does not copy the current directory. 2. "cp -r" The folder containing files will overwrite the folder with the same name without files, and the files will also be overwritten, while "cp -R" will not overwrite the folder containing the content, but it will overwrite An empty file with the same name; 3. "cp -r" does not use the file suffix name as the basis for identification, but "cp -R" uses the file suffix name as the basis for identification.

What is the difference between the parameters r and R of cp in linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

What is the difference between the parameters r and R of cp in Linux

The difference between the cp -r and -R of the LINUX command is: different copying, different coverage, and different identification basis.

1. Copy different files

  • cp -r: cp -r copies the files in the current directory files, and also copies folders in the current directory.

  • -R: -R only copies files in the current directory, not folders in the current directory.

2. Cover different

  • cp -r: cp -r contains files Folders will overwrite folders with the same name that do not contain files, and files will also be overwritten.

  • -R: -R will not overwrite folders with contents, but will overwrite empty files with the same name.

3. Different identification basis

  • ##cp -r: cp -r does not The file extension name is used as the basis for identification.

  • -R: -R uses the file suffix name as the basis for identification.

Examples are as follows:

What is the difference between the parameters r and R of cp in linux?

Extension:

Linux cp (full spelling in English :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 a directory, it Preserve links, file attributes, and copy all contents of the directory. Its effect is equal to the dpR parameter combination.

  • -d: Keep the link when copying. The links mentioned here are equivalent to shortcuts in Windows systems.

  • -f: Overwrite an existing target file without giving a prompt.

  • -i: Contrary to the -f option, a prompt is given before overwriting the target file, asking the user to confirm whether to overwrite. The target file will be overwritten when answering y.

  • -p: In addition to copying the contents 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, all subdirectories and files in the directory will be copied.

  • -l: Do not copy files, just generate link files.

Recommended learning:

Linux video tutorial

The above is the detailed content of What is the difference between the parameters r and R of cp in linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn