Is `mv dir dir2` atomic ?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Is `mv dir dir2` atomic ?
# 1  
Old 02-26-2008
Is `mv dir dir2` atomic ?

if I rename a dir
mv dir dir2

Is this operation atomic? Suppose there 100 files in dir, does linux rename them one by one or at once?

In other words, is there a time at which both dir and dir2 exist, with dir has, say 30 files and dir2 has the rest 70 files?
# 2  
Old 02-26-2008
I'm really only familiar with the HP-UX version, but I'm guessing that Linux version must be similar. HP's mvdir is confined to operating in a filesystem...never between filesystems. To understand it, consider the first unix implemention of it... If you have /parent/A which has a lot of files in it and you move it to /parent/B, the original version would invoke the link system call and link A to B. At this point, both A and B exist and they are just two names to the same directory. Then, as soon as possible, it would unlink A. This would leave just B. The operation took two very quick system calls. This was NOT atomic. Between the system calls, the filesystem was in an illegal state. A and B should not be links to the same directory even for a millisecond. Today, instead of two system calls, we use just one...and rename(). This is absolutely atomic. For all intents and purposes A just morphs into B. A and B must be in the same filesystem, but not necessarily have the same exact parent as I have indicated here.
# 3  
Old 02-27-2008
Within fileysystems mv may or may not be atomic. Across filesystems mv is not atomic.
# 4  
Old 02-27-2008
Thanks all.
Can I get an official link or resource for whether mv is atomic? I am writing a tech document of them. Thanks.
# 5  
Old 02-27-2008
i would start searching here: IEEE Std 1003.1, 2004 Edition

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Linux

Atomic Operations

Hello I am a newbie in linux. Please tell me what are atomic operations in Linux. IS i++ a atomic oparation?? Please help.. (3 Replies)
Discussion started by: aditya08
3 Replies

3. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

4. UNIX for Dummies Questions & Answers

system calls and atomic operation

Are system calls atomic operations? Is a system call can be interrupted? (2 Replies)
Discussion started by: vistastar
2 Replies

5. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

6. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

7. UNIX and Linux Applications

CPIO Problem, copy to the root dir / instead of current dir

HI all, I got a CPIO archive that contains a unix filesystem that I try to extract, but it extract to the root dir / unstead of current dir, and happily it detects my file are newer otherwise it would have overwrited my system's file! I tried all these commands cpio -i --make-directories <... (2 Replies)
Discussion started by: nekkro-kvlt
2 Replies

8. Programming

Atomic lock file creation

Hello, I need to implement a locking system in C. My problem is how to make the check if the lock file exist and locking it atomic operation. I want to make something like this: FILE* lock_fname; lock_fname = fopen ( "file.lock", "r"); /*check if file exsists*/ if (lock_fname) { fclose... (7 Replies)
Discussion started by: tsurko
7 Replies

9. Shell Programming and Scripting

a script to clone a dir tree, & overwrite the dir struct elsewhere?

hi all, i'm looking for a bash or tcsh script that will clone an empty dir tree 'over' another tree ... specifically, i'd like to: (1) specify a src directory (2) list the directory tree/hiearchy beneath that src dir, w/o files -- just the dirs (3) clone that same, empty dir hierarchy to... (2 Replies)
Discussion started by: OpenMacNews
2 Replies
Login or Register to Ask a Question