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
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