Linux system USES cp command to implement the method of mandatory coverage function

  • 2020-06-19 12:33:25
  • OfStack

preface

The cp command is used to copy one or more source files or directories to the specified destination file or directory. It can copy a single source file to a specific file with a specified file name or to an existing directory. The cp command also supports copying multiple files at the same time. When copying multiple files at once, the target file parameter must be an existing directory or an error will occur.

grammar

cp(Options)(parameters)

options

-ES14en: This parameter has the same effect as specifying the "-ES15en" parameter; -ES16en: When copying a symbolic connection, establish the target file or directory as a symbolic connection and point to the original file or directory connected to the source file or directory; -ES17en: Force a copy of a file or directory, regardless of whether the target file or directory already exists; -ES18en: Ask the user before overwriting an existing file; -ES19en: Hardwiring the source files instead of copying them; -ES20en: Preserves the properties of the source file or directory; -ES21en /r: Recursively processes all files in the specified directory together with subdirectory 1; -ES23en: Establish symbolic links to source files instead of copying files; -ES24en: After using this parameter, the file will only be copied if the change time of the source file is updated compared to the target file or if the target file with the corresponding name does not exist; -ES25en: When backing up a file, replace the default suffix of the file with the specified suffix "SUFFIX"; -ES27en: Make a backup of the existing file target before overwriting it; -ES28en: Details what the command does.

parameter

Source files: Make a list of source files. By default, the cp command does not copy directories. If you want to copy directories, you must use the -ES33en option.

Destination file: Specifies the destination file. When Source files are multiple files, target files are required to be the specified directory.

The cp command is used to implement mandatory coverage

When we normally use cp in Linux, we will find that if we copy files from one directory to another directory with the same file name, even if the -ES43en parameter is added to force overwrite the copy, the system will still prompt you to manually enter y to confirm the copy. The added rf parameter does not work.

The reason:

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

Query the 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 no parameters are added, the system will automatically add the -ES61en parameter when we use the cp command by default


 -i, --interactive
  prompt before overwrite

-ES65en is the abbreviation for interactive, that is, the system will ask for a confirmation prompt before using THE cp command for overwriting files. This is originally an insurance measure for the system. If there are many files to be copied and you find it difficult to input y one by one, you can use the following method to solve the problem:

Duplicate the

I suggest you to use method 1, because it is easy to create risks if you cancel the alias. If you forget to restore the alias again, there will be no prompt message in the future replication.
Can have clew information much 1 insurance, it is the person can have when making mix, add 1 insurance to oneself, have safeguard.

Method 1

Use the native cp command


/bin/cp -rf xxxx

Way 2

Cancel the cp command alias


unalias cp

Remove the alias of the cp command so that you will not ask for confirmation when you copy the file again using cp-ES89en.

Restore alias after replication is complete


alias cp='cp -i'

conclusion


Related articles: