Linux – Are there limits to file length piped from find to xargs or using find -exec +

findlinuxshell

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?

Best Answer

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

Related Question