歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Linux 學習:find命令習題

Linux 學習:find命令習題

日期:2017/3/3 16:55:56   编辑:關於Linux

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

Copyright © Linux教程網 All Rights Reserved