免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
你不知道的Linux下的常用查找命令

Linux下的常用查找命令

  • locate

  • whereis

  • which

  • find

locate

-i, 忽略大小寫

find

根據(jù)文件名或正則表達(dá)式搜索

-name

條件限制

-a 與條件

-o 或條件

-not 非條件(此參數(shù)的功能類似于否定參數(shù)‘!’)

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find <span class="hljs-attribute" style="box-sizing: border-box;">-name</span> <span class="hljs-string" style="box-sizing: border-box;">"t*"</span> <span class="hljs-attribute" style="box-sizing: border-box;">-a</span> <span class="hljs-attribute" style="box-sizing: border-box;">-name</span> <span class="hljs-string" style="box-sizing: border-box;">"*.text"</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找以t開頭并且以.text結(jié)尾的文件</span> find <span class="hljs-attribute" style="box-sizing: border-box;">-name</span> <span class="hljs-string" style="box-sizing: border-box;">"t*"</span> <span class="hljs-attribute" style="box-sizing: border-box;">-o</span> <span class="hljs-attribute" style="box-sizing: border-box;">-name</span> <span class="hljs-string" style="box-sizing: border-box;">"*.text"</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找以t開頭或以.text結(jié)尾的文件</span> find <span class="hljs-attribute" style="box-sizing: border-box;">-not</span> <span class="hljs-attribute" style="box-sizing: border-box;">-name</span> <span class="hljs-string" style="box-sizing: border-box;">"t*"</span> <span class="hljs-attribute" style="box-sizing: border-box;">-o</span> <span class="hljs-attribute" style="box-sizing: border-box;">-name</span> <span class="hljs-string" style="box-sizing: border-box;">"*.text"</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找不以t開頭或以.text結(jié)尾的文件</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">3</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">3</span></li></ul>

設(shè)定find命令在子目錄中遍歷的深度參數(shù):

-maxdepth

-mindepth

根據(jù)文件類型搜索:

類型符號
普通文件f
符號文件l
目錄d
字符設(shè)備c
塊設(shè)備b
套接字s
管道文件p

<code class="hljs fsharp has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find -<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box;">type</span> <span class="hljs-title" style="box-sizing: border-box;">l</span> //查找此目錄及子目錄以下的所有符號文件</span> find -<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box;">type</span> <span class="hljs-title" style="box-sizing: border-box;">f</span> //普通文件</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li></ul>

根據(jù)文件時(shí)間進(jìn)行查找:

linux文件系統(tǒng)中的每個(gè)文件都有三種時(shí)間戳:

1. 訪問時(shí)間(atime——access time):就是上次訪問這個(gè)文件的時(shí)間。

2. 改變時(shí)間(ctime——change time):就是文件的inode改變的時(shí)間(什么是inode?)當(dāng)你往一個(gè)文件中添加數(shù)據(jù)或者刪除數(shù)據(jù)的時(shí)候,修改文件所有者的時(shí)候,鏈接改變的時(shí)候,文件的ctime就會發(fā)生改變。

3. 修改時(shí)間(mtime——modification time):就是文件的內(nèi)容上一次發(fā)生改變的時(shí)候的時(shí)間。

<code class="hljs fsharp has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find -<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box;">type</span> <span class="hljs-title" style="box-sizing: border-box;">f</span> -<span class="hljs-title" style="box-sizing: border-box;">atime</span> -7 #查找7天內(nèi)被訪問的文件</span> find -<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box;">type</span> <span class="hljs-title" style="box-sizing: border-box;">f</span> -<span class="hljs-title" style="box-sizing: border-box;">atime</span> 7 #查找恰好在7天前被訪問的文件</span> find -<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box;">type</span> <span class="hljs-title" style="box-sizing: border-box;">f</span> -<span class="hljs-title" style="box-sizing: border-box;">atime</span> +7 #查找超過7天沒被訪問的文件</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">3</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">3</span></li></ul>

-atime,-ctime,-mtime可作為find的時(shí)間參數(shù),單位是天。還有基于“分鐘”的,-amin,-mmin

-cmin。這些值通常還帶有+或-:+表示大于,-表示小于。

-newer參數(shù),我們可以指定一個(gè)用于比較時(shí)間戳的參考文件,然后找出比參考文件更新的所有文件。

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find <span class="hljs-attribute" style="box-sizing: border-box;">-type</span> f <span class="hljs-attribute" style="box-sizing: border-box;">-newer</span> test4 <span class="hljs-comment" style="box-sizing: border-box;">//查找當(dāng)前目錄及子目錄下比test4更新的文件</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li></ul>

基于文件大小的查找

