主頁 > 知識庫 > linux命令之find命令簡單概述

linux命令之find命令簡單概述

熱門標簽:鶴崗400電話申請 百度地圖標注直線距離 天津電話外呼系統(tǒng)排名 測繪地圖標注名稱 外呼電話系統(tǒng)怎么操作 怎么在百度地圖標注公司的位置 智能電銷機器人有用嗎 商機地圖標注 德陽400電話申請

Linux下find命令在目錄結(jié)構(gòu)中搜索文件,并執(zhí)行指定的操作。Linux下find命令提供了相當多的查找條件,功能很強大。由于find具有強大的功能,所以它的選項也很多,其中大部分選項都值得我們花時間來了解一下。即使系統(tǒng)中含有網(wǎng)絡文件系統(tǒng)( NFS),find命令在該文件系統(tǒng)中同樣有效,只你具有相應的權(quán)限。 在運行一個非常消耗資源的find命令時,很多人都傾向于把它放在后臺執(zhí)行,因為遍歷一個大的文件系統(tǒng)可能會花費很長的時間(這里是指30G字節(jié)以上的文件系統(tǒng))。

1.命令格式:

find pathname -options [-print -exec -ok ...]

2.命令功能:

用于在文件樹種查找文件,并作出相應的處理

3.命令參數(shù):

pathname: find命令所查找的目錄路徑。例如用.來表示當前目錄,用/來表示系統(tǒng)根目錄。

-print: find命令將匹配的文件輸出到標準輸出。
-exec: find命令對匹配的文件執(zhí)行該參數(shù)所給出的shell命令。相應命令的形式為'command' { } \;,注意{ }和\;之間的空格。
-ok: 和-exec的作用相同,只不過以一種更為安全的模式來執(zhí)行該參數(shù)所給出的shell命令,在執(zhí)行每一個命令之前,都會給出提示,讓用戶來確定是否執(zhí)行。

4.命令選項:

-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ù)的文件

5.使用實例:

實例1:查找指定時間內(nèi)修改過的文件

命令:

find -atime -2

輸出:

[root@peidachang ~]# find -atime -2
./logs/monitor
./.bashrc
./.bash_profile
./.bash_history

說明:

超找48小時內(nèi)修改過的文件

實例2:根據(jù)關(guān)鍵字查找

命令:

find . -name "*.log"

輸出:

[root@localhost test]# find . -name "*.log" 
./log_link.log
./log2014.log
./test4/log3-2.log
./test4/log3-3.log
./test4/log3-1.log
./log2013.log
./log2012.log
./log.log
./test5/log5-2.log
./test5/log5-3.log
./test5/log.log
./test5/log5-1.log
./test5/test3/log3-2.log
./test5/test3/log3-3.log
./test5/test3/log3-1.log
./test3/log3-2.log
./test3/log3-3.log
./test3/log3-1.log

說明:

在當前目錄查找 以.log結(jié)尾的文件。 “. “代表當前目錄

實例3:按照目錄或文件的權(quán)限來查找文件

命令:

find /opt/soft/test/ -perm 777

輸出:

[root@localhost test]# find /opt/soft/test/ -perm 777
/opt/soft/test/log_link.log
/opt/soft/test/test4
/opt/soft/test/test5/test3
/opt/soft/test/test3

說明:

查找/opt/soft/test/目錄下 權(quán)限為 777的文件

實例4:按類型查找

命令:

find . -type f -name "*.log"

輸出:

[root@localhost test]# find . -type f -name "*.log"
./log2014.log
./test4/log3-2.log
./test4/log3-3.log
./test4/log3-1.log
./log2013.log
./log2012.log
./log.log
./test5/log5-2.log
./test5/log5-3.log
./test5/log.log
./test5/log5-1.log
./test5/test3/log3-2.log
./test5/test3/log3-3.log
./test5/test3/log3-1.log
./test3/log3-2.log
./test3/log3-3.log
./test3/log3-1.log
[root@localhost test]#

說明:

查找當目錄,以.log結(jié)尾的普通文件

實例5:查找當前所有目錄并排序

命令:

find . -type d | sort

輸出:

[root@localhost test]# find . -type d | sort
.
./scf
./scf/bin
./scf/doc
./scf/lib
./scf/service
./scf/service/deploy
./scf/service/deploy/info
./scf/service/deploy/product
./test3
./test4
./test5
./test5/test3
[root@localhost test]#

實例6:按大小查找文件

命令:

find . -size +1000c -print

輸出:

[root@localhost test]# find . -size +1000c -print
.
./test4
./scf
./scf/lib
./scf/service
./scf/service/deploy
./scf/service/deploy/product
./scf/service/deploy/info
./scf/doc
./scf/bin
./log2012.log
./test5
./test5/test3
./test3
[root@localhost test]#

說明:

查找當前目錄大于1K的文件

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Linux 命令find之查找文件的示例
  • 詳解Linux中兩個查找命令locate和find教程
  • Linux下find和grep常用命令及區(qū)別介紹
  • Linux中 find查找命令用法詳解
  • Linux中find命令的用法匯總
  • linux使用find和crontab命令定期清理過期文件
  • linux的一個find命令配合rm刪除某天前的文件方法
  • linux find下如何統(tǒng)計一個目錄下的文件個數(shù)以及代碼總行數(shù)的命令
  • Linux中查找工具的友好替代方案

標簽:自貢 武漢 丹東 六盤水 鎮(zhèn)江 百色 滁州 優(yōu)質(zhì)小號

巨人網(wǎng)絡通訊聲明:本文標題《linux命令之find命令簡單概述》,本文關(guān)鍵詞  linux,命令,之,find,簡單,概述,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《linux命令之find命令簡單概述》相關(guān)的同類信息!
  • 本頁收集關(guān)于linux命令之find命令簡單概述的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章