linux文件查找之find命令
find
在windows中,我們想查找文件時,只需要在查找中輸入您想要查找的東西,對於linux來說,沒有那麽方便的圖像查找,但是使用find命令,將會是最好的選擇,find具有強大的查找命令方式,之前,聽一個學長說他面試jd的時候,問道的第一個問題就是你怎樣查找系統中大於10M 的文件,因此對find命令在我心裏就更為重視了,這會正好總結以下
find 查找位置 -條件 條件值 -exec 動作 {} \;
1>通過文件名查找文件地址
find / -name vsftpd.conf
-iname:按照文件名查找文件,且不區分大小寫
[[email protected]
2>通過部分文件名查找
find / -name *httpd*
[[email protected] Desktop]# find / -name *httpd* /run/httpd /run/httpd/httpd.pid find: ‘/run/user/1000/gvfs’: Permission denied /sys/fs/cgroup/devices/system.slice/httpd.service /sys/fs/cgroup/systemd/system.slice/httpd.service /etc/sysconfig/httpd /etc/systemd/system/multi-user.target.wants/httpd.service /etc/logrotate.d/httpd /etc/httpd /etc/httpd/conf/httpd.conf
3>無錯誤輸出查找
find / -name vsftpd.conf 2>/dev/null
[[email protected] Desktop]# find / -name vsftpd.conf 2>/dev/null /etc/vsftpd/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/INTERNET_SITE_NOINETD/vsftpd.conf /usr/share/doc/vsftpd-3.0.2/EXAMPLE/VIRTUAL_USERS/vsftpd.conf [[email protected] Desktop]#
4>根據文件的特征查詢方法
find / -user student #查找文件屬主用戶為student的文件
find / -group zpy #查找文件屬主小組為zpy的文件
find / -uid 1001 #-uid:UID:當某個用戶被刪除,用戶所屬的文件UID沒有被刪除,在這個情況下就可以使用此選項
[[email protected] Desktop]# userdel zpy [[email protected] Desktop]# find / -uid 1001
find /tmp -nouser -nogrouop:查找沒有有效所屬組的文件,即該文件所屬的組在/etc/groups中不存在
find / -type 類型
在Linux文件系統中常用到的文件類型有:
b:塊設備文件
d:目錄
c:字符設備文件
p:管道文件
l:符號鏈接文件
f:普通文件
s:套接字設備文件
p:管道設備文件
find / -size 文件大小
find /mnt -size 10k ##查找10k文件
find /mnt -size -10k ##查看小於10k 文件
find /mnt -size +10k ##查看大於10k文件
find / -perm 755 ##尋找權限為755的文件
find /mnt -user student -a -group linux ##-a表示既滿足前者又滿足後者
find / -user student -a -group shengchan ##0表示滿足前者或後者
find / -maxdepth 2 -name passwd ##最大的目錄遞進為2
[[email protected] Desktop]# find / -maxdepth 2 -name passwd /etc/passwd [[email protected] Desktop]# find / -mindepth 2 -name passwd find: ‘/run/user/1000/gvfs’: Permission denied /etc/passwd /etc/pam.d/passwd /usr/bin/passwd /usr/share/bash-completion/completions/passwd
本文出自 “12462896” 博客,請務必保留此出處http://12472896.blog.51cto.com/12462896/1953763
linux文件查找之find命令