Linux cp command

Function: Copy files or directories
Description : The cp command is used to copy files or directories. If two or more files or directories are specified at the same time, and the final destination is an existing directory, it will copy all the previously specified files or directories. directory is copied into this directory. If multiple files or directories are specified at the same time, and the final destination is not an existing directory, an error message will appear
Parameters :
     -a or --archive The effect of this parameter is the same as specifying the "-dpR" parameter at the same time
     -b or --backup Delete or overwrite the destination file and back it up first. The backed up file or directory is also established as a symbolic link, pointing to the source file or directory linked to the source file or directory. If this parameter is not added, if a symbolic link is encountered during the copying process, the source file or directory will be copied directly
     -f or --force to force the copy of the file or directory, regardless of whether the destination file or directory already exists
     -i or -- interactive ask user before overwriting file
     -l or --link hard link to source file instead of copying file
     -p or --preserve preserve source file or directory attributes, including owner, group, permissions and time
     -P Or --parents keep the path of the source file or directory. This path can be an absolute path or a relative path, and the destination directory must have been
     processed recursively in -r, and the files in the specified directory will be processed together with subdirectories. If the form of the source file or directory does not belong to a directory or a symbolic link, it will be treated as a normal file.
     -R or --recursive Recursive processing, the files and subdirectories in the specified directory will be processed together
     -s or --symbolic-link Create a symbolic link to the source file instead of copying the file
     -S <backup suffix string> or --suffix=<backup suffix string> After backing up the destination file with the "-b" parameter , a backup string will be added to the end of the backup file. The default backup suffix is ​​the symbol "~"
     -u or --update After using this parameter, only when the modification time of the source file (Modification Time) is updated compared to the destination file, or the destination files whose names correspond to each other Copy the file if it does not exist
     -v or --verbose show the execution process
     -V <backup method> or --version-control=<backup method> Specify the naming method of the backup file name when backing up files, there are the following 3 types :
                         1.numbered or t, the backup number will be used, and ~1~ will be added to the end of the suffix, and the number will be incremented in turn.
                         2.simple or never will use the simple backup, the default backup suffix string is ~, also
                         3. Existing or nil can be specified by -S. The current method will be used. The program will first check whether there is a backup number. If there is, use the backup number. If not, use simple backup
     -x or --one-file-system copy The file system stored in the file or directory must be the same as the file system where the cp command is executed, otherwise it will not copy or process files located in other partitions
     --help Display online help
     --sparse=<use time> Set the time to save the sparse file
     --version Display the version

Example : .Copy the
    file, only when the modification time of the source file is newer than the destination file, the file will be copied
     cp -u -v file1 file2

    . Copy file file1 to file file2
     cp file1 file2

    . Use interactive mode to copy file file1 to file file2
     cp -i file1 file2

    . Copy file file1 to file2, because the destination file already exists, so specify the forced copy mode
     cp -f file1 file2

    . Copy the directory dir1 to the directory dir2
     cp -R file1 file2

    . Simultaneously copy the files file1, file2, file3 and the directory dir1 to dir2
   cp -R file1 file2 file3 dir1 dir2

    . Keep the file attributes when copying
     cp -p a.txt tmp /

    . Keep the directory structure of the file when copying
     cp -P /var/tmp/a.txt ./temp/

    . Generate a backup file when copying
     cp -b a.txt tmp/

    .A backup file is generated when copying, the tail mark ~1~ format
     cp -b -V t a.txt /tmp   
 
    . Specify the tail mark of the backup file   
     cp -b -S _bak a.txt /tmp

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326395962&siteId=291194637