What are the differences between cp-an and cp-r in linux
This article mainly introduces the relevant knowledge of "what is the difference between cp-a and cp-r in linux". Xiaobian shows you the operation process through actual cases. The operation method is simple and fast, and practical. I hope this article "what is the difference between cp-a and cp-r in linux" can help you solve the problem.
The difference between "cp-a" and "cp-r" in linux is that the data copied by "cp-a" command retains metadata timestamps and file attributes, while the data copied by "cp-r" command uses new timestamps and other information.
Operating environment: Linux 7.3 system, Dell G3 computer.
What is the difference between CP-A and CP-R in Linux?
Linux cp (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 typically used when copying directories, preserving links, file attributes, and copying everything under 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 under the directory will be copied.
cp -a : Recursive replication, the copied data will retain the timestamp and other information of the original data (specifically: timestamp + ownership + copy link file attributes rather than the file itself)
cp -r : Recursive replication, copied data will use new timestamp and other information
Copy linked file attributes rather than the file itself: e.g. soft link, copy soft link attributes (timestamp etc.) rather than the actual document
For example:
cp -a test.sh test1.sh
Use ls -l to check: both timestamps are consistent
cp -r test.sh test2.sh
Use ls -l to see: the two timestamps are different
The same is true for copy link files:
To summarize briefly:
Using cp -a is equivalent to copying the original data intact without changing any information inside.
Use cp -r to copy data, and the result of copying is to generate new information such as timestamps.
About "what are the differences between cp-a and cp-r in linux" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.