Linux 學習:find命令習題

 1. 查找/var目錄屬主爲root,且屬組爲mail的所有文件

1
2


[root@www ~]# find /var \( -user root -a -group mail \) -ls
132134    4 drwxrwxr-x   2 root     mail         4096 9月 12 13:55 /var/spool/mail

2. 查找/usr目錄下不屬於root、bin或hadoop的所有文件

1
2


[root@www ~]# find /usr ! \( -user root -o -user bin -o -user hadoop \) -exec ls -l {} \;
-rwsr-xr-x. 1 abrt abrt 10296 7月  25 00:08 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

3. 查找/etc目錄下最近一週內其內容修改過,且屬主不爲root或hadoop的所有文件


1
2


[root@www ~]# find /etc ! \( -user root -o -user hadoop \) -mtime -7 -exec ls -l {} \;
-rw-r--r--. 1 bash root 0 9月  12 13:46 /etc/find_lab/find.txt

4.  查找當前系統上沒有屬主或屬組,且最近一週內曾被訪問過的所有文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


[root@www ~]# find / -atime -7 -a \( -nouser -o -nogroup \) -ls
131305    0 -rw-rw----   1 507      mail            0 9月 12 13:55 /var/spool/mail/rainman
find: “/proc/16541/task/16541/fd/5”: 沒有那個文件或目錄
find: “/proc/16541/task/16541/fdinfo/5”: 沒有那個文件或目錄
find: “/proc/16541/fd/5”: 沒有那個文件或目錄
find: “/proc/16541/fdinfo/5”: 沒有那個文件或目錄
430089    4 -rwxr--r--   1 507      abc            21 9月 11 13:33 /lab/readme.txt
    
39    4 drwx------   4 507      507          4096 9月 12 13:55 /home/rainman
    
40    4 -rw-r--r--   1 507      507            18 7月 24 02:55 /home/rainman/.bash_logout
    
41    4 drwxr-xr-x   2 507      507          4096 11月 12  2010 /home/rainman/.gnome2
    
47    4 -rw-r--r--   1 507      507           500 11月 27  2014 /home/rainman/.emacs
    
46    4 -rw-r--r--   1 507      507           176 7月 24 02:55 /home/rainman/.bash_profile
    
45    4 -rw-r--r--   1 507      507           124 7月 24 02:55 /home/rainman/.bashrc
    
42    4 drwxr-xr-x   4 507      507          4096 8月 17 19:31 /home/rainman/.mozilla
    
43    4 drwxr-xr-x   2 507      507          4096 8月 18  2010 /home/rainman/.mozilla/plugins
    
44    4 drwxr-xr-x   2 507      507          4096 8月 18  2010 /home/rainman/.mozilla/extensions

5. 查找/etc目錄下大於20K且類型爲普通文件的所有文件

1
2
3
4
5
6
7
8
9
10
11


[root@www ~]# find /etc -type f -size +20k -exec ls -l {} \; |head -n 10
-rw-r--r--. 1 root root 27223 11月 12 2010 /etc/sound/events/gnome-2.soundlist
-rw-r--r--. 
1 root root 34419 3月   4 2015 /etc/httpd/conf/httpd.conf
-rw-r--r--. 
1 root root 21214 6月  16 2014 /etc/dnsmasq.conf
-rw-r--r--. 
1 root root 23173 11月 21 2014 /etc/gimp/2.0/gimprc
-rw-r--r--. 
1 root root 29853 4月  10 00:44 /etc/sysconfig/network-scripts/network-functions-ipv6
-rw-r--r--. 
1 root root 45016 11月 11 2010 /etc/gconf/schemas/compiz-decoration.schemas
-rw-r--r--. 
1 root root 49322 11月 11 2010 /etc/gconf/schemas/compiz-wall.schemas
-rw-r--r--. 
1 root root 148031 11月 11 2010 /etc/gconf/schemas/gok.schemas
-rw-r--r--. 
1 root root 31365 11月 11 2010 /etc/gconf/schemas/gedit.schemas
-rw-r--r--. 
1 root root 32382 3月  14 2012 /etc/gconf/schemas/gweather.schemas

6. 查找/etc目錄下所有用戶都沒有寫權限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


