Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How the cp command in linux does not overwrite the file

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how the cp command in linux does not cover the relevant knowledge points of the file, the content is detailed, and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

In linux, you can use the "- I" parameter of the cp command not to overwrite the file, and the cp command is used to copy the file or directory. When the parameter is set to "- I", a prompt is given before overwriting the file. When you answer "n", you do not agree to overwrite the file. When you answer "y", you agree to overwrite the file. The syntax is "cp-I file name".

The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Why doesn't the cp command in linux overwrite the file?

The Linux cp (English full spelling: copy file) command is mainly used to copy files or directories.

Grammar

Cp [options] source dest

Or

Cp [options] source... Directory

Parameter description:

-a: this option is usually used when copying a directory, preserving links, file properties, and copying everything in the directory. Its function is equal to the combination of dpR parameters.

-d: keep the link when copying. The links mentioned here are equivalent to shortcuts in the Windows system.

-f: overwrite existing target files without prompting.

-I: contrary to the-f option, prompt the user to confirm whether or not to overwrite the target file before overwriting, and the target file will be overwritten when answering y.

Use awk loop to give Yes (y) or No (n), agree to overwrite or disagree to overwrite. Obviously agree to cover a bit of chicken ribs, you can use-f to force coverage.

Examples are as follows:

Copy all files and subdirectories under the folder Raw to the New directory

Awk 'BEGIN {cmd= "cp-ri. / Raw/*. / New"; print "n" | cmd;}'

Remarks: print "n" | cmd, print the cmd command first, and then print n.

These are all the contents of the article "how to not overwrite files with cp commands in linux". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report