0%

RHCSA (EX200) - 查找文件

查找文件

查找归 jacques 所有的所有文件并将其副本放入 /root/findfiles 目录

1
2
3
4
5
6
7
[root@node1 ~]# mkdir /root/findfiles
[root@node1 ~]# find / -user jacques -exec cp -a {} /root/findfiles/ \;
[root@node1 ~]# ls -l /root/findfiles/
total 0
-rw-r--r--. 1 jacques root 0 Feb 19 11:56 gamelan
-rw-r--r--. 1 jacques jacques 0 Feb 19 11:56 jacques
-rw-r--r--. 1 jacques root 0 Feb 19 11:56 libWedgeit.so.1.2.3

Using the find -exec Command Option

5. The Delimiter

We need to provide the find command with a delimiter so it'll know where our -exec arguments stop.

Two types of delimiters can be provided to the -exec argument: the semi-colon(;) or the plus sign (+).

As we don't want our shell to interpret the semi-colon, we need to escape it (\;).

The delimiter determines the way find handles the expression results. If we use the semi-colon (;), the -exec command will be repeated for each result separately. On the other hand, if we use the plus sign (+), all of the expressions' results will be concatenated and passed as a whole to the -exec command, which will run only once.