CentOS common commands for copying files and folders
cp
No1. Copy the file of the specified directory to the current directory and rename it
[[email protected] root]# cp ~/.bashrc bashrc_bak
NO2. Force the file of the specified directory to be copied to the current directory, regardless of whether the current directory contains the file or not
[[email protected] root]# cp -f ~/.bashrc bashrc
NO2. Copy the specified directory to the current directory
[[email protected] root]# cp -r /root/test .
[[email protected] root]# cp -r /root/test/ .
The effect is the same. When copying a directory, the last level directory of the source path will be copied, including itself.
No3. Copy the files of the specified directory to the specified directory
[[email protected] root]# cp ~/.bashrc /bak/.bashrc
If prompted:
cp: omitting directory
Then:
[[email protected] root]# cp -r ~/.bashrc /bak/.bashrc
If prompted:
cp:overwrite
Use slash:
[[email protected] root]# /cp -r -f ~/.bashrc /bak/.bashrc
No4. Copy all the attributes of the source file. If you do not specify parameters, the properties of the target file and the source file may not be consistent.
[[email protected] root]# cp -a ~/.bashrc /bak/.bashrc
No5. If two folders need to be synchronized, one file will be changed and the other will be changed, but the files of both files should be up to date.
[[email protected] root]# cp -u /src/.bashrc /bak_src/bashrc