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 method of using cp Command to realize the function of forced coverage in Linux system

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

Share

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

Preface

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 an existing directory. The cp command also supports copying multiple files at the same time, and when copying multiple files at a time, the target file parameter must be an existing directory, otherwise an error will occur.

Grammar

Cp (option) (parameter)

Option

-a: this parameter has the same effect as specifying the "- dpR" parameter at the same time;-d: when copying a symbolic connection, the target 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 copy the file or directory, regardless of whether the target file or directory already exists;-I: ask the user before overwriting the existing file -l: establish a hard connection to the source file instead of copying the file;-p: retain the attributes of the source file or directory;-Rhampr: recursive processing, processing all files in the specified directory with subdirectories;-s: establish a symbolic connection to the source file instead of copying the file -u: after using this parameter, the file will be copied only when the change time of the source file is longer than that of the target file, or when the target file with corresponding names does not exist;-S: when backing up the file, replace the default suffix of the file with the specified suffix "SUFFIX";-b: back up the target file before overwriting the existing file destination;-v: show the operation performed by the command in detail.

Parameters.

Source files: develop a list of source files. By default, the cp command cannot copy directories, and if you want to copy directories, you must use the-R option

Target file: specify the target file. When the Source File is multiple files, the destination File is required to be the specified directory.

Using cp command to realize forced override function

We usually use the cp command in Linux, we will find that when copying files in one directory to another directory with the same file name, even if the-rf parameter is added to force override replication, the system will still prompt you to manually enter y to confirm the copy, the added rf parameter will not work.

Reason:

The cp command is aliased by the system, which is equivalent to cp='cp-i'.

Query alias command

[root@localhost sonarqube] # alias alias cp='cp-i'alias egrep='egrep-- color=auto'alias fgrep='fgrep-- color=auto'alias grep='grep-- color=auto'alias l.='ls-d. *-- color=auto'alias ll='ls-l-color=auto'alias ls='ls-- color=auto'alias mv='mv-i'alias rm='rm-i'alias which='alias | / usr/bin/which-- tty-only-- read-alias-- show-dot-- show-tilde'

From the above output, we can see that we usually use the cp command. Although we do not add any parameters, the system automatically adds the-I parameter when we use the cp command by default.

-I-- interactive prompt before overwrite

-I is the interactive abbreviation, that is, before using the cp command for file overwriting, the system will ask for a confirmation prompt. This was originally an insurance measure of the system. If you have a lot of files to copy and find it troublesome to input y, you can use the following methods:

Forced replication

It is recommended that you use method 1, because it is easy to cause risk if you cancel the alias, in case you forget to restore the alias, there will be no prompt for future replication.

There is a hint of information can be an extra layer of insurance, is that people will have a time to get mixed up, give themselves an insurance, there is a guarantee.

Mode one

Use the native cp command

/ bin/cp-rf xxxx

Mode two

Cancel cp command alias

Unalias cp

Remove the alias of the cp command, and when you copy the file with cp-rf, you will not ask for confirmation.

Restore aliases after replication is complete

Alias cp='cp-i'

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

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