搜索文件命令還有which,whereis(不經常使用),locate 組合鍵解釋: Ctrl+a : 光標移動到命令最前面; Ctrl+e:光標移到命令最後面; Ctrl+L:清屏 Ctrl+u:刪除光標前面全部的命令 概念:find命令 就是用於搜索文件 命令格式: find 路徑 參數 參數: -atime +n和-n :表示訪問或執行時間大於或小於n天的文件。 -ctime +n和-n :表示寫入、更改iNode屬性(如更改全部者、權限或者連接)的時間大於或小於n天的文件。 -mtime +n和-n :表示寫入時間大於或小於n天的文件,該參數用的最多。
find使用到的命令:node
- -type 經過文件類型查找文件 例: -type f 以文件類型找到
- -mtime 表示幾天內 或者幾天前的文件,mtime -1 一天內; mtime +10 10天前
- -size 表示文件字節選擇列出來的文件 例:-size +10k 大於10k的文件。
- -o 和,例:-type f -o -mtime -1 查看以文件類型和小於一天的文件。
- -exec 推進後面的命令,例: find /root/ -type f -mmin -120 -exec ls -l {} \; 把前面的命令 以ls -l列出來。
find命令的使用,例:若是知道在哪一個目錄下,而後知道文件名字,如何查找呢? find /etc/ -name "sshd_config"linux
[root@zhangzhen-01 ~]# find /etc/ -name "sshd_config" #在這裏find是搜索,-name空格後面雙引號跟文件全面查找以下
/etc/ssh/sshd_configbash
若是你只知道大概文件名,能夠用模糊查找 find /etc/ -name "sshd※"ssh
[root@zhangzhen-01 ~]# find /etc/ -name "sshd*" #在這裏,前面格式同樣,雙引號裏面sshd後面跟的是「※號」,表示通配符,以sshd開頭的文件所有列出來。
/etc/ssh/sshd_config
/etc/systemd/system/multi-user.target.wants/sshd.service
/etc/sysconfig/sshd
/etc/pam.d/sshdui
概念:-type filetype 表示經過文件類型查找文件。以下幾種文件類型 d 表示該文件爲目錄; f 表示該文件爲普通文件 l 表示該文件爲連接文件 (如軟連接 硬連接) b 表示該文件爲塊設備 c 表示該文件爲串行端口設備文件 s 表示該文件爲套接字文件 該命令格式以下: find /etc/ -type d -name "sshd*" #查找文件爲目錄的sshd*全部文件
概念:這個stat命令主要就是看最近訪問(atime)、最近更改(mtime)、和最近改動的時間(ctime)建立時間的。
使用命令以下:spa
[root@zhangzhen-01 ~]# stat dior
文件:"dior"
大小:32 塊:0 IO 塊:4096 目錄
設備:803h/2051d Inode:499801 硬連接:2
權限:(0755/drwxr-xr-x) Uid:( 0/ root) Gid:( 1001/ user1)
環境:unconfined_u:object_r:admin_home_t:s0
最近訪問:2018-03-29 00:31:52.739168672 +0800
最近更改:2018-03-28 22:44:38.990222665 +0800
最近改動:2018-03-29 00:31:40.627056046 +0800
建立時間:-.net
作個示例,搜索小於1天內,在/etc目錄下,最近訪問的塊設備有哪些。code
[root@zhangzhen-01 ~]# find /etc/ -type b -atime -1
[root@zhangzhen-01 ~]# find /etc/ -type f -atime -1
/etc/resolv.conf
/etc/pki/tls/openssl.cnf
/etc/pki/nss-legacy/nss-rhel7.config
/etc/rpm/macros.dist
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-CR.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repoblog在這裏,find表示搜索, 空格 後面跟須要搜索的文件,空格 -type(表示經過文件類型查找文件) 空格 後面 b(表示塊設備)空格 -atime(最近訪問)-1 (小於一天,能夠用「+」多少天之前的,「-」表示多少天之內的)
「-o」 表示或者,使用方法以下:ssl
[root@zhangzhen-01 ~]# find /etc/ -type f -o -mtime -1 -0 -name "*.com"
如何搜索硬連接,如何搜索iNode文件都有什麼。
[root@zhangzhen-01 ~]# ln anaconda-ks.cfg /tmp/23.txt.heh #作個硬連接到/tmp下建立個23.txt.heh的文件
[root@zhangzhen-01 ~]# ls -l anaconda-ks.cfg #下面的內容就是硬連接的文件
-rw-------. 2 root root 6901 3月 27 22:40 anaconda-ks.cfg
[root@zhangzhen-01 ~]# ls -i /tmp/23.txt.heh #查看剛硬連接的iNode號
33574978 /tmp/23.txt.heh
[root@zhangzhen-01 ~]# find / -inum 33574978 #查看iNode號的文件都有哪些
/root/anaconda-ks.cfg
/tmp/23.txt.heh
如何用find查看2小時以內的文件
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -120 **#-mmin後面跟分鐘數
/root/.bash_history
/root/dior/1.txt
若是利用find把查看的文件直接ls -l出來,格式以下:
root@zhangzhen-01 ~]# find /root/ -type f -mmin -120 -exec ls -l {} \;
-rw-------. 1 root root 9759 3月 31 00:22 /root/.bash_history
-rw-r--r--. 1 root root 15 3月 30 23:39 /root/dior/1.txt注:-exec也是find的一種格式,後面跟你要對文件進行的命令, {} 花括號表示ls -l出來的內容, \;反斜槓+分號只是讓他執行這個命令,推進出來。
如何利用find給以前建立的文件批量改後綴名呢,命令格式以下: -mmin
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -300
/root/.bash_history
/root/dior/1.txt
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -120 -exec mv {} {}.bak \;
[root@zhangzhen-01 ~]# find /root/ -type f -mmin -300
/root/dior/1.txt.bak
/root/.bash_history.bak注:第二個花括號表示所每個文件。
如何用find把大於10K的文件列出來。 -size +10k
[root@zhangzhen-01 ~]# find /root/ -type f -size +10k -exec ls -lh {} \;
-rwxr-xr-x. 2 root root 37K 8月 4 2017 /root/dior/login注:在這裏,小於就用「-」號,後面跟單位字節。
概念:在linux裏,命令有區分大小寫。 後綴名可自定義,不過通常都是分類進行區別,方便你們查找。 參考文獻:https://blog.csdn.net/fushaonian/article/details/72782651