Example : use find lookup /data Under the directory , with .txt File at the end of the file and copy to /tmp lower
Method 1
find And |xargs It's a golden partner ,-t Parameter specifies the target directory , Using pipes for replication
[root@centos ~]# ls /tmp [root@centos ~]# find /date/ -type f -name "*.txt" |
xargs cp -t /tmp [root@centos ~]# ls /tmp 1.txt [root@centos ~]#
Method 2
{} The content in braces is find Results found by command
[root@centos ~]# ls /tmp [root@centos ~]# find /date/ -type f -name "*.txt"
-exec cp {} /tmp \; [root@centos ~]# ls /tmp 1.txt [root@centos ~]#
Method 3
$()=`` Store the execution result of the command
[root@centos ~]# ls /tmp [root@centos ~]# cp $(find /date/ -type f -name
"*.txt") /tmp [root@centos ~]# ls /tmp 1.txt [root@centos ~]#
Method 4
-i Parameter specifies that the found results are placed in {} in , Using pipes to achieve
[root@centos ~]# ls /tmp [root@centos ~]# find /date/ -type f -name "*.txt" |
xargs -i cp {} /tmp [root@centos ~]# ls /tmp 1.txt [root@centos ~]#
summary : The above four methods can be achieved find Command and cp Combined use of commands , You can choose one of them according to your own needs in life and work . If it helps you , Hope to support .
Technology
Daily Recommendation