Home  >  Article  >  Operation and Maintenance  >  What is the difference between cp-a and cp-r in linux

What is the difference between cp-a and cp-r in linux

WBOY
WBOYOriginal
2022-03-15 14:28:5929422browse

The difference between "cp-a" and "cp-r" in Linux is: the data copied by the "cp-a" command will retain information such as metadata timestamps and file attributes, while "cp-r" "The data copied by the command will use new timestamp and other information.

What is the difference between cp-a and cp-r in linux

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

What is the difference between cp-a and cp-r in Linux

The Linux cp (full English spelling: 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.

  • -r: If the given source file is a directory file, all subdirectories and files in the directory will be copied.

cp -a : Recursive copy, the copied data will retain the timestamp and other information of the original data (specifically: timestamp ownership copy link file attributes rather than files itself)

cp -r: Recursive copy, the copied data will use new timestamp and other information

Copy the link file attributes instead of the file itself: for example, a software For links, the properties of the soft link (timestamp and other information) are copied, rather than the

of the actual document. For example:

cp -a test.sh test1.sh

Use ls -l to view: two The timestamps of the two are the same

cp -r test.sh test2.sh

Usels -l View: the timestamps of the two are different

What is the difference between cp-a and cp-r in linux

The same is true for copying the linked file:

What is the difference between cp-a and cp-r in linux

A brief summary:

Using cp -a is equivalent to copying the original data intact without changing anything inside. Information

Usecp -r to copy data. The result of the copy is to generate new timestamps and other information

Related recommendations: "Linux Video Tutorial

The above is the detailed content of What is the difference between cp-a and cp-r 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