prompt before overrite : cp in linux

Posted on 2010-04-01
Medium Priority
Last Modified: 2013-12-06

I am new to linux. I use following command but still get interactive prompts "overite ?" for each file. I want to over rite all existing files at destination dir i.e. like "yes to all" in windows.

cp -f -r [source dir] [dest dir]

any suggestions or idea? All I want to do is copy all files and sub directories from source to dest (overwrite files at dest)
Question by:idforpg1
  • 2
  • 2
LVL 58

Expert Comment

ID: 29402737
You may have an alias. Try

\cp -f -r [source dir] [dest dir]

however note that with that the sourcedir would be copied inside the destdir. You should use

\cp -f -r [source dir]/* [dest dir]

Accepted Solution

ajay_mhasal earned 2000 total points
ID: 29426165

Just run following command on terminal and then try copying again you issue will be resolved

unalias cp

But above change is temporary i.e. you need to run this command every time you login and if you wish to make it permanent then edit file ".bashrc"  ( Pl. note "." before bashrc this is not typing mistake) located at home dir of that user and delete line "alias cp='cp -i'" to edit .bashrc file use following command.

vi ~/.bashrc

Assisted Solution

ajay_mhasal earned 2000 total points
ID: 29426555

After running unalias command or after editing .bashrc file  mentioned in my previous post you dont need to pass additional parameters to cp command, simply use cp command and now it will never prompts you to type yes/no before overwriting!


cp -r <source dir> <dest dir>
LVL 68

Expert Comment

ID: 29455717
Is there a file "-i" in source_dir?

If so, and if you are not willing or allowed to delete it, use

cp -r -- [source dir] [dest dir]

LVL 58

Expert Comment

ID: 29510853
I would not recommend getting rid of the alias from the profile/bashrc permanently. It is safety net that is needed by everyone no matter how experience one has. One day this would haunt you when you would lose something important. Temporary unaliasing by prefixing the command by \ is safer way.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question