Make xargs execute the command once for each line of input

后端 未结 13 681
栀梦
栀梦 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:32

    The following command will find all the files (-type f) in /path and then copy them using cp to the current folder. Note the use if -I % to specify a placeholder character in the cp command line so that arguments can be placed after the file name.

    find /path -type f -print0 | xargs -0 -I % cp % .

    Tested with xargs (GNU findutils) 4.4.0

提交回复
热议问题