Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In question [ Find and delete all the directories named "test" in linux ] on this site, the best answer talks about using these two commands:

find . -name test -type d -print0|xargs -0 rm -r --
find . -name test -type d -exec rm -r {} +

because they will call rm with a list of directory instead of invoking it many times individually.

Since I cannot comment there due to low reputation, I ask here in a new question:

Is there any limit on the number of files that can be passed to rm using these techniques (aside from realistic system resource bounds)?

From the shell, a command like 'rm *' can exceed the shell's maximum command-line length, but do limits like that apply to this usage of find + or via a pipe to xargs?

share|improve this question
up vote 1 down vote accepted

In short, no.

The long answer: - Find will run the command specified by exec for every match, so if your find turns up 20 files, it will run 20 seperate instances of rm. - xargs will determine the maximum command length for your shell and add arguments within these limits as you can see with the output of xargs --show-limits mtak@frisbee:~$ xargs --show-limits Your environment variables take up 4050 bytes POSIX upper limit on argument length (this system): 2091054 POSIX smallest allowable upper limit on argument length (all systems): 4096 Maximum length of command we could actually use: 2087004 Size of command buffer we are actually using: 131072

share|improve this answer
    
Using the + in find's -exec will cause it to pass a list rather than invoke rm for each file. It seems to pass ~128k of filenames at a time, so it apparently has similar logic to xargs. Thank you for pointing out that option to xargs! – user9999999 Apr 2 '14 at 22:45
    
Thank you for clarifying. I always use find with the -exec rm {} \; option. – mtak Apr 2 '14 at 22:46
    
I did too, and it's slow when deleting thousands of files, so I want to start using the + but was worried about it. Your answer about xargs made me think to write a test.pl to use instead of calling 'rm', which reported the number of args and their length -- so I could verify it behaved intelligently like xargs. – user9999999 Apr 2 '14 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .