日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux我ll查不到usr,Linux学习-文件查寻

發布時間:2024/4/17 linux 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux我ll查不到usr,Linux学习-文件查寻 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Linux學習---文件查找

grep, egrep, fgrep ?:文本查找

文件查找

locate

全系統查找,非實時,模糊匹配。查找時根據全系統文件數據庫進行的。

系統在每天的計劃任務時間生成數據庫。

updatedb ?手動生成文件數據庫。

速度快。

find

實時查找,精確。速度慢。

遍歷指定目錄中所有文件完成查找。

支持多種查找標準。

find ? PATH ? 查找標準 ? 找到后的處理動作

路徑默認:表示當前目錄

標準默認:指定路徑下所有文件

動作默認:為打印到屏幕上

查找標準:

-name: 根據文件名精確查找,做精確匹配。嚴格區分大小寫

支持文件名通配:

* ? ? ? ? ?[]

-iname : ?文件名匹配不區分大小寫。

[root@localhost shell_example]# find /etc -name passwd

/etc/passwd

/etc/pam.d/passwd

[root@localhost shell_example]# find /etc -name 'passwd*'

/etc/passwd

/etc/passwd-

/etc/pam.d/passwd

[root@localhost shell_example]# find /etc -name '*passwd'

/etc/passwd

/etc/security/opasswd

/etc/pam.d/passwd

-regex ?PATTERN ?:基于正則表達式進行文件查找。

-user ? USERNAME: 根據文件的屬主來查找

-group GROUPNAME: 根據屬組查找

一旦某個用戶被刪除,那么此前屬主是這個用戶的文件的屬主變成這個用戶此前的UID。

-uid: 根據UID查找

-gid: 根據GID查找

-nonuser :查找沒有屬主的文件。

-nogroup:查找沒有屬組的文件。

-type : 根據文件類型

f:普通文件

d:目錄文件

c: 字符設備

b:塊文件

l ?:鏈接文件,符號鏈接

p :管道文件

s :套接字文件

-size :根據文件大小。默認單位字節。

[+/-]#k

#M

#G

找 10M 的文件,所有9.xM 的文件都認為是10M。

組合條件:

-a: ?and

-o: ?or

-not: not

默認是 and 操作。

[root@localhost test]# find ./ -not -user user1 -ls

479024 0 drwxr-xr-x 2 root root 38 7月 18 21:43 ./

3670696 0 -rw-r--r-- 1 user2 root 0 7月 18 21:43 ./b

3692673 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./c

3692674 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./d

[root@localhost test]# find ./ -not -user user1 -a -not -user user2 -ls

479024 0 drwxr-xr-x 2 root root 38 7月 18 21:43 ./

3692673 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./c

3692674 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./d

[root@localhost test]# find ./ -not \( -user user1 -a -type d \)

./

./a

./b

./c

./d

./hi

[root@localhost test]# ll

總用量 0

-rw-r--r--. 1 user1 root 0 7月 18 21:43 a

-rw-r--r--. 1 user2 root 0 7月 18 21:43 b

-rw-r--r--. 1 root root 0 7月 18 21:43 c

-rw-r--r--. 1 root root 0 7月 18 21:43 d

drwxr-xr-x. 2 user1 root 6 7月 18 21:44 hello

drwxr-xr-x. 2 root root 6 7月 18 21:45 hi

-mtime:修改時間

-ctime: 改變時間

-atime: 訪問時間

# ? ? #天前

+# ? ?至少#天沒有

-# ? ? #天之內

[root@localhost test]# find /tmp -atime +7

/tmp/.X11-unix/X0

/tmp/.ICE-unix/3504

/tmp/.esd-1000/socket

/tmp/a.hadoop

/tmp/ssh-DqYXtl0A4ffy/agent.3504

/tmp/swap.txt

/tmp/sed.txt

/tmp/blandline.txt

/tmp/bash.txt

/tmp/nologin.txt

/tmp/.X0-lock

/tmp/set.txt

[root@localhost test]# find /tmp -atime +30

/tmp/.X11-unix/X0

/tmp/.ICE-unix/3504

/tmp/.esd-1000/socket

/tmp/a.hadoop

/tmp/ssh-DqYXtl0A4ffy/agent.3504

/tmp/.X0-lock

分鐘:

-mmin

-cmin

-amin

[root@localhost test]# find ./ -amin -5

[root@localhost test]# touch -a a

[root@localhost test]# find ./ -amin -5

./a

-perm MODE ?: 755 644 ?精確匹配權限來查找。

/MODE: 任意一位權限匹配即滿足條件。 ?或關系。

-MODE: 文件權限能完全包含此MODE時才顯示。 ?與關系。

[root@localhost test]# find ./ -perm 644 -ls

2121677 0 -rw-r--r-- 1 user1 root 0 7月 18 21:43 ./a

3670696 0 -rw-r--r-- 1 user2 root 0 7月 18 21:43 ./b

3692673 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./c

3692674 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./d

[root@localhost test]# chmod o-r a

[root@localhost test]# ll

總用量 0

-rw-r-----. 1 user1 root 0 7月 18 21:43 a

-rw-r--r--. 1 user2 root 0 7月 18 21:43 b

-rw-r--r--. 1 root root 0 7月 18 21:43 c

-rw-r--r--. 1 root root 0 7月 18 21:43 d

drwxr-xr-x. 2 user1 root 6 7月 18 21:44 hello

drwxr-xr-x. 2 root root 6 7月 18 21:45 hi

[root@localhost test]# find ./ -perm 644 -ls

3670696 0 -rw-r--r-- 1 user2 root 0 7月 18 21:43 ./b

3692673 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./c

3692674 0 -rw-r--r-- 1 root root 0 7月 18 21:43 ./d

[root@localhost test]# man chmod

[root@localhost test]# find ./ -perm /644

./

./a

./b

./c

./d

./hello

./hi

[root@localhost test]# find ./ -perm /640

./

./a

./b

./c

./d

./hello

./hi

[root@localhost test]# chmod 006 b

[root@localhost test]# find ./ -perm /640

./

./a

./c

./d

./hello

./hi

執行動作:

默認 -print ?:打印

-ls :類似 ls -l 的形式顯示每個文件的詳細信息。

-ok ?COMMAND ?{} ?\; ?反斜線分號結束。 每個操作需要用戶確認。

-exec ?COMMAND {} ?\; ? 無需確認,直接執行。

[root@localhost test]# ll

總用量 0

-rw-r-----. 1 user1 root 0 7月 18 21:43 a

-------rw-. 1 user2 root 0 7月 18 21:43 b

-rw-r--r--. 1 root root 0 7月 18 21:43 c

-rw-r--r--. 1 root root 0 7月 18 21:43 d

drwxr-xr-x. 2 user1 root 6 7月 18 21:44 hello

drwxr-xr-x. 2 root root 6 7月 18 21:45 hi

[root@localhost test]# find ./ -perm -006

./b

[root@localhost test]# find ./ -perm -006 -exec chmod o-rw {} \;

[root@localhost test]# ll

總用量 0

-rw-r-----. 1 user1 root 0 7月 18 21:43 a

----------. 1 user2 root 0 7月 18 21:43 b

-rw-r--r--. 1 root root 0 7月 18 21:43 c

-rw-r--r--. 1 root root 0 7月 18 21:43 d

drwxr-xr-x. 2 user1 root 6 7月 18 21:44 hello

drwxr-xr-x. 2 root root 6 7月 18 21:45 hi

[root@localhost test]# find ./ -type d -ok chmod +x {} \;

< chmod ... ./ > ?

< chmod ... ./hello > ?

< chmod ... ./hi > ?

[root@localhost test]# find ./ -perm -060 -exec mv {} {}.new \;

[root@localhost test]# ll

總用量 0

-rw-rw-r--. 1 root root 0 7月 18 21:43 1.new.new

-rw-r-----. 1 user1 root 0 7月 18 21:43 a

-rw-rw-rw-. 1 root root 0 7月 18 22:24 b.new

-rw-r--r--. 1 root root 0 7月 18 21:43 c

-rw-rw-rw-. 1 root root 0 7月 18 22:24 d.new

drwxr-xr-x. 2 user1 root 6 7月 18 21:44 hello

drwxr-xr-x. 2 root root 6 7月 18 21:45 hi

找到所有.sh 結尾的并且所有用戶都有執行權限的文件,將其他用戶的執行權限去掉。

