Re: Is the shell command "mv" atomic

From: Dragan Cvetkovic (
Date: 04/03/03

From: Dragan Cvetkovic <>
Date: 03 Apr 2003 10:54:30 -0500

Chris Lowth <dont@want.spam> writes:

> Andy Isaacson wrote:
> > mv(1) uses rename(2) to do its work. rename(2) is atomic. Therefore,
> > the race condition you describe cannot occur. Your script is safe.
> No: Not true for all Unixes - some have "rename" as a system, and for others
> "rename" is library call that uses link and unlink to do it's work.
> Under linux (for example) - "rename" is indeed a system call - but I
> wouldn't like to guarantee that this means that the action is atomic.

Well, POSIX requires it. Here is the quote from OpenGroup specification for
rename(2) (in Rationale):

    This rename() function is equivalent for regular files to that defined
    by the ISO C standard. Its inclusion here expands that definition to
    include actions on directories and specifies behavior when the new
    parameter names a file that already exists. That specification
    requires that the action of the function be atomic.

Note the last sentence there.

Bye, Dragan

Dragan Cvetkovic, 
To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

Relevant Pages

  • Re: Is the shell command "mv" atomic
    ... >> the race condition you describe cannot occur. ... Your script is safe. ... I don't think any systems that use link/unlink have been produced for many ...
  • Re: BDS 2006 Update 2 latest results
    ... Norton now picks up a file BDS.exe as a malicious script. ... Is it completely ok to authorise this script as always safe, ... Borland guarantee this script is safe? ...
  • Re: New Meds...
    ... It's the DEA who wants the 3 month script writing. ... down isn't safe for what we would need one for. ... we get three month supplies of meds from THEIR mail in pharmacies, ... I still only see my doctor every 3 months. ...
  • Re: Redirect file output into variables
    ... Hmm, i would use a safe interpreter for that..., as you say limited ... interp alias foo puts buffered_puts ... set script "script you want to execute in a safe environment" ...
  • Re: How to migrate my localhost php site to my ISP - Was: willing to learn php basics
    ... If your users can enter data, then the script must have at least some write privileges on the database. ... "The 1&1 60-Day Money Back Guarantee applies to the Instant Mail and Beginner packages as well as all shared hosting, ... There's a Business at GBP 9 per month, about the same as your Swiss one, which offers two 100MB MySQL databases plus perl and PHP. ...