How to make CP command not prompt overwrite file under Linux

Source: Internet
Author: User

Under Linux, if you want to copy file files to directory dir, you can do this: CP file dir
However, if a file named files already exists under Dir, the system will always prompt you to overwrite it.

This is a good feature that prevents us from inadvertently causing damage to the system, but what if we don't want to see the cues for these interactions? For example, we need to write a script to install some files into the specified directory, we certainly do not want to see the prompt.

You can try the-f option, and-F generally indicates enforcement (force).

Cp-f file dir


But it seems that the result is not as we hoped, the system will still have the overlay hint. Why is it?

The reason is simple, the system will be the CP command alias Cp-i.

When we execute the CP command, the system often executes the CP-I,-I option to indicate that there are interactive prompts,

So when the cp-f is executed, the system actually executes cp-i-F, so there will still be an overlay hint.

You can perform the alias command to view the following:

Alias cp= ' cp-i ' Alias l.= ' ls-d. *--color=auto ' Alias ll= ' Ls-l--color=auto ' Alias ls= ' ls--color=auto ' alias mv= ' Mv-i ' Ali As rm= ' rm-i ' Alias Which= ' Alias | /usr/bin/which--tty-only--read-alias--show-dot--show-tilde '


It's also easy to execute the original CP:
1. Add an absolute path (available via the whereis CP command) when calling CP, as

/bin/cp-f file dir

2. Invoke the system's original command by directly executing the following statement:

\cp-f file dir

3. Comment out Alias cp= ' cp-i ' in ~/.BASHRC
4.unalias CP, then use CP, but restore alias cp= ' cp-i ' after use

Reference:

Http://www.myexception.cn/linux-unix/446791.html

Http://www.php100.com/html/webkaifa/Linux/2010/0525/6409.html


How to make CP command not prompt overwrite file under Linux

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.