Search code examples
linuxterminalfile-move

move linux directory unless it already exists


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


Solution

  • rsync -av --remove-source-files source/ destination/ && rm -rf source/

    Replace source/ and destination/ accordingly.

    Source