Linux method for copying files/folders using CP commands

  
                

Linux users can use cp and scp in the Linux kernel system without using other third-party tools when copying files. How to do this? Let's take a look at how to use the cp command to copy files and folders.

Copy method:

Name: cp

Access: All users

use:

cp [ ,null,null,0],Options] source dest

cp [options] source... directory

Description: Copy one file to another file or copy several files to another directory.

-a, --archive is equal to -dR --preserve=all

--backup[=CONTROL Create a backup for each existing object file

-b Similar to --backup but does not accept arguments

--copy-contents in recursive processing is to copy special file contents

-d equals --no-dereference --preserve=links

-f, --force Remove the target file if it cannot be opened and try again (you don't need to select this option when the -n option

exists)

-i, --interactive pre-overwrite query (make the previous -n option invalid)

-H Follow the command line symbolic link in the source file

-l, --link link file without copying < Br>

-L, --dereference always follow symbolic links

-n, --no-clobber Do not overwrite existing files (make the previous -i option invalid)

-P, --no-dereference does not follow symbolic links in source files

-p equals --preserve=mode, ownership, timestamps

--preserve[=attribute list hold Specified attribute (default: mode , ownership, timestamp), if

may maintain additional properties: environment, link, xattr, etc.

-R, -r, --recursive Copy all directories in the directory and directory< Br>

Example:

.Copy files, copy files only if the source file has a new modification time than the destination file

cp -u -v file1 file2

Copy file file1 to file file2

cp file1 file2

. Copy file file1 to file file2 in interactive mode

cp -i file1 file2

Copy the file file1 to file2, because the destination file already exists, so specify the mode to use forced copy

cp -f file1 file2

. Copy the directory dir1 to the directory dir2

cp -R file1 file2

. Also copy the file file1, file2, file3 and directory dir1 to dir2

cp -R file1 file2 file3 dir1 dir2

.Retain file attributes when copying

cp -p a.txt tmp/

.Retaining the directory structure of files when copying

c p -P /var/tmp/a.txt ./temp/

.Generate backup files when copying

cp -b a.txt tmp/

. Generate backup file, tail ~1~ format

cp -b -V t a.txt /tmp

. Specify backup file tail

cp -b -S _bak a.txt /tmp

If you don't like to use third-party copy tools, try copying files and folders using the cp command. I believe this feature will bring you some surprises.

Copyright © Windows knowledge All Rights Reserved