On Linux Linux cp command cp command

 

Linux cp command

Function: copy a file or directory
Description: CP instruction for copying a file or directory, such as specifying two or more files or directories, and the final destination is a directory already exists, it will all files specified above or directory copied to this directory. If specify multiple files or directories, but the final destination is not an existing directory, an error message appears
parameters:
     -a --archive or effect of this parameter and specify the same parameters "-dpR"
     -b or --backup 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
     -f or --force forcibly copy a file or directory, regardless of the destination file or directory already exists
     -i or - ask before overwrite files first interactive user
     -l or --link establish a hard link to the source file, rather than copying the file
     attribute -p or --preserve keep the source file or directory, including the owner, owning group, permissions and time
     -P or --parents path to keep the source file or directory, this path can be absolute or relative path, and destination directory must already abundant in the
     recursive processing -r, 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 processing
    -R or --recursive recursive processing, the files and subdirectories in the specified directory treated together
     -s --symbolic-link or the source file to create a symbolic link, rather than copy the file
     after -S <backup suffix string> or --suffix = <backup suffix string> with "-b" parameter files for backup purposes , suffix backup files will be backed up plus a string. Default backup suffix string is "~" symbol
     after the -u or --update use this parameter only when the updated file object representing the source file modification time (Modification Time), or a file name corresponding to each object does not exist, the file only copied
     -v --verbose display or execution
     -V <backup> or --version-control = <backup> specified when the backup file, the backup file name is named, following three :
                         1.numbered or t, will use the backup numbers will suffixes ~ 1 ~ string, which is incremented sequentially numbered
                         2.simple or never will use a simple backup default backup suffix string is ..., and can be specified by -S
                         3.existing nil or current mode to be used, the program will check whether there is a backup number, if the number using the backup, if not then a simple backup
     -x --one-file-system or replication file or directory stored in the file system, which must be the same with the cp command execution when file system, or do not copy, nor handle located in other partition file
     --help display online help
     --sparse = <use of time>
     --version display version

Example:
    When copying files, only the source file modification time than the purpose of the document, just copy the files
     cp -u -v file1 file2

    Copy the file to a file file1 file2
     cp file1 file2

    . Interactively copy files to a file file1 file2
     cp -i file1 file2

    Copy the file file1 to file2, because the destination file already exists, so specify the use of force replication mode
     cp -f file1 file2

    The copy the directory to the directory dir1 dir2
     CP -R & lt file1 file2

   Meanwhile Copy the file file1, file2, file3 directory dir1 to dir2   CP -R & lt file1 file2 file3 dir1 dir2
 

    When you copy a file to retain the properties
     cp -p a.txt tmp /

    Reserved file when copying a directory structure
     cp -P /var/tmp/a.txt ./temp/

    . Backup file copy
     cp -b a.txt tmp /

    . When copying the backup file is generated, the suffix 1 ~ ~ format
     CP -V T a.txt -b / tmp    
  
    . Specify the backup file suffix    
     cp -b -S _bak a.txt / tmp

   Forced to copy files to display the copy process 

   cp -Rfv /etc  /yum

Guess you like

Origin www.cnblogs.com/linuxandy/p/11300123.html