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
Similar entries
- How to recursively create md5 and sha1 sum of your files.
- How to compress/backup just ascii-text files with linux tar
- Search only in .php files under linux
- Using "Linux Find" command to get human readable directory sizes in public_html
- Save / open .ico files (icons) with Adobe Photoshop CS4 64 / 32 Bit
- Using shared same Mysql Data dir on multiOS Linux+Windows Laptop
- Iframe Trojan / Virus of Alcobro.net
- Search in text files recursively with PHP - Grep
- Include both php/ html files, catch & assign output to a string variable
- search for files and create an archive with them (tar,find,linux)
- CuteFTP or FTP Client lists just 1998 / 2000 files
- Comparison of HDGuard, DeepFreeze, Dr-Kaiser and SteadyState
- List all files in a Directory without Filesize, heading info under Windows using MS-Dos Dir command
- Server Crash - "isc_socket_create: fcntl/reserved: Too many open files" [Howto Fix]
- Argument List too Long
- Free Web-Hosting with PHP-MYSQL, FTP and no-ads
- Howto duplicate (clone) VirtualBox image in Windows 7
- Cool Drupal Themes with preview to download directly
- Howto protect admin.php / login.php with htaccess password
- How can I disable Firefox Pop-up blocker for local html 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:
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...
Thanks
This is very useful
command at the end of copy ...
many file in a same time in linux....
thanks & regards
Pramod
Another option is to temporarily disable the alias that enables interactive copying/moving.
cp=cp
mv=mv
Then -f will actually work, I believe.
Post new comment