Make xargs execute the command once for each line of input

后端 未结 13 532
栀梦
栀梦 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

    These two ways also work, and will work for other commands that are not using find!

    xargs -I '{}' rm '{}'
    xargs -i rm '{}'
    

    example use case:

    find . -name "*.pyc" | xargs -i rm '{}'
    

    will delete all pyc files under this directory even if the pyc files contain spaces.

提交回复
热议问题