linux系列(二十):find命令
生活随笔
收集整理的這篇文章主要介紹了
linux系列(二十):find命令
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1、命令格式
??? find?pathname?-options [-print?-exec?-ok?...]
2、命令功能
??? 用于在文件樹種查找文件,并作出相應(yīng)的處理
3、命令參數(shù)
pathname: find命令所查找的目錄路徑。例如用.來表示當前目錄,用/來表示系統(tǒng)根目錄。 -print: find命令將匹配的文件輸出到標準輸出。 -exec: find命令對匹配的文件執(zhí)行該參數(shù)所給出的shell命令。相應(yīng)命令的形式為'command' { } \;,注意{ }和\;之間的空格。 -ok: 和-exec的作用相同,只不過以一種更為安全的模式來執(zhí)行該參數(shù)所給出的shell命令,在執(zhí)行每一個命令之前,都會給出提示,讓用戶來確定是否執(zhí)行。-name 按照文件名查找文件。 -perm 按照文件權(quán)限來查找文件。 -prune 使用這一選項可以使find命令不在當前指定的目錄中查找,如果同時使用-depth選項,那么-prune將被find命令忽略。 -user 按照文件屬主來查找文件。 -group 按照文件所屬的組來查找文件。 -mtime -n +n 按照文件的更改時間來查找文件, - n表示文件更改時間距現(xiàn)在n天以內(nèi),+ n表示文件更改時間距現(xiàn)在n天以前。find命令還有-atime和-ctime 選項,但它們都和-m time選項。 -nogroup 查找無有效所屬組的文件,即該文件所屬的組在/etc/groups中不存在。 -nouser 查找無有效屬主的文件,即該文件的屬主在/etc/passwd中不存在。 -newer file1 ! file2 查找更改時間比文件file1新但比文件file2舊的文件。 -type 查找某一類型的文件,諸如: b - 塊設(shè)備文件。 d - 目錄。 c - 字符設(shè)備文件。 p - 管道文件。 l - 符號鏈接文件。 f - 普通文件。 -size n:[c] 查找文件長度為n塊的文件,帶有c時表示文件長度以字節(jié)計。-depth:在查找文件時,首先查找當前目錄中的文件,然后再在其子目錄中查找。 -fstype:查找位于某一類型文件系統(tǒng)中的文件,這些文件系統(tǒng)類型通常可以在配置文件/etc/fstab中找到,該配置文件中包含了本系統(tǒng)中有關(guān)文件系統(tǒng)的信息。 -mount:在查找文件時不跨越文件系統(tǒng)mount點。 -follow:如果find命令遇到符號鏈接文件,就跟蹤至鏈接所指向的文件。 -cpio:對匹配的文件使用cpio命令,將這些文件備份到磁帶設(shè)備中。 另外,下面三個的區(qū)別: -amin n 查找系統(tǒng)中最后N分鐘訪問的文件 -atime n 查找系統(tǒng)中最后n*24小時訪問的文件 -cmin n 查找系統(tǒng)中最后N分鐘被改變文件狀態(tài)的文件 -ctime n 查找系統(tǒng)中最后n*24小時被改變文件狀態(tài)的文件 -mmin n 查找系統(tǒng)中最后N分鐘被改變文件數(shù)據(jù)的文件 -mtime n 查找系統(tǒng)中最后n*24小時被改變文件數(shù)據(jù)的文件4、簡單實例
(1)、查找1天內(nèi)修改過的文件
命令:
find -atime -1
輸出:
felix@felix-computer:~$ find -atime -1.
./視頻
./VirtualBox VMs
./VirtualBox VMs/win7
./VirtualBox VMs/win7/Snapshots
./VirtualBox VMs/win7/Snapshots/{e2df63ca-142e-4bac-849a-4e87f0149a22}.vdi
./VirtualBox VMs/win7/Snapshots/{e227ccf9-442f-4ff6-bbe7-3734924bfd9f}.vdi
./VirtualBox VMs/win7/Snapshots/{086a508b-6776-4e39-96d1-0c4a93945112}.vdi
./VirtualBox VMs/win7/Snapshots/{830ed964-d779-4f5e-b880-dd972b13afba}.vdi
(2)、根據(jù)關(guān)鍵字查找
命令:
find -name "*.log"
輸出:
felix@felix-computer:~$ find -name "*.log" ./java_error_in_WEBIDE_1932.log ./VirtualBox VMs/win7/Logs/VBox.log ./VirtualBox VMs/win10/Logs/VBox.log ./VirtualBox VMs/Ubuntu/Logs/VBox.log ./VirtualBox VMs/centos部署/Logs/VBox.log ./VirtualBox VMs/centos/Logs/VBox.log ./configuration/1541311074510.log ./configuration/1543413166475.log ./文檔/25 elastic search/codes/demo_data/imooc_log/access.20161111.log ./文檔/25 elastic search/codes/demo_data/imooc_log/access.1w.log find: ‘./.cache/dconf’: 權(quán)限不夠 ./.cache/netease-cloud-music/Logs/webview.log ./.cache/netease-cloud-music/Logs/web-statis.log ./.cache/netease-cloud-music/Cef/console.log(3)、查找當前所有目錄并排序
命令:
find . -type d | sort
輸出:
felix@felix-computer:~/test$ find . -type d | sort . ./a ./a/b ./a/b/c ./a/b/c/d felix@felix-computer:~/test$?
更多命令參考博客
轉(zhuǎn)載于:https://www.cnblogs.com/felixwang2/p/10081875.html
與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的linux系列(二十):find命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hive 小文件数据合并
- 下一篇: __init__函数