Reputation: 858
I need a way to move a linux directory and all of it's contents only if it doesn't currently exist in the target location. If it does currently exist (including all sub-folders and files) then the source folder can just can just be removed recursively.
I currently use the following framework but wish to expand it to meet the above criteria.
mv /source/* /target
Thanks
Upvotes: 2
Views: 171
Reputation: 513
rsync -av --remove-source-files source/ destination/ && rm -rf source/
Replace source/
and destination/
accordingly.
Upvotes: 1
Reputation: 60068
Gnu mv
has the -n
or --no-clobber
option. Unfortunately, it seems to return with an successful exit status even if the mv
was a no-op due to the --no-clobber
option, however it seems that in your use case, you can simply do the --no-clobber
move and then clear the source if the move succeeds regardless of whether or not it did anything.
Upvotes: 0