LINUX-CP command

Source: Internet
Author: User

Linux of the CP command is used to copy one or more source files or directories to a specified destination file or directory . It can copy a single source file into a specific file with a specified file name or a directory that already exists. the CP Command also supports copying multiple files at once, and when copying multiple files at a time, the target file parameter must be a directory that already exists, or an error will occur.

1 . command format:

CP [ options] [source] [Target]

2 . command options:

-A:The effect of this parameter and specifying both"-DPR"The same parameters;
-D: When a symbolic connection is copied, the destination file or directory is also established as a symbolic connection and points to the original file or directory connected to the source file or directory;
-F: Forcibly copying a file or directory regardless of whether the destination file or directory already exists;
-I.: Ask the user before overwriting existing files;
-L: Make a hard connection to the source file, not copy the file;
- P : Preserves the properties of the source file or directory;
-r/r : Recursive processing, all files under the specified directory are processed together with subdirectories;
-S: Create a symbolic connection to the source file rather than copying the file;
-U: When this parameter is used, the file is copied only when the source file is changed more than when the target file is updated or when the target file corresponding to the name does not exist .
-S: When backing up a file, use the specified suffix"SUFFIX"Replace the default suffix of the file;
-B: The target file is backed up before overwriting the existing file target;
-V: Displays the actions performed by the command in detail.

3. command function:

Copy files or directories

4. usage Examples:

Instance one: Overwrite files that are already in the target while copying files, and Specify the backup file footer

[email protected] data]# LL

-rw-r--r--1 root root 0 Mar 19:05a.txt

[Email protected] data]# ll/tmp/

-rw-r--r--1 root root 0 Mar 19:06a.txt

[[Email protected]]# cp-b-s_xxx-v a.txt/tmp/ backup file suffix here _xxx

' A.txt ', '/tmp/a.txt ' (Backup: '/tmp/a.txt_xxx ')

[Email protected] data]# ll/tmp/

-rw-r--r--1 root root 0 Mar 19:06 a.txt

-rw-r--r--1 root root 0 Mar 19:05 a.txt_xxx

Example two: Generate Tail for ~1~

[Email protected] data]# cp-b-v t a.txt/tmp/

[Email protected] data]# ll/tmp/

-rw-r--r--1 root root 0 Mar 19:06 a.txt

-rw-r--r--1 root root 0 Mar 19:06 a.txt~

Example three: Copy file file{1..3} and directory Dir1 to Dir2

[[email protected] data] # cp-r file1 file2 file3 dir1 dir2

[email protected] data]# ll dir2/

Drwxr-xr-x 2 root root 4096 Mar 19:09dir1

-rw-r--r--1 root root 0 Mar 19:09 file1

-rw-r--r--1 root root 0 Mar 19:09 file2

-rw-r--r--1 root root 0 Mar 19:09 file3

Example four: Renaming files at the same time

[email protected] data]# LL

-rw-r--r--1 root root 0 Mar 19:10file1

[Email protected] data]# ll/tmp/

[Email protected] data]# cpfile1/tmp/file2

[Email protected] data]# ll/tmp/

-rw-r--r--1 root root 0 Mar 19:10file2

TIP : You can use \ or /bin/cp . Full path Avoid Y the confirmation!!!


This article is from the "krik2015" blog, make sure to keep this source http://krik2015.blog.51cto.com/10524959/1751992

LINUX-CP command

Related Article

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.