[root@www ~]# find /etc ! -perm /222 -exec ls -l {} \;
-r-xr-xr-x. 1 root root 1340 7月  24 12:04 /etc/rc.d/init.d/blk-availability
-r-xr-xr-x. 
1 root root 3042 7月  24 12:04 /etc/rc.d/init.d/lvm2-monitor
-r-xr-xr-x. 
1 root root 2134 7月  24 12:04 /etc/rc.d/init.d/lvm2-lvmetad
-r--r--r--. 
1 root root 146 7月  24 19:09 /etc/pam.d/cups
-r--r--r--. 
1 root root 324 7月  24 00:14 /etc/ld.so.conf.d/kernel-2.6.32-573.el6.x86_64.conf
-r--------. 
1 root root 45 8月  17 19:37 /etc/openldap/certs/password
-r--r--r--. 
1 root root 359773 8月  17 19:34 /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-r--r--r--. 
1 root root 198453 8月  17 19:34 /etc/pki/ca-trust/extracted/java/cacerts
-r--r--r--. 
1 root root 266702 8月  17 19:34 /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
-r--r--r--. 
1 root root 217510 8月  17 19:34 /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
-r--r--r--. 
1 root root 211626 8月  17 19:34 /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
-r--r-----. 
1 root root 4002 3月   2 2012 /etc/sudoers
----------. 
1 root root 807 9月  12 14:00 /etc/gshadow-
----------. 
1 root root 1299 9月  12 14:01 /etc/shadow
-r--r--r--. 
1 root root 2249 7月  24 12:04 /etc/lvm/profile/command_profile_template.profile
-r--r--r--. 
1 root root 828 7月  24 12:04 /etc/lvm/profile/metadata_profile_template.profile
-r--r--r--. 
1 root root 80 3月  24 10:00 /etc/lvm/profile/thin-performance.profile
-r--r--r--. 
1 root root 76 3月  24 10:00 /etc/lvm/profile/thin-generic.profile
-r--r--r--. 
1 root root 460 7月  24 19:09 /etc/dbus-1/system.d/cups.conf
----------. 
1 root root 788 9月  12 14:01 /etc/gshadow
----------. 
1 root root 1329 9月  12 13:55 /etc/shadow-

7. 查找/etc目錄下至少有一類用戶沒有執行權限的文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


[root@www ~]# find /etc ! -perm -111 -exec ls -l {} \;
-rw-r--r--. 1 root root 12623 7月  24 09:34 /etc/autofs.conf
-rw-r--r--. 
1 root root 27223 11月 12 2010 /etc/sound/events/gnome-2.soundlist
-rw-r--r--. 
1 root root 18097 11月 12 2010 /etc/sound/events/gtk-events-2.soundlist
-rw-r--r--. 
1 root root 667 7月  24 09:34 /etc/auto.master
-rw-r--r--. 
1 root root 58 6月   3 2013 /etc/setuptool.d/99system-config-network-tui
-rw-r--r--. 
1 root root 45 6月   3 2013 /etc/setuptool.d/99sndconfig
-rw-r--r--. 
1 root root 47 6月   3 2013 /etc/setuptool.d/98system-config-display
-rw-r--r--. 
1 root root 69 6月   3 2013 /etc/setuptool.d/98system-config-authentication
-rw-r--r--. 
1 root root 62 6月   3 2013 /etc/setuptool.d/98system-config-keyboard
-rw-r--r--. 
1 root root 42 6月   3 2013 /etc/setuptool.d/99mouseconfig
-rw-r--r--. 
1 root root 59 6月   3 2013 /etc/setuptool.d/99system-config-firewall-tui
-rw-r--r--. 
1 root root 40 6月   3 2013 /etc/setuptool.d/99Xconfigurator
-rw-r--r--. 
1 root root 42 6月   3 2013 /etc/setuptool.d/98netconfig
-rw-r--r--. 
1 root root 50 6月   3 2013 /etc/setuptool.d/99authconfig
-rw-r--r--. 
1 root root 43 6月   3 2013 /etc/setuptool.d/99kbdconfig
-rw-r--r--. 
1 root root 44 6月   3 2013 /etc/setuptool.d/99timeconfig
-rw-r--r--. 
1 root root 33 6月   3 2013 /etc/setuptool.d/99ntsysv
-rw-r--r--. 
1 root root 46 6月   3 2013 /etc/setuptool.d/99printconf-tui
-rw-r--r--. 
1 root root 168 8月  19 2010 /etc/acpi/events/power.conf
-rw-r--r--. 
1 root root 236 8月  19 2010 /etc/acpi/events/video.conf

8.  查找/etc/init.d目錄下,所有用戶都有執行權限,且其它用戶擁有寫權限的文件

1
2


[root@www ~]# find /etc/init.d -perm -112 -exec ls -l {} \;
lrwxrwxrwx. 1 root root 11 8月  17 19:31 /etc/init.d -> rc.d/init.d

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章