Remove files in batches of x files

Every now and then I try to do things on a large amount of files – this often ends in a command error about “Too many files” or something similar. One solution to this is to send batches of information to the command instead of sending all at once.

Here is an example on how to delete files in batches of 1000 files:

ls | xargs -n 1000 rm -v

The trick here is the -n 1000 that will send the result from the ls command in batches of a 1000 results per time until the ls list is empty to rm. Neat ah? 🙂

Tested on RHEL 3

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

This site uses Akismet to reduce spam. Learn how your comment data is processed.