Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So I may have kind of accidentally rm -r'd ~. Not to worry, I have backups! I did a quick file listing diff to copy across files that were removed, all is good. But...

Does GNU rm corrupt files if I interrupt it? Surely it was just unlinking gigabytes of my priceless data a second, rather than removing the file from the disk itself?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

No. rm just calls unlink() to remove the name. This syscall is atomic, meaning it either succeeds in removing the name, or does not. It can not be interrupted. If you interrupt rm while it is unlink()ing multiple files, then some files will be successfully removed, and some will not be. Housekeeping such as freeing the blocks the file was using if all links have been removed is a separate operation and may be done later, and if this is interrupted ( by a power failure or system crash, not interrupting rm ), the filesystem may require a fsck to finish it, but most filesystems these days are journaled so they do not need this. Either way, the file is either removed, or not, there is no in between.

share|improve this answer
add comment

From Wikipedia

To be more precise, rm removes references to objects from the filesystem, where those objects might have had multiple references (for example, a file with two different names), and the objects themselves are discarded only when all references have been removed and no programs still have open handles to the objects.

So yeah, your unlinking analogy is pretty good. If you have multiple hard links to a file, the data won't be marked ask discardable until all links are gone (symlinks don't qualify, hard links only).

If you have backups, it might be a good idea to do some md5 or sha1 hashes on the backups and your home directory, and diff them to spot any changes, but as long as you restored teh missing files, the files that stuck around shouldn't suffer any corruption.

As always, YMMV.

share|improve this answer
    
Hmm... To be more clear, would interrupting rm during a huge file delete cause corruption (if only half the file was deleted?) I'd find this unlikely if it only removes references, but I need to be sure. –  Jookia Jan 26 '13 at 1:39
    
If you need to be sure, then run a check using hashes. Trust but verify. –  peelman Jan 26 '13 at 1:48
    
Eh, I don't think I have a slow enough computer to test the hypothesis. I'll go read the source code. –  Jookia Jan 26 '13 at 1:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.