My understanding is that running rm on a file simply unlinks it, marking the space as free in the filesystem. It should then follow that deleting one file always takes roughly the same amount of time (i.e. delete speed is proportional to number of files, not size of files).

So why does deleting a 15 GB file take over a minute with a simple rm file.tar.gz?

  • 5
    What filesystem? – Shane Madden Sep 7 '12 at 3:23
  • 8
    On many file systems, each "block" of free space has to be "marked" free. Large files have more blocks. This is not true of all file systems though! – Chris S Sep 7 '12 at 3:25
  • @ShaneMadden good question; ext4 right now, but I've noticed it on other ext#'s as well. – Tom Marthenal Sep 7 '12 at 3:28
  • That's why every file should have it's own virtualized filesystem so the inodes can be blindly wiped super fast! <JEST> – thinice Sep 7 '12 at 3:56
  • 1
    Which filesystem would perform better at this case? I am right now using a portable drive to move large VM disks from one machine to another and rm taking forever is driving me nuts. – motobói May 6 '14 at 2:30

It takes a constant amount of time to unlink a single block, but files beyond the size of a single block consist of multiple blocks linked together, and the larger the file the larger the quantity of blocks that are linked.

  • 15
    <BSD Zealot> mumble mumble UFS mumble mumble soft updates mumble mumble delete stuff faster mumble mumble pancakes! </BSD Zealot> – voretaq7 Sep 7 '12 at 3:45
  • XFS deletes large files very rapidly, but large numbers of small files very slowly. – Andrew Sep 7 '12 at 4:37
  • 5
    One file will always just use one inode. It does use multiple data blocks. – Simon Richter Sep 7 '12 at 7:58
  • 2
    One block to rule them all, one block to find them, One block to bring them all and in the darkness bind them. – Rqomey Sep 13 '12 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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