Make xargs execute the command once for each line of input

后端 未结 13 636
栀梦
栀梦 2020-11-29 15:09

How can I make xargs execute the command exactly once for each line of input given? It\'s default behavior is to chunk the lines and execute the command once, passing multip

13条回答
  •  温柔的废话
    2020-11-29 15:41

    You can limit the number of lines, or arguments (if there are spaces between each argument) using the --max-lines or --max-args flags, respectively.

      -L max-lines
             Use at most max-lines nonblank input lines per command line.  Trailing blanks cause an input line to be logically continued on the next  input
             line.  Implies -x.
    
      --max-lines[=max-lines], -l[max-lines]
             Synonym  for  the -L option.  Unlike -L, the max-lines argument is optional.  If max-args is not specified, it defaults to one.  The -l option
             is deprecated since the POSIX standard specifies -L instead.
    
      --max-args=max-args, -n max-args
             Use at most max-args arguments per command line.  Fewer than max-args arguments will be used if the size (see  the  -s  option)  is  exceeded,
             unless the -x option is given, in which case xargs will exit.
    

提交回复
热议问题