How to delete thousands of files

Tutorial to delete millions of files without using 100% of available resources.

How to delete thousands of files

Let's say we have a folder containing millions of small files, images, temporary files or the like that we want to delete to regain valuable resources. Using a simple rm -rf folder may take a lot of time and use up 100% disk and CPU resources.

Linux provides 2 commands which can decrease resource usage (ionice and nice). However, using them with rm command does not seem to work correctly and still uses all resources in some cases.

We could use the rsync command to works around the problem.

You must first create an empty folder ...

mkdir empty

It is then possible to synchronize the 2 folders.

ionice -c 3 nice -19 rsync -a --delete empty/ folder/

This will then delete all the contents of the folder folder.

Need help?

You did not found what your were looking for?

Speak with one of our specialists today.

By email

Other suggestions

Accéder au contenu d'un fichier qcow2

Linux Ubuntu

Tutoriel pour accéder au contenu d'un fichier .qcow2 sur un serveur Linux.

Commandes Linux utiles

CentOS Linux Ubuntu

Liste de commandes Linux utile tous les jours.

Comment supprimer des milliers de fichiers

Linux

Tutoriel pour supprimer des millions de fichiers sans utiliser 100% des resources disponible.