命令
用find查找/data目录下,以.txt文件结尾的文件并复制到/tmp下
方法一
find与|xargs是黄金搭档,-t参数指定目标目录
[[email protected] ~]# find /data/ -type f -name"*.txt" | xargs cp -t /tmp
方法二
{}大括号里的内容为find命令找到的结果
[[email protected] ~]# find /data/ -type f -name"*.txt" -exec cp {} /tmp \;
方法三
$()=` ` 存放命令的执行结果
[[email protected] ~]# cp $(find /data/ -type f -name"*.txt") /tmp
方法四
-i参数指定找到的结果放到{}中
[[email protected] ~]# find/data/ -type f -name "*.txt" | xargs -i cp{} /tmp
来源: http://www.bubuko.com/infodetail-2283189.html