Sunday 7 January 2018

linux - What happens if mv is interrupted?


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

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...