cp command instructions

1, Command Overview

cp command can be understood as an abbreviation for the English word copy, whose function is to copy a file or directory (rename).

2, the command syntax

cp [options] [filename or directory name] [destination directory]

3, command options

-f forced to copy a file or directory, regardless of whether the destination file or directory already exists, if the target file already exists, it will directly overwrite the original file.

-i If the target file already exists, you are asked whether to overwrite

-P property to keep the source file or directory, including the owner, owning group, permissions and time

-r recursive processing, the files and subdirectories in the specified directory dealt with together. If the form of the source file or directory, not a directory or a symbolic link, be regarded as an ordinary file handling

-d When copying symbolic link, the target file or directory is also established as a symbolic link pointing to the original file and connected to a source file or directory or directories

-l establish a hard link to the source file, rather than copying files

-s to create a symbolic link to the source file, rather than copying files

-b delete, covering the destination file to back up, back up files or directories also establish a symbolic link, and a link to the source file or directory of the source file or directory. If you do not add this parameter in the replication process if the symbolic link is encountered, it will directly copy the source files or directories

-v display execution process

-a This option is typically used when copying a directory, it retains links, file properties, and copy all the contents of the directory. Parameter combination is equal to its role dpR

-P path to keep the source file or directory, this path can be absolute or relative path, and destination directory must already exist

-R recursive processing, the files and subdirectories in the specified directory treated together

-u After using this parameter, only when compared with the purpose of updating the file, or the file name corresponding to each other purposes does not exist in the source file modification time (Modification Time), just copy the files

-V <backup> or --version-control = <backup> specified when the backup file, the backup file name is named, there are the following three:
1.numbered or t, will use the backup numbers will suffix plus ~ 1 ~ string, which is incremented sequentially numbered
2.simple or never will use a simple backup default backup suffix string is ..., may be specified by -S
3.existing will use the current mode or nil, the program will first check whether there is a backup number, if the use of a backup number, if not then a simple backup

-x copied files or directories stored in the file system, which must execute the cp command when the same file system, or do not copy, nor processing files located in other districts

4, an example of command

4.1 copying files to the work directory a.txt

1 [root@localhost ~]# cp a.txt /work/

4.2 copying files to work a.txt directory and renamed b.txt

1 [root@localhost ~]# cp a.txt /work/b.txt

4.3 a.txt and copy files to a work directory b.txt

1 [root@localhost ~]# cp a.txt b.txt /work/

4.4 -i If the target file already exists, you are asked whether to overwrite

1 [root@localhost ~]# cp -i a.txt /work/
2 cp: overwrite '/work/a.txt'? 

4.5 -r recursive processing, the files and subdirectories in the specified directory dealt with together.

1 [root@localhost ~]# cp -r job/ /work/

 

Guess you like

Origin www.cnblogs.com/liuzgg/p/11648141.html