Modifying replace string in xargs

前端 未结 8 1536
梦毁少年i
梦毁少年i 2021-01-30 01:43

When I am using xargs sometimes I do not need to explicitly use the replacing string:

find . -name \"*.txt\" | xargs rm -rf

In oth

8条回答
  •  天命终不由人
    2021-01-30 02:22

    Adding on that the wikipedia article is surprisingly informative

    for example:

    Shell trick

    Another way to achieve a similar effect is to use a shell as the launched command, and deal with the complexity in that shell, for example:

    $ mkdir ~/backups
    $ find /path -type f -name '*~' -print0 | xargs -0 bash -c 'for filename; do cp -a "$filename" ~/backups; done' bash
    

提交回复
热议问题