How to make the CP command not prompt for overwriting under Linux? When using the CP command under Linux, you will often be prompted whether to overwrite. If the files are overwritten in too many batches, it will be annoying to keep such prompts. So how to solve this problem?
Let's take a look at the reason first!
Generally, the command we use is cp -rf sourcefile targetdir or cp -r -f sourcefile targetdir,
-r means recursive copy, that is, copy folders and their The following all files
-f means to encounter files with the same name, do not prompt, directly overwrite
But why do we use these two parameters, the system will prompt to overwrite?
This is because the system uses aliases during installation to prevent us from Misoperation, overwriting files that should not be overwritten. Use the alias command to see 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 to say, no matter how we enter cp -rf, in fact, the execution is cp -i -rf, and it is no wonder that we always ask whether it is overwritten.
From the above commands, we can know that several other commands also use aliases, such as ll, ls mv, rm, etc.
So how to solve this problem?
[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
Just add a # sign before the corresponding command to comment out the command. Save and exit, then you can use the pure original command.
In fact, there is another way to solve this problem, that is to use \cp -f file dir!
linux cp cancel prompt
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327092328&siteId=291194637
Recommended
Ranking