linux find查找并拷贝 exec xargs区别[转载]

-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

{} 标识find命令找到的文件

结束符有两种   ; 和 +

;会对每个找到item执行command

+ 会执行一次

-exec rm -f {} +   执行 rm -f 1 2 3 等同于
-exec rm -f {} ; 执行 rm -f 1 rm -f 2 rm -f 3
的作用是防止截断

转载于 https://www.cnblogs.com/howhy/p/6385736.html

原文地址:https://www.cnblogs.com/wolbo/p/12941346.html