25 C
Jaipur
Sunday, October 25, 2020

How to Force cp Command to Overwrite without Confirmation

Must read

How to Use Shortcuts to Track Your iPhone 12 Shipment

As Apple has started to ship its latest iPhone 12 models, customers are eagerly waiting for their orders to reach their homes. So, if...

Take Game Boy Camera-Style Selfies With This New Web-App

The internet, as we all know, is filled with all kinds of crazy websites and web-apps. We have not only seen websites that self-destruct...

This Website Takes You Back in Time to Explore Retro Tech

Since technology started evolving, we have seen various kinds of devices make their way to the market and even die, over the years. Well,...

Microsoft GitHub Disables youtube-dl Open Source Project

The open source project youtube-dl is one of the best tools to download videos from YouTube and many other video hosting websites. But the existence...

The cp command (which stands for a copy) is one of the commonly used commands on Linux and other UNIX-like operating systems, for copying files and directories. In this guide, we will show how to force the cp command to overwrite a copy operation without confirmation in Linux.

Usually, when you run a cp command, it overwrites the destination file(s) or directory as shown.

# cp bin/git_pull_frontend.sh test/git_pull_frontend.sh

To run cp in interactive mode so that it prompts you before overwriting an existing file or directory, use the -i flag as shown.

# cp -i bin/git_pull_frontend.sh project1/git_pull_frontend.sh

By default, modern Linux distributions especially those in the Red Hat Enterprise Linux (RHEL) family come with an alias for the cp command which makes a user run the cp command in interactive mode. This may not be the case on Debian and Ubuntu derivatives.

To check all your default aliases, run the alias command as shown.

# alias
View All Linux Aliases

The highlighted alias in the above screenshot implies that when you run the command, by default it will run in interactive mode. Even when you use the yes command, the shell will still prompt you to confirm the overwrite.

# yes | cp -r bin test
Run Copy Command With Confirmation
Run Copy Command With Confirmation

The best way to force the overwrite is to use a backward slash before the cp command as shown in the following example. Here, we are copying contents of the bin directory to test directory.

# cp -r bin test
Force cp Command to Overwrite Files without Confirmation
Force cp Command to Overwrite Files without Confirmation

Alternatively, you can unalias the cp alias for the current session, then run your cp command in the non-interactive mode.

# unalias cp
# cp -r bin test
Unalias cp Command Alias
Unalias cp Command Alias

For more information, see the cp command man page.

# man cp

If you have any questions, ask us via the feedback form below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to Use Shortcuts to Track Your iPhone 12 Shipment

As Apple has started to ship its latest iPhone 12 models, customers are eagerly waiting for their orders to reach their homes. So, if...

Take Game Boy Camera-Style Selfies With This New Web-App

The internet, as we all know, is filled with all kinds of crazy websites and web-apps. We have not only seen websites that self-destruct...

This Website Takes You Back in Time to Explore Retro Tech

Since technology started evolving, we have seen various kinds of devices make their way to the market and even die, over the years. Well,...

Microsoft GitHub Disables youtube-dl Open Source Project

The open source project youtube-dl is one of the best tools to download videos from YouTube and many other video hosting websites. But the existence...

China has ‘good news’ for Apple despite tensions with US

The latest iPhone 12 models seem to be an instant hit in China with people queuing up outside Apple’s flagship...