If you use the CP command in Linux, you will often be prompted whether to overwrite the file. If it is too large to overwrite files in batches, it will be annoying to always prompt this. So how can we solve this problem?
Let's take a look at the reason!
Generally, the command we use is cp-rf sourcefile targetdir or cp-r-f sourcefile targetdir,
-R indicates recursive replication, that is, copying a folder and all its files.
-F indicates that a file with the same name is encountered and directly overwritten without prompting
But why are we still prompted to overwrite the two parameters?
This is because the system uses aliases during installation to prevent improper operations and overwrite files that should not be overwritten. Use the alias command to view the specific configuration.
[Test @ Server home] # alias
Alias cp = 'cp-I'
Alias l. = 'LS-d. * -- color = tty'
Alias ll = 'LS-l -- color = tty'
Alias ls = 'ls -- color = tty'
Alias mv = 'mv-I'
Alias rm = 'rm-I'
Alias which = 'Alias |/usr/bin/which -- tty-only -- read-alias -- show-dot -- show-tilde'
We can see from the above that the cp command we entered is actually the "cp-I" command,
That is, no matter how we input cp-rf, we actually execute cp-I-rf, And it's no wonder we always ask whether to overwrite it.
We can see from the above commands that several other commands also use aliases, such as ll, ls mv, and rm.
How can this problem be solved?
[Test @ Server home] # vi ~ /. Bashrc
#. Bashrc
# User specific aliases and functions
Alias rm = 'rm-I'
Alias cp = 'cp-I'
Alias mv = 'mv-I'
# Source global definitions
If [-f/etc/bashrc]; then
./Etc/bashrc
Fi
You only need to add the # sign before the corresponding command to comment out the command. Save and exit, and then you can use pure original commands.
In fact, there is another way to solve this problem, that is, you can use \ cp-f file dir!
From
Ghost Wang's blog