I wrote an bash enumerator because I was sick of xargs
21–30 of 202 posts
Re: I wrote an bash enumerator because I was sick of xargs
#22Earlier quoted context omitted.
why would you ever pipe find into xargs instead of calling -exec? find -exec the '{}' iterated command ';'
Because xargs is faster. Exec will invoke the command once per matching file (which is sometimes what you want, of course)! While xargs will accumulate a bunch of file names, then when it as n names will invoke the command with those names, while continuing to accumulate names until n is reached or the pipe closes. The size of n depends on the system, but is usually at least a thousand.
find -exec command '{}' '+'
accumulates file arguments too. the only advantage of xargs is that you can tell it how many arguments to accumulate,̶ ̶t̶h̶e̶ ̶d̶o̶w̶n̶s̶i̶d̶e̶ ̶o̶f̶ ̶x̶a̶r̶g̶s̶ ̶i̶s̶ ̶t̶h̶a̶t̶ ̶y̶o̶u̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶s̶p̶e̶c̶i̶f̶y̶ ̶t̶h̶e̶ ̶n̶u̶m̶b̶e̶r̶,̶ ̶w̶h̶e̶r̶e̶a̶s̶ ̶f̶i̶n̶d̶ ̶j̶u̶s̶t̶ ̶f̶i̶t̶s̶ ̶a̶s̶ ̶m̶a̶n̶y̶ ̶a̶s̶ ̶i̶t̶ ̶c̶a̶n̶.̶Re: I wrote an bash enumerator because I was sick of xargs
#23Earlier quoted context omitted.
why would you ever pipe find into xargs instead of calling -exec? find -exec the '{}' iterated command ';'
Because xargs is faster. Exec will invoke the command once per matching file (which is sometimes what you want, of course)! While xargs will accumulate a bunch of file names, then when it as n names will invoke the command with those names, while continuing to accumulate names until n is reached or the pipe closes. The size of n depends on the system, but is usually at least a thousand.
I do it because I do it, just like why I use egrep and sed in pipes along with awk.
Re: I wrote an bash enumerator because I was sick of xargs
#24seq 1 10|xargs -I@ echo 'bash run.py @'|parallel -j 10
I know the echo is a little silly but then I can remove the |parallel and see if it's right. And if I don't want parallelism, I just pass to bash
Re: I wrote an bash enumerator because I was sick of xargs
#25in zsh you can just write: for x (*.sh); echo "before $x after" or for x in *.sh; echo "before $x after" or for x (*.sh) { echo -n "before "; echo -n $x; echo " after" }
for example
for a in `find / ` ; do echo $a ; done
will take A LOT of memory, while using find's -exec, xargs, or parallel will notRe: I wrote an bash enumerator because I was sick of xargs
#26Re: I wrote an bash enumerator because I was sick of xargs
#27find -print0 | xargs -0 -I {} "the {} iterated command"
why would you ever pipe find into xargs instead of calling -exec? find -exec the '{}' iterated command ';'
Re: I wrote an bash enumerator because I was sick of xargs
#28Earlier quoted context omitted.
Because xargs is faster. Exec will invoke the command once per matching file (which is sometimes what you want, of course)! While xargs will accumulate a bunch of file names, then when it as n names will invoke the command with those names, while continuing to accumulate names until n is reached or the pipe closes. The size of n depends on the system, but is usually at least a thousand.
the example as given does not accumulate, so that is what i worked with. find -exec command '{}' '+' accumulates file arguments too. the only advantage of xargs is that you can tell it how many arguments to accumulate,̶ ̶t̶h̶e̶ ̶d̶o̶w̶n̶s̶i̶d̶e̶ ̶o̶f̶ ̶x̶a̶r̶g̶s̶ ̶i̶s̶ ̶t̶h̶a̶t̶ ̶y̶o̶u̶ ̶h̶a̶v̶e̶ ̶t̶o̶ ̶s̶p̶e̶c̶i̶f̶y̶ ̶t̶h̶e̶ ̶n̶u̶m̶b̶e̶r̶,̶ ̶w̶h̶e̶r̶e̶a̶s̶ ̶f̶i̶n̶d̶ ̶j̶u̶s̶t̶ ̶f̶i̶t̶s̶ ̶a̶s̶ ̶m̶a̶n̶y̶ ̶a̶s̶ ̶i̶t̶ ̶c…
Re: I wrote an bash enumerator because I was sick of xargs
#29in zsh you can just write: for x (*.sh); echo "before $x after" or for x in *.sh; echo "before $x after" or for x (*.sh) { echo -n "before "; echo -n $x; echo " after" }
missed the point. reason to use xargs or parallel are generally two: list of arguments is too long, or list of arguments that is kept in memory would take too much for example for a in `find / ` ; do echo $a ; done will take A LOT of memory, while using find's -exec, xargs, or parallel will not
Re: I wrote an bash enumerator because I was sick of xargs
#30 find . -name '*.log' -print0 | xargs -0 rm
For this simple example (derived from the article), find also has a delete operator.This null termination is now a POSIX standard.