Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of the Linux basic command cp

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "the usage of the Linux basic command cp". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the usage of the Linux basic command cp".

Cp

Copy files, you can copy one file to another place, or you can copy multiple files to a directory. The scope of this command: RedHat, RHEL, Ubuntu, CentOS, SUSE, openSUSE, Fedora.

1. Grammar

Cp [option] [- T] src dst

Cp [option] src dir

Cp [option]-t dir src

2. List of options

Option

Description

-- help

Show help documentation

-- version

Show command version

-a |-- archive

Equivalent to "- dR-- preserve=all"

-- backup [= CONTROL]

Create a backup for each existing target file

-b

Similar to "--backup", but with no parameters

-- copy-contents

Copy the contents of a special file on recursion

-d

Equivalent to "--no-dereference-- preserve=links"

-f |-- force

Enforcement

-I |-- interactive

Interactive mode, ask before overwriting the file

-H

Follow the command line symbolic links in src.

-l |-- link

Create links and do not copy

-L |-- dereference

Always follow symbolic links in src

-n |-- no-clobber

Do not overwrite existing files

-R |-r

Recursive mode, copying subdirectories

-s |-- symbolic-link

Create symbolic links and do not copy

-P |-- no-dereference

Do not follow symbolic links in src

-p

Equivalent to "--preserve=mode"

-- preserve [= ATTR_LIST]

Keep the specified attributes (default: mode, ownership, timestamp) and, if possible, other attributes: context, link, xattr, all

-c

Equivalent to "--preserve=context"

-- no-preserve=ATTR_LIST

Do not retain the specified attribute

-- parents

Use the full source file name under the directory

-R |-r |-- recursive

Recursively copy subdirectories

-- reflink [= WHEN]

Control copy

-- remove-destination

Move each existing target file before trying to open it (as opposed to "--force")

-- sparse=WHEN

Control the creation of sparse files

-- strip-trailing-slashes

Removes any trailing slashes from each source parameter.

-s |-- symbolic-link

Create symbolic links and do not copy

-S |-- suffix=SUFFIX

Override the usual backup suffix

-t |-- target-directory=DIRECTORY

Copy all source parameters into DIRECTORY.

-T |-- no-target-directory

Treat the target file as a normal file

-t |-- target-directory=dir

Copy all source files to the directory

-u |-- update

Copy in an updated way

-v |-- verbose

Show detailed execution process

-x |-- one-file-system

Keep it on this file system

-Z |-- context=CONTEXT

Set the security context of the copy to context

3. Description

When "--reflink [= always]" is specified, a lightweight copy is executed, in which the data block is copied only when modified. If this is not possible, the copy fails, or if "--reflink=auto" is specified, return to the standard copy.

The backup suffix is'~ 'unless "--suffix" or "SIMPLE_BACKUP_SUFFIX" is set. Versioning methods can be selected through the "--backup" option or through the VERSION_CONTROL environment variable. Here are the values:

1) none, off, never backup, even if "--backup" is specified.

2) numbered, t, digital version control.

3) existing, nil, if there is a digital backup, then use digital backup, otherwise use simple backup.

4) simple, never, simple backup.

As a special case, when mandatory and backup options are provided, cp backs up the source, src and dst have the same name, and are both regular files.

4. Examples

1) copy the entire directory

[root@192 weijie] # cp-r test01/ test03/ copy recursively using the-r option

[root@192 weijie] # ls test03

1.c 1.c ~ 2.c 3.c

2) use the "- t" option to copy multiple files to the directory

[root@192 weijie] # cp-t test01 1.c 2.c 3.c / / copy 3 files to the test01 directory

Cp: does it overwrite "test01/1.c"? Y

[root@192 weijie] # ls test01

1.c 1.c ~ 2.c 3.c

3) create a link

[root@localhost wj] # cp-s 3.c 4.c / / create symbolic links, not copy

[root@localhost wj] # ls-l 4.c / / View the contents, which is a symbolic link

Lrwxrwxrwx 1 root root 3 October 30 08:09 4.c-> 3.c

[root@localhost wj] #

Thank you for your reading, the above is the content of "the usage of the Linux basic command cp". After the study of this article, I believe you have a deeper understanding of the usage of the Linux basic command cp, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report