**示例:**用find查找/data目录下,以.txt文件结尾的文件并复制到/tmp下
方法一
find与|xargs是黄金搭档,-t参数指定目标目录,使用管道实现复制
[root@centos ~]# ls /tmp
[root@centos ~]# find /date/ -type f -name "*.txt" | xargs cp -t /tmp
[root@centos ~]# ls /tmp
1.txt
[root@centos ~]#
方法二
{}大括号里的内容为find命令找到的结果
[root@centos ~]# ls /tmp
[root@centos ~]# find /date/ -type f -name "*.txt" -exec cp {} /tmp \;
[root@centos ~]# ls /tmp
1.txt
[root@centos ~]#
方法三
$()=`` 存放命令的执行结果
[root@centos ~]# ls /tmp
[root@centos ~]# cp $(find /date/ -type f -name "*.txt") /tmp
[root@centos ~]# ls /tmp
1.txt
[root@centos ~]#
方法四
-i参数指定找到的结果放到{}中,使用管道实现
[root@centos ~]# ls /tmp
[root@centos ~]# find /date/ -type f -name "*.txt" | xargs -i cp {} /tmp
[root@centos ~]# ls /tmp
1.txt
[root@centos ~]#