I have a large folder with a few million files on my external hard drive that I have to delete. Using rm -rf works, but is very slow due to the sheer amount of files, and the size of the folder.

Files that are in /tmp/ seem to be deleted instantly on reboot, no matter how big they are or how many files there are. So I am wondering if it is possible to give a folder on an external drive the same attributes as, and make it behave in the same way as /tmp/.


rm is only necessary because you want to delete one piece of data (a specific file), while leaving the rest of the data on the filesystem in place.

If you segregate your data so that you can retire all the data at the same time, then you don't have to remove the pieces individually. You can discard (and probably recreate) the filesystem quickly.

/tmp is often created using virtual memory as the storage space instead of a disk partition. When this is true, the data is not stable across reboots, so it is created (empty) at every boot.

You can't do that with a folder, but you can create a separate filesystem and mount it at the location you want. When you're ready to expire the data, you need to unmount it, recreate it, then remount it. Should take a few seconds.


The difference in performance that you are seeing is likely because your /tmp directory is mounted in RAM as opposed to physical storage. You can check this with mount.

Also different types of file systems have different performance impacts in certain operations. XFS should outperform ext4, as should btrfs.

These links could be useful too:

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.