Modifying replace string in xargs

前端 未结 8 1351
梦毁少年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
    
    0 讨论(0)
  • 2021-01-30 02:24

    The following command constructs the move command with xargs, replaces the second occurrence of '.' with '.bar.', then executes the commands with bash, working on mac OSX.

    ls *.txt | xargs -I {} echo mv {} foo/{} | sed 's/\./.bar./2' | bash
    
    0 讨论(0)
提交回复
热议问题