find命令node
find [option]... [查找路徑] [查找條件] [處理動做]vim
好比:find / -type d -name sysconfigcentos
查找路徑:默認爲當前路徑bash
查找條件:指定的查找標準,能夠根據文件名、大小、屬主屬組、類型等進行;默認爲找出指定路徑下的全部文件;less
處理動做:對符合條件的文件作指定操做;默認輸出至屏幕ssh
-type 類型:目錄d 文件f等ide
-mtime 時間:+10天表明10天之前 -10天表明10天之內centos7
-mmin 分鐘:-60表明一小時之內spa
-size 大小:k,Morm
-o 各參數之間的與或關係
-exec 搜索結果執行後一命令
-name 文件名,支持模糊名稱
[root@24centos7-01 tmp]# find /usr -name ls
/usr/bin/ls
[root@24centos7-01 tmp]# find / -type d -name sysconfig
/run/initramfs/state/etc/sysconfig
/etc/sysconfig
查找文件示例
· 根據時間查找
[root@24centos7-01 tmp]# stat tooth.txt
File: 'tooth.txt'
Size: 5 Blocks: 8 IO Block: 4096 regular file
Device: 803h/2051d Inode: 16783948 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-10-23 22:09:33.380613716 +0800
Modify: 2017-10-23 22:12:47.861123460 +0800
Change: 2017-10-23 22:12:47.861123460 +0800
Birth: -
--atime最後訪問時間,指文件被讀取而更新的時間
--mtime內容修改時間,即文件的內容發生變化
--ctime狀態修改時間,指文件的屬性或者權限發生變化而更新的時間
[root@24centos7-01 tmp]# find /tmp/ -type f -mtime -2
/tmp/test.txt
/tmp/tooth.txt
[root@24centos7-01 tmp]# find /tmp/ -type f -ctime -2
/tmp/test.txt
/tmp/tooth.txt
[root@24centos7-01 tmp]# find /tmp/ -type f -atime -2
/tmp/test.txt
/tmp/tooth.txt
--一小時之內
[root@24centos7-01 tmp]# find . -type f -mmin -60
./test/test.txt
./test.txt
./tooth.txt
--參數或關係-o
[root@24centos7-01 tmp]# find /tmp/ -type f -size -10k -o-mmin -60;
/tmp/
/tmp/.bash_history
/tmp/test
/tmp/test/test.txt.bak
/tmp/test.txt.bak
/tmp/tooth.txt.bak
--查找出一小時之內的文件並列舉其信息
--find . -type f -mmin -60 -exec ls -l {} \;
[root@24centos7-01 tmp]# find . -type f -mmin -60 -exec ls -l {} \;
-rw-r--r-- 2 root root 0 Oct 23 22:09 ./test/test.txt
-rw-r--r-- 2 root root 0 Oct 23 22:09 ./test.txt
-rw-r--r-- 1 root root 5 Oct 23 22:12 ./tooth.txt
--將查找出來的文件更名
[root@24centos7-01 tmp]# find . -type f -mmin -60 -exec ls -l {} \;
-rw-r--r-- 2 root root 0 Oct 23 22:09 ./test/test.txt
-rw-r--r-- 2 root root 0 Oct 23 22:09 ./test.txt
-rw-r--r-- 1 root root 5 Oct 23 22:12 ./tooth.txt
[root@24centos7-01 tmp]# find . -type f -mmin -60 -exec mv {} {}.bak \;
[root@24centos7-01 tmp]# find . -type f -mmin -60 -exec ls -l {} \;
-rw-r--r-- 2 root root 0 Oct 23 22:09 ./test/test.txt.bak
-rw-r--r-- 2 root root 0 Oct 23 22:09 ./test.txt.bak
-rw-r--r-- 1 root root 5 Oct 23 22:12 ./tooth.txt.bak
· 根據iNode號查找
[root@24centos7-01 tmp]# ln test.txt /tmp/test/test.txt
[root@24centos7-01 tmp]# ls -i /tmp/test
16783946 test.txt
[root@24centos7-01 tmp]# find -inum 16783946
./test/test.txt
./test.txt
· 按文件大小查找
[root@24centos7-01 tmp]# find /root/ -type f -size -10k-exec ls -lh {} \;
-rw-r--r--. 1 root root 18 Dec 29 2013 /root/.bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 /root/.bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 /root/.bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 /root/.cshrc
-rw-r--r--. 1 root root 129 Dec 29 2013 /root/.tcshrc
-rw-------. 1 root root 1.4K Oct 13 05:50/root/anaconda-ks.cfg
-rw-r--r-- 1 root root 343 Oct 17 21:25/root/.ssh/known_hosts
-rw------- 1 root root 1.7K Oct 17 21:59/root/.ssh/id_rsa
-rw-r--r-- 1 root root 399 Oct 17 21:59/root/.ssh/id_rsa.pub
-rw-r--r-- 1 root root 0 Oct 20 21:18/root/showtime/showtime.txt
-rw-r--r-- 1 root root 0 Oct 20 21:15/root/showtime/showtime/showtime.txt
-rw-r--r-- 1 root root 0 Oct 20 21:37 /root/test/1.txt
-rw-r--r-- 1 root root 0 Oct 20 21:37 /root/test/2.txt
-rw-r--r-- 1 root root 0 Oct 20 21:37 /root/test/3.txt
-rw------- 1 root root 6.9K Oct 20 22:14 /root/.viminfo
-rw------- 1 root root 54 Oct 21 20:11 /root/.lesshst
[root@24centos7-01 tmp]# find /root/ -type f -size +10k-exec ls -lh {} \;
-rw-------. 1 root root 12K Oct 23 21:27/root/.bash_history
文件名後綴
· .txt文件文件
· .zip壓縮文件
· .tar.gz打包文件
· .conf配置文件
· .exe可執行文件