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 to use the cp command to force overwrite in Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use the cp command in Linux to force coverage". In the daily operation, I believe many people have doubts about how to use the cp command to force coverage in Linux. The editor consulted all kinds of data and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the question of "how to use the cp command to force coverage in Linux". Next, please follow the editor to study!

When cp is copying, if it encounters a file with the same file name, it will keep asking whether to overwrite it and ask you to enter yes or no. Why? This is for linux to use an alias on the cp command for security reasons. That is, when you just enter the cp command, the system is actually "cp-I". The "I" means interactive, constantly asking if you want to overwrite. Therefore, there are three ways for cp to force overrides.

Method 1:

Enter the alias command and see that the alias of cp is being used internally.

The code is as follows:

# alias

Alias cp='cp-i'

Enter the unalias cp command to remove the alias.

The code is as follows:

# unaslias cp

(this is only a temporary alias for cp, not permanent)

The code is as follows:

# cp a test/a

Oh, now it's normal.

Method 2:

Enter the\ cp command, which also cancels the alias of cp.

The code is as follows:

#\ cp a test\ a

Oh, it works just as well in this way.

This method is equivalent to directly using the absolute path of the executable file of the cp command

The code is as follows:

# / bin/cp a.txt

Method 3:

Enter yes | cp a test\ a, and use the pipe to enter yes automatically.

The code is as follows:

# yes | cp a test\ a

See, automatically type out a bunch of yes and type it for you.

At this point, the study on "how to use the cp command to force override in Linux" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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: 275

*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