Update / overwrite files and directories recursively with Linux mv - cp commands

Update / overwrite files and directories recursively with Linux mv - cp commands

You want to update / upgrade your system. Its not easy as you think to copy or move new files with overwriting old files on linux. I know you think "--force" will help you, but not here!

With move command 'mv' it was not possible to update all files and directories. Therefore we use copy command 'cp'.

#mv new/files/* files or #mv -f new/files/* files
mv: cannot overwrite directory ...

#cp -af new/files/* files
cp: overwrite '...'?

You have type "yes" many times.

The solution:

#yes | cp -a new/files/* files

"cp -a src/* dest" does not copy hidden files like .htaccess on top level. Try again with cp -a src/.* dest

To not overwrite:

no | cp -a new/files/* files

Actually, it's better to edit your .bashrc - and put these lines there:

#ask before overwriting files
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i -v'

It just means that everytime you type the cp command it will always ask if you want to -i (overwrite it?) -v (and be verbose about it)

Great article! Thanks.

I am trying it on ubuntu but I dont asked to overwrite etc...

This is very useful
command at the end of copy ...
many file in a same time in linux....

thanks & regards


Another option is to temporarily disable the alias that enables interactive copying/moving.


Then -f will actually work, I believe.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.