In Linux, how does one make the CP command not prompt overwrite?

Source: Internet
Author: User
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-rfsourcefiletargetdir or cp-r...

 

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.