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