How to delete long list of files in Linux?

Let’s say you have a long list of files that you want to delete and simply running rm -fv * just won’t work and Linux will let you know by giving you this error:

Argument list too long.

When you get this error, it means that the number of files is too many for the kernel to process.

There is a simple workaround for this.

By using xargs, you can pipe xargs into the command to process each output. This can be done like so:

ls | xargs rm -fv

This command will list all files in the working directory and execute delete without confirmation.

If it still returns the same error, you can use find and pipe xargs.

find . -type f | xargs rm -fv

The command find will search the current directory for all files, excluding directories, and delete without confirmation.

xargs is a versatile Linux and you can use the man page anytime if you want to know more.

man xargs

Popularity: 9% [?]

Share and Enjoy:
  • E-mail this story to a friend!
  • StumbleUpon
  • Digg
  • Technorati
  • del.icio.us
  • Reddit
  • Facebook
  • Google
  • Slashdot
  • Blogosphere News
  • TwitThis
  • NewsVine
  • Propeller
  • Furl
  • Simpy
  • Spurl

Related Posts