Linux 里面的find 命令与cp命令的使用
示例:用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 /tmp1.txt
   ·  
 示例:用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 ~]#总结:以上四种方法都可以做到find命令与cp命令的组合使用,生活工作中可根据自身需求任选其中之一就可以了。如果对你有帮助的话,希望支持呀。
更多推荐
 
 



所有评论(0)