CP Command Learning

Source: Internet
Author: User

Cpfunction Description

CP,copy, meaning copy, you can directly copy a file to the specified directory, you can also copy the directory directly. The file name can be modified at the same time as replication. When copying multiple files at the same time, the target must be a directory that already exists.

Syntax Format

CP ( option ) ( parameter )

Common Options

-A : This parameter includes all functions of the "-DPR" parameter;

- 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 :Force, forcibly copying a file or directory regardless of whether the target file or directory already exists;

- I. : Ask the user before overwriting an existing file ( the shell defaults to alias cp=cp–i);

- L : Create a hard connection to the source file instead of copying the file (equivalent to ln, which generally uses ln to establish a hard-soft link);

- P : Preserves the properties of the source file or directory;

-r/r : Recursively handles all files in the specified directory with subdirectories ( commonly used to copy files in directories and directories);

- S : Establish a symbolic connection to the source file rather than copying the file (equivalent to ln-s establishing a soft connection);

- b : The target file is backed up before overwriting the existing file target;

- v : Displays the actions performed by the command in detail.

Parameters

source file: Specifies one or more source files, with multiple source files separated by a space, when the source file is a directory, using -r/r for replication.

target file: Specify the destination file, whether it will prompt for overwrite, or self-define the name of the copy, when copying multiple files at the same time, the destination file must be an existing directory.

Example

copy a file into a directory

[Email protected] ~]CP 123/tmp

Cp:overwrite '/tmp/123 '? Y

[Email protected] ~]# CD!$

Cd/tmp

[[email protected] tmp]# ls

123 Oldboy.txt Stu4.txt.bak.bak

123~ Stu1.txt.bak.bak Stu5.txt.bak.bak

Beyond.txt Stu2.txt.bak.bak Yum.log

Lixin Stu3.txt.bak.bak YUM_SAVE_TX-2016-03-04-01-53MXM_EJ.YUMTX

copy multiple files to one directory at a time and keep the properties

[[Email protected] ~] ls

10.txt 2.txt 4.txt 6.txt 8.txt install.log.syslog

1.txt 3.txt 5.txt 7.txt 9.txt Install.log

[Email protected] ~]# cp-p *.txt/tmp

[Email protected] ~]# ls/tmp

10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt

Little Tricks

because the shell defaults to the CP alias,cp=cp–i, so the overwrite will appear when prompted, if you do not want to prompt, you can add \ in front of the command, To mask the alias (or use the absolute path of the command). For example \CP 123/tmp or/bin/cp 123/tmp, so even if there is a 123 under /tmp, it will not prompt for overwrite.


CP Command Learning

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.