代码改变世界

linux find查找并拷贝 exec xargs区别

2018-03-02 09:29  nigaopeng  阅读(441)  评论(0编辑  收藏  举报

-exec
    1.参数是一个一个传递的,传递一个参数执行一次rm
    2.文件名有空格等特殊字符也能处理
-xargs 
    1.一次将参数传给命令,可以使用-n控制参数个数
    2.处理特殊文件名需要采用如下方式:
    find . -name "*.txt" print0 |xargs -0 rm {} 

find /opt/test/ -type f -name "*.txt" -exec cp {} /tmp \;

find /opt/test/ -type f -name "*.txt" | xargs -i cp {} /tmp