Linux CP command and sample detailed _linux

Source: Internet
Author: User

Recently learned the Linux command, now the CP command sorted out for future inquiries.

Features: Copying Files or directories

Description: The CP directive is used to copy files or directories, such as specifying more than two files or directories, and the last destination is an existing directory, which copies all the files or directories previously specified to this directory. If you specify multiple files or directories at the same time, and the last destination is not an existing directory, an error message appears

Parameters:

-A or--archive the effect of this parameter is the same as specifying the '-DPR ' parameter

-B or--backup Delete, overwrite the destination file first, back up the file or directory is also established as a symbolic link, and point to the source file or directory link source files or directories. If you do not add this parameter, if you encounter a symbolic link during the copy process, the source file or directory will be copied directly

-F or--force forcibly copies a file or directory, regardless of whether the destination file or directory already exists

-I or--interactive to ask the user before overwriting the file

-L or--link create hard links to source files, not copy files

-P or--preserve preserves the properties of the source file or directory, including owner, owning group, permissions, and time

-P or--parents preserves the path to the source file or directory, which can be an absolute or relative path, and the destination directory must already be abundant in the

-R recursively processes the files in the specified directory with the subdirectories. If the source file or directory form, does not belong to the directory or symbolic link, it is considered as normal file processing

-R or--recursive recursion to handle files and subdirectories in the specified directory

-S or--symbolic-link create symbolic links to source files instead of copying files

-S < backup tail string > or--suffix=< backup Word tail string > The end of the backup file is backed up with a backup string after the "-B" parameter is used to back up the destination file. The default backup Word tail string is the symbol "~"

-U or--update Use this parameter to copy files only when the source file is modified (modification time) is newer than the destination file, or if the destination file name corresponds to the other

-V or--verbose display the execution process

-V < backup mode > or--version-control=< backup method > Specifies the following 3 ways to name a backup file name when backing up a file:

1.numbered or T, the backup number is used, and the ~1~ string is added to the end of the word, and its number is incremented sequentially

2.simple or never will use a simple backup, the default backup tail string is ~, or it can be specified by-s

3.existing or nil will use the current mode, the program will first check whether there is a backup number, if there is a backup number, if not the use of simple backup

File systems that are stored in files or directories that are copied by-X or--one-file-system must be the same as the file system in which the CP directive is executed, otherwise they will not be replicated and files located in other partitions are not processed

--help Show online Help

--sparse=< Use time > Set the time to save the Greek files

--version Display version

Example:

Copying files, copying files only if the source file is newer than the destination file's modification time

Cp-u-V file1 file2

. copy file file1 to file File2

CP file1 File2

. interactively copy file file1 into a file file2

Cp-i file1 file2

Copy the file file1 to File2 because the destination file already exists, so specify the mode to use forced replication

Cp-f file1 file2

. copy directory Dir1 into a directory Dir2

 Cp-r file1 file2

. Also copy files File1, file2, File3, and directory Dir1 to Dir2

Cp-r file1 file2 file3 dir1 dir2

. preserve file properties when copying

 Cp-p a.txt tmp/

. Preserve the directory structure of files when replicating

Cp-p/var/tmp/a.txt./temp/

. Generate backup files when replicating

Cp-b a.txt tmp/

The backup file is generated when copying, and the tail-label ~1~ format

Cp-b-V T  a.txt/tmp  

. Specify the tail label of the backup file

Cp-b-S _bak a.txt/tmp

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.