[root@localhost sh]# find ./ -name "*.sh" -perm -111 -exec chmod o-x {} \;

[root@localhost sh]# ll

總用量 112

-rwxr-xr--. 1 root root 153 7月 18 22:28 add.sh

-rwxr-xr--. 1 root root 647 7月 18 22:28 adduser.sh

-rwxr-xr--. 1 root root 303 7月 18 22:28 bash2.sh

-rwxr-xr--. 1 root root 209 7月 18 22:28 bash.sh

-rwxr-xr--. 1 root root 57 7月 18 22:28 calc.sh

-rwxr-xr--. 1 root root 267 7月 18 22:28 cpu.sh

-rwxr-xr--. 1 root root 340 7月 18 22:28 expired.sh

-rwxr-xr--. 1 root root 232 7月 18 22:28 file.sh

-rwxr-xr--. 1 root root 194 7月 18 22:28 filetest1.sh

-rwxr-xr--. 1 root root 227 7月 18 22:28 filetest.sh

-rwxr-xr--. 1 root root 148 7月 18 22:28 history.sh

-rwxr-xr--. 1 root root 296 7月 18 22:28 lees4.sh

-rwxr-xr--. 1 root root 155 7月 18 22:28 less1.sh

-rwxr-xr--. 1 root root 70 7月 18 22:28 less2.sh

-rwxr-xr--. 1 root root 394 7月 18 22:28 less3_1.sh

-rwxr-xr--. 1 root root 201 7月 18 22:28 less3_2.sh

-rwxr-xr--. 1 root root 206 7月 18 22:28 less3.sh

-rwxr-xr--. 1 root root 254 7月 18 22:28 sayhi.sh

-rwxr-xr--. 1 root root 66 7月 18 22:28 shift.sh

-rwxr-xr--. 1 root root 1209 7月 18 22:28 statisticsshell.sh

-rwxr-xr--. 1 root root 262 7月 18 22:28 string.sh

-rwxr-xr--. 1 root root 249 7月 18 22:28 sum2.sh

-rwxr-xr--. 1 root root 188 7月 18 22:28 sum3.sh

-rwxr-xr--. 1 root root 85 7月 18 22:28 sum.sh

-rwxr-xr--. 1 root root 49 7月 18 22:28 test1.sh

-rwxr-xr--. 1 root root 116 7月 18 22:28 than.sh

-rwxr-xr--. 1 root root 366 7月 18 22:28 usermanage.sh

-rwxr-xr--. 1 root root 167 7月 18 22:28 utest.sh

練習:

1、找到/var下屬主root ?屬組mail的所有文件

[root@localhost sh]# find /var -user root -group mail -ls

100664298 4 drwxrwxr-x 2 root mail 4096 7月 18 21:40 /var/spool/mail

103419761 196 -rw------- 1 root mail 198458 6月 12 23:23 /var/spool/mail/root

2、找到/usr下不屬于root、bin或student的文件

[root@localhost sh]# find /usr -not \( -user root -o -user bin -o -user beny \) -ls

68744954 4 drwx------ 2 polkitd root 4096 4月 25 22:10 /usr/share/polkit-1/rules.d

34704584 16 -rwsr-sr-x 1 abrt abrt 15336 12月 1 2015 /usr/libexec/abrt-action-install-debuginfo-to-abrt-cache

3、找/etc下最近一周內內容修改且不屬于root及student用戶的文件

[root@localhost sh]# find /etc -mtime -7 -not -user root -ls

4、找當前系統沒有屬主或屬組且最近1天內訪問過,并將屬主、屬組改為root

[root@localhost sh]# find / -nouser -nogroup -exec chown root:root {} \;

5、找/etc下大于1M的文件并寫入/tmp/etc.largefiles

[root@localhost sh]# find /etc/ -size +1M -exec cp {} /tmp/etc.largefiles \;

[root@localhost sh]# ls -lh /tmp/etc.largefiles

-r--r--r--. 1 root root 1.4M 7月 18 22:55 /tmp/etc.largefiles

6、找/etc下所有用戶都沒有寫權限的文件,顯示詳細信息。

總結

以上是生活随笔為你收集整理的linux我ll查不到usr,Linux学习-文件查寻的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。