Linux尋找命令:which, whereis, locate, find

來源:互聯網
上載者:User

命令尋找 - which

which命令用於尋找PATH裡包含的可執行檔(即命令)

which [-a] command

-a:列出所有命令

檔案和目錄尋找 - whereis, locate, find

其中whereis和locate是從資料庫裡尋找,因此速度較快,但無法找出最新的資料,因為資料庫預設情 況下是每天更新一次(也可以執行updatedb命令手動更新)。

whereis file/dirname

locate [-i] keyword

-i:忽略大小寫

whereis和locate的區別是whereis是精準匹配,而locate是關鍵字尋找。

find指令是從硬碟尋找,速度比較慢,但它功能更強大。

find [PATH] [option] [action]

find指令包含三個部分,[PATH]指要尋找的路徑,[option]指定參數,如:

-name 要尋找的檔案名稱

-atime -ctime -mtime  檔案時間

-type 檔案類型

-size 檔案大小

其中和時間相關的參數比較常用,如:

-mtime +n:列出在n天之前(不含n)被更改過的檔案

-mtime -n:列出在n天之內(含n)被更改過的檔案

-newer file:列出比file還要新的檔案

[action]表示對尋找後的檔案進行操作的指令,指令內容以-exec開水,到\;結束,如下所示:

find /etc -name sysconfig -exec ls -l {} \;

其中{}表示由find找到的所有內容,所以上條命令表示尋找/etc下sysconfig檔案和目錄,並列出其目 錄結構。

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.