I have folders old and new.
I want to replace all the contents in old/* to new/*. There can be many subdirectories in those folders.
But there can be few files which are not in new/* but are in old/*, so I want them to stay as they are.
How can I do that from a Linux shell?
3 Answers
rsync would probably be a better option here. It's as simple as rsync -a subdir/ ./. check this unix.stackexchage answer for better solutions
use -f with the cp command
cp -fR /source/files /destsuppress cp to overwrite" prompt..
To override cp's alias you can simply enclose it in quotes:
'cp' -rf ./source/* /destination/for more information follow these links:
1Use rsync. It will synchronize the directories in one direction. So, if you want to update your old folder with everything from new, but keep what's in there, just use:
rsync -avh --dry-run /path/to/new/ /path/to/old/This will, in a first instance, just output the list of files that would be transferred. In that case: Everything found in new will be copied to old, unless it's already there. Everything in old stays as it is.
If it looks fine to you, remove the --dry-run argument to transmit them for real.
The -avh flags just enable archive mode (which will preserve timestamps, etc.), verbosity and human-readable file-sizes. Nothing will be deleted from the destination unless you specify the --delete flag. Consult man rsync for more information.
please Try Once if you want to change the name of a folder theare are no command to rename the files/folders the mv command is used to move the old directory to new directery so rename sucess.
mkdir new sudo mv -fr old/* new/
1