Modifying replace string in xargs

前端 未结 8 1540
梦毁少年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:21

    It is possible to do this in one pass (tested in GNU) avoiding the use of the temporary variable assignments

    find . -name "*.txt" | xargs -I{} sh -c 'mv "$1" "foo/$(basename ${1%.*}).new.${1##*.}"' -- {}
    

提交回复
热议问题