文件查找命令find
find 路徑 查找條件[補充條件]
在目錄當中找到指定的文件
(1)知道文件的完整名稱,進行查找
user1@SC02ZRC4KMD6N /etc % find passwd
passwd
(2) 查找某路徑以及子路徑是否包含文件
user1@SC02ZRC4KMD6N / % find etc/ -name passwd
etc//pam.d/passwd
etc//passwd
(3)使用通配符進行模糊匹配
user1@SC02ZRC4KMD6N / % find etc/ -name pass*
(4)使用正則表達式進行模糊匹配
user1@SC02ZRC4KMD6N / % find etc/ -regex .*wd
(5)查找指定的文件類型
user1@SC02ZRC4KMD6N / % find etc/ -type f -regex .*wd
(6)按照時間來查找文件
user1@SC02ZRC4KMD6N / % find etc/ -ctime xx
user1@SC02ZRC4KMD6N / % stat test.txt
File: 'test.txt'
Size: 42 Blocks: 8 IO Block: 4096 regular file
Device: 804h/2052d Inode: 59158038 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-04-06 12:53:33.659773937 +0800
Modify: 2020-04-06 12:53:28.651706463 +0800
Change: 2020-04-06 12:53:28.651706463 +0800
Birth: -
atime指文件的訪問時間,ctime文件的i節點時間,mtime指文件內容發生變化的時間
(7)查找文件,刪除文件
user1@SC02ZRC4KMD6N tmp % touch {1..9}.txt
user1@SC02ZRC4KMD6N tmp % ls -l
total 0
-rw-r--r-- 1 user1 staff 0 4 6 15:11 1.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 2.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 3.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 4.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 5.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 6.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 7.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 8.txt
-rw-r--r-- 1 user1 staff 0 4 6 15:11 9.txt
user1@SC02ZRC4KMD6N tmp % find *txt -exec rm -v {} \;
1.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt
user1@SC02ZRC4KMD6N tmp % ls -l