Rename/Move file only if destination does not exist

Posted by mikeY on Server Fault See other posts from Server Fault or by mikeY
Published on 2010-05-12T12:42:40Z Indexed on 2010/05/12 12:44 UTC
Read the original article Hit count: 275

Filed under:
|
|
|
|

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.

© Server Fault or respective owner

Related posts about shell

Related posts about move