Rename/Move file only if destination does not exist
- by mikeY
I would like to know if there is any way a file can be moved only if the destination does not exist - in other words, move only if it does not lead to overwriting.
mv --update
seemed first to be the solution, however, if the timestamp of the source path is newer than the destination, move will overwrite it and all attempts to circumvent this by modifying the timestamp before the move will fail.
I need this behaviour to implement a simple file based lock where existence of a 'lock' file indicates that the lock is acquired.