Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to implement the cp command not to override the prompt

Shulou Source: shulou.com Published: 2022-06-01 09:40:51 09月19日 Update

This article mainly explains "how to implement the cp command not to overwrite the prompt", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to implement the cp command not to override the prompt"!

Under Linux, if you want to copy the file file to the directory dir, you can execute:

Cp file dir

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

This is a good feature to prevent the damage to the system caused by negligence, but what if we don't want to see the prompts of these interactions? For example, we need to write a script to install some files in the specified directory, and we certainly don't want to see the prompt.

You can try the-f option, which generally means force.

Cp-f file dir

But as if the result is not what we expected, the system will still have an override prompt. Why?

The reason is simple: the system alias the cp command as cp-I. When we execute the cp command, the system often executes the cp-iflint option to indicate that there is an interactive prompt, so when executing cp-f, the system actually executes cp-I-f, so there will still be an override prompt.

It is also easy to execute the original cp by adding an absolute path when calling cp and, of course, executing the following statement directly:

\ cp-f file dir

At this point, I believe you have a deeper understanding of "how to implement the cp command not to override the prompt". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Hint system command time file information content actual directory learning original practical deeper interest function reason practicality copy simple operation method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info vpn Huawei Docker Linux