What happens if the Linux mv
command is interrupted? Say, I'm moving a whole directory to some other place and interrupt it while it's moving. Will the source directory still be untouched?
Answer
If you move a directory on the same file system, you only move the directory entry from one location in the file system to another one. E.g., mv /source/dir /target/dir
will delete the directory entry of dir
from /source
and create a new one in /target
. That's done by one atomic system call (i.e., uninterruptable). The inode containing the directory entries of dir
as well as the actual content of the directory itself is not affected.
If you move the directory from one file system to another, all of the files are first copied to the new file system and then unlinked from the original one. So if you interrupt mv
while it’s copying, you may end up with two copies of some of the files – at the old location and at the new one.
No comments:
Post a Comment