Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    ls won't work because of the amount of files in the folder. This is why I had to use find, thanks though. Commented Apr 26, 2012 at 8:19
  • 5
    @Toby: Try ls -f, which disables sorting. Sorting requires that the entire directory be loaded into memory to be sorted. An unsorted ls should be able to stream its output. Commented Apr 26, 2012 at 10:59
  • 2
    Does not work on filenames that contain newlines. Commented Jan 5, 2014 at 7:53
  • @camh that's true. But removing files in sorted order is faster than in unsorted (because of recalculating the btree of the directory after each deletion). See this answer for an example serverfault.com/a/328305/105902 Commented Jun 29, 2015 at 12:50
  • @maxschlepzig for such files you can use find . -print0 | xargs -0 rm, which will use the NULL char as filename separator. Commented Jun 29, 2015 at 12:51