-size參數(shù)

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find <span class="hljs-attribute" style="box-sizing: border-box;">-type</span> f <span class="hljs-attribute" style="box-sizing: border-box;">-size</span> <span class="hljs-subst" style="box-sizing: border-box;">+</span><span class="hljs-number" style="box-sizing: border-box;">45</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找文件大小比45大的普通文件</span> find <span class="hljs-attribute" style="box-sizing: border-box;">-type</span> f <span class="hljs-attribute" style="box-sizing: border-box;">-size</span> <span class="hljs-number" style="box-sizing: border-box;">45</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找文件大小為45的普通文件</span> find <span class="hljs-attribute" style="box-sizing: border-box;">-type</span> f <span class="hljs-attribute" style="box-sizing: border-box;">-size</span> <span class="hljs-subst" style="box-sizing: border-box;">-</span><span class="hljs-number" style="box-sizing: border-box;">45</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找文件大小比45小的普通文件</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">3</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">3</span></li></ul>

基于文件權(quán)限和文件所有人的查找

-perm

-user

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find <span class="hljs-attribute" style="box-sizing: border-box;">-type</span> f <span class="hljs-attribute" style="box-sizing: border-box;">-perm</span> <span class="hljs-number" style="box-sizing: border-box;">664</span> <span class="hljs-comment" style="box-sizing: border-box;">//查找權(quán)限為664的普通文件</span> find <span class="hljs-attribute" style="box-sizing: border-box;">-type</span> f <span class="hljs-attribute" style="box-sizing: border-box;">-user</span> lee <span class="hljs-comment" style="box-sizing: border-box;">//查找所有人為lee的普通文件</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li></ul>

結(jié)合find執(zhí)行命令或動作

-exec

<code class="hljs mel has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find -type f -name <span class="hljs-string" style="box-sizing: border-box;">"*.c"</span> -<span class="hljs-keyword" style="box-sizing: border-box;">exec</span> cat> <span class="hljs-keyword" style="box-sizing: border-box;">file</span>.txt \; #將所有.c文件拼接起來寫入單個(gè)文件<span class="hljs-keyword" style="box-sizing: border-box;">file</span>.txt中 find -type f -mtime +<span class="hljs-number" style="box-sizing: border-box;">10</span> -name <span class="hljs-string" style="box-sizing: border-box;">"*.text"</span> -<span class="hljs-keyword" style="box-sizing: border-box;">exec</span> cp /<span class="hljs-number" style="box-sizing: border-box;">5</span>_15 #將<span class="hljs-number" style="box-sizing: border-box;">10</span>天前的.<span class="hljs-keyword" style="box-sizing: border-box;">text</span>文件復(fù)制到/tmp下</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li></ul><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">1</span></li><li style="box-sizing: border-box; padding: 0px 5px;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">2</span></li></ul>

find與xargs結(jié)合使用

xargs參數(shù) 將標(biāo)準(zhǔn)輸入轉(zhuǎn)換成命令行參數(shù)

<code class="hljs bash has-numbering" style="display: block; padding: 0px; box-sizing: border-box; white-space: pre; border-radius: 0px; word-wrap: normal; background-image: initial; background-attachment: initial; background-color: transparent; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><span style="font-family:Courier New;font-size:18px;color:#ff0000;">find -type f -name <span class="hljs-string" style="box-sizing: border-box;">"*.txt"</span> -print0 |xargs -<span class="hljs-number" style="box-sizing: border-box;">0</span> rm <span class="hljs-operator" style="box-sizing: border-box;">-f</span> <span class="hljs-comment" style="box-sizing: border-box;">#將匹配到的文件刪除,xargs -0將 \0作為輸入定界符。</span> find -type f -name <span class="hljs-string" style="box-sizing: border-box;">"*.c"</span> -print0 | xargs -<span class="hljs-number" style="box-sizing: border-box;">0</span> <span class="hljs-operator" style="box-sizing: border-box;">-l</span> <span class="hljs-comment" style="box-sizing: border-box;">#統(tǒng)計(jì)所有c程序文件的行數(shù)</span></span></code>

更多必看IT干貨資源盡在大數(shù)據(jù)架構(gòu)師專家,公眾號 xinsz08 ,聯(lián)系微信czq100w,加入各城市IT運(yùn)維安全總?cè)?,與大牛同臺交流學(xué)習(xí)。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Android屏幕適配方案
面試題
Android日志打印類LogUtils,能夠定位到類名,方法名以及出現(xiàn)錯(cuò)誤的行數(shù)并保存日志文件
Loss和神經(jīng)網(wǎng)絡(luò)訓(xùn)練
美!太美了!//清理了大量無效代碼
手機(jī)卡了,慢了,死機(jī)了,無故黑屏了?教你幾招這么玩轉(zhuǎn)...
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服