My understanding is that mv dir1/file1 dir2/ is atomic,
Is mv dir1/* dir2/ also atomic?
As an example, assume there are 10 files in dir1 that are 10GB each.
Let's start with the statement that
mv is not always atomic.
For any individual file, the move or rename performed by
mv is atomic provided that the file is moved within the same filesystem. The atomicity does not guarantee that the file is only in one place or another; it is quite possible that the file could be present in the filesystem in both places simultaneously for "a short time".
mv is most definitely not atomic when the move that it performs is from one filesystem to another, or when a remote filesystem cannot implement the
mv operation locally. In these instances
mv is implemented by the equivalent of a
cp followed by
Now, moving on to the question of atomicity across multiple files.
mv is at best atomic only per file, so if you have a number of files to move together, the implementation is such that they will be moved one at a time.
If you really need a group of files to appear in a destination simultaneously, consider putting them in a directory and moving that directory. This single object (the directory) can be moved atomically.
mv dir1/* is the same as
mv dir1/file1 && mv dir1/file2 && mv dir1/fileN. Each individual move is atomic, but not the full set.
Another case, a new file is added to dir1 after the mv has started.
As the “*” is expanded by the shell, mv will not even know about the new file.