Do not overwrite the cp command.

Source: Internet
Author: User
In Linux, if you want to copy the file to the directory dir, run: cpfiledir. However, if a file named file already exists under dir, the system always prompts whether to overwrite the file. This is a good function that can prevent system damages due to negligence. But what if we do not want to see the interaction prompts? For example, if we need to write a script to install some files in the specified directory, we certainly do not want to see the prompt. You can try the-f option ,-

In Linux, if you want to copy the file to the directory dir, run the following command:

Cp file dir

However, if a file named file already exists under dir, the system will always prompt whether to overwrite the file.

This is a good function that can prevent system damages due to negligence. But what if we do not want to see the interaction prompts? For example, if we need to write a script to install some files in the specified directory, we certainly do not want to see the prompt.

You can try the-f option.-f generally indicates force ).

Cp-f file dir

But it seems that the result is not as expected, and the system will still have a coverage prompt. Why?

The reason is simple. the system sets the cp command alias cp-I. When we execute the cp command, the system usually executes cp-I, and the-I option indicates that there is an interactive prompt. Therefore, when we execute cp-f, what the system actually executes isCp-I-f, so there will still be a overwriting prompt.

To execute the original cp, you can add the absolute path when calling cp. of course, you can also directly execute the following statement:

\ Cp-f file dir


Related Article

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.