39

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
  • 5
    What filesystem? Sep 7, 2012 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, 2012 at 3:25
  • @ShaneMadden good question; ext4 right now, but I've noticed it on other ext#'s as well. Sep 7, 2012 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, 2012 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, 2014 at 2:30

1 Answer 1

46

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.

5
  • 15
    <BSD Zealot> mumble mumble UFS mumble mumble soft updates mumble mumble delete stuff faster mumble mumble pancakes! </BSD Zealot>
    – voretaq7
    Sep 7, 2012 at 3:45
  • XFS deletes large files very rapidly, but large numbers of small files very slowly.
    – Andrew
    Sep 7, 2012 at 4:37
  • 5
    One file will always just use one inode. It does use multiple data blocks. Sep 7, 2012 at 7:58
  • 4
    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, 2012 at 20:02
  • 1
    For anyone else wondering what this block size is: "Block size is specified at mkfs time and typically is 4KiB." More info at: ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Blocks
    – Luc
    Jan 23, 2022 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .