0%

创建存档

创建一个名为 /root/backup.tar.gz 的 tar 存档,其应包含 /usr/local 的 tar 存档,其应包含 /usr/local 的内容。该 tar 存档必须使用 gzip 进行压缩。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
[root@node1 ~]# tar -czvf /root/backup.tar.gz /usr/local
tar: Removing leading `/' from member names
/usr/local/
/usr/local/bin/
/usr/local/etc/
/usr/local/games/
/usr/local/include/
/usr/local/lib/
/usr/local/lib64/
/usr/local/libexec/
/usr/local/sbin/
/usr/local/sbin/rht-vmsetup-ifcfg
/usr/local/sbin/rht-vmsetup-getkeys
/usr/local/sbin/rht-vmsetup-getcourse
/usr/local/sbin/rht-vmsetup-reseal
/usr/local/share/
/usr/local/share/applications/
/usr/local/share/applications/mimeinfo.cache
/usr/local/share/info/
/usr/local/share/man/
/usr/local/share/man/man1/
/usr/local/share/man/man1x/
/usr/local/share/man/man2/
/usr/local/share/man/man2x/
/usr/local/share/man/man3/
/usr/local/share/man/man3x/
/usr/local/share/man/man4/
/usr/local/share/man/man4x/
/usr/local/share/man/man5/
/usr/local/share/man/man5x/
/usr/local/share/man/man6/
/usr/local/share/man/man6x/
/usr/local/share/man/man7/
/usr/local/share/man/man7x/
/usr/local/share/man/man8/
/usr/local/share/man/man8x/
/usr/local/share/man/man9/
/usr/local/share/man/man9x/
/usr/local/share/man/mann/
/usr/local/src/
[root@node1 ~]# file /root/backup.tar.gz
/root/backup.tar.gz: gzip compressed data, last modified: Tue Feb 21 03:47:17 2023, from Unix, original size 51200

查找字符串

查找文件 /usr/share/xml/iso-codes/iso_639_3.xml 中包含字符串 ng 的所有行。将所有这些行的副本按原始顺序放在文件 /root/list 中。/root/list 不得包含空行,且所有行必须是 /usr/share/xml/iso-codes/iso_639_3.xml 中原始行的确切副本。

1
[root@node1 ~]# grep ng /usr/share/xml/iso-codes/iso_639_3.xml > /root/list

创建脚本

创建一个名为 myresearch 的脚本

该脚本放置在 /usr/bin

该脚本用来查找 /usr 下所有小于 10m 且具有修改 SGID 权限的文件,将这些文件名称放置于 /root/myfiles 文件中

创建脚本

创建一个名为 newsearch 的脚本

该脚本放置在 /usr/bin

该脚本用来查找 /usr 下所有大于 30k,但是小于 50k 且具有 SUID 权限的文件,将这些文件名列表保存在 /root/newfiles 文件中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@node1 ~]# find /usr -size -10M -perm /2000 | xargs ls -lh
-rwx--s--x. 1 root slocate 47K Aug 12 2018 /usr/bin/locate
-rwxr-sr-x. 1 root tty 21K Dec 17 2019 /usr/bin/write
-r-xr-sr-x. 1 root ssh_keys 619K Jan 8 2020 /usr/libexec/openssh/ssh-keysign
-rwx--s--x. 1 root utmp 13K Aug 12 2018 /usr/libexec/utempter/utempter
[root@node1 ~]# vim /usr/bin/myresearch
#!/bin/bash
find /usr -size -10M -perm /2000 > /root/myfiles
[root@node1 ~]# chmod +x /usr/bin/myresearch
[root@node1 ~]# /usr/bin/myresearch
[root@node1 ~]# cat /root/myfiles
/usr/bin/write
/usr/bin/locate
/usr/libexec/utempter/utempter
/usr/libexec/openssh/ssh-keysign
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@node1 ~]# find /usr -size +30k -size -50k -perm /4000 | xargs ls -lh
-rws--x--x. 1 root root 33K Dec 17 2019 /usr/bin/chfn
-rwsr-xr-x. 1 root root 33K Dec 13 2019 /usr/bin/passwd
-rwsr-xr-x. 1 root root 33K Dec 17 2019 /usr/bin/umount
-rwsr-x---. 1 root cockpit-wsinstance 46K Mar 12 2020 /usr/libexec/cockpit-session
-rwsr-xr-x. 1 root root 37K Dec 19 2019 /usr/sbin/unix_chkpwd
-rws--x--x. 1 root root 47K Nov 20 2018 /usr/sbin/userhelper
[root@node1 ~]# vim /usr/bin/newsearch
#!/bin/bash
find /usr -size +30k -size -50k -perm /4000 > /root/newfiles
[root@node1 ~]# chmod +x /usr/bin/newsearch
[root@node1 ~]# /usr/bin/newsearch
[root@node1 ~]# cat /root/newfiles
/usr/bin/umount
/usr/bin/passwd
/usr/bin/chfn
/usr/sbin/unix_chkpwd
/usr/sbin/userhelper
/usr/libexec/cockpit-session

-perm 选项用于查找具有特定权限集的文件。权限可以描述为八进制值,包含代表读取、写入和执行的 4、2 和 1 的某些组合。权限前面可以加上 / 或 - 符号。

前面带有 / 的数字权限将匹配文件的用户、组、其他人权限集中的至少一位。权限为 r--r--r-- 的文件并不匹配 /222,权限为 rw-r--r-- 的文件才匹配。权限前带有 - 符号表示该位的所有三个实例都必须存在,因此前面的两个示例都不匹配,但诸如 rw-rw-rw- 的对象则匹配。

与 / 或 - 一起使用时,0 值类似于通配符,因此其表示至少无任何内容的权限。

查找文件

查找归 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.

配置用户帐号

配置用户 manalo,其用户 ID 为 3533。此用户的密码应当为 flectrag

1
2
3
4
5
6
[root@node1 ~]# useradd -u 3533 manalo
[root@node1 ~]# echo flectrag | passwd --stdin manalo
Changing password for user manalo.
passwd: all authentication tokens updated successfully.
[root@node1 ~]# id manalo
uid=3533(manalo) gid=3533(manalo) groups=3533(manalo)