自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

在Linux上尋找你正在尋找的東西

系統(tǒng) Linux
怎樣在 Linux 系統(tǒng)上使用 find、locate、mlocate、which、 whereis、 whatis 和 apropos 命令尋找文件。在 Linux 系統(tǒng)上找到你要找的文件或命令并不難, 有很多種方法可以尋找。

[[228710]]

怎樣在 Linux 系統(tǒng)上使用 find、locate、mlocate、which、 whereis、 whatis 和 apropos 命令尋找文件。

在 Linux 系統(tǒng)上找到你要找的文件或命令并不難, 有很多種方法可以尋找。 

find

最顯然的無疑是 find 命令,并且 find 變得比過去幾年更容易使用了。它過去需要一個搜索的起始位置,但是現(xiàn)在,如果你想將搜索限制在當(dāng)下目錄中,你還可以使用僅包含文件名或正則表達(dá)式的 find 命令。

  1. $ find e*
  2. empty
  3. examples.desktop

這樣,它就像 ls 命令一樣工作,并沒有做太多的搜索。

對于更專業(yè)的搜索,find 命令需要一個起點和一些搜索條件(除非你只是希望它提供該起點目錄的遞歸列表)。命令 find -type f 從當(dāng)前目錄開始將遞歸列出所有常規(guī)文件,而 find ~nemo -type f -empty 將在 nemo 的主目錄中找到空文件。

  1. $ find ~nemo -type f -empty
  2. /home/nemo/empty

參見:11 個好玩的 Linux 終端技巧。 

locate

locate 命令的名稱表明它與 find 命令基本相同,但它的工作原理完全不同。find 命令可以根據(jù)各種條件 —— 名稱、大小、所有者、權(quán)限、狀態(tài)(如空文件)等等選擇文件并作為搜索選擇深度,locate 命令通過名為 /var/lib/mlocate/mlocate.db 的文件查找你要查找的內(nèi)容。該數(shù)據(jù)文件會定期更新,因此你剛創(chuàng)建的文件的位置它可能無法找到。如果這讓你感到困擾,你可以運行 updatedb 命令立即獲得更新。

  1. $ sudo updatedb 

mlocate

mlocate 命令的工作類似于 locate 命令,它使用與 locate 相同的 mlocate.db 文件。 

which

which 命令的工作方式與 find 命令和 locate 命令有很大的區(qū)別。它使用你的搜索路徑($PATH)并檢查其上的每個目錄中具有你要查找的文件名的可執(zhí)行文件。一旦找到一個,它會停止搜索并顯示該可執(zhí)行文件的完整路徑。

which 命令的主要優(yōu)點是它回答了“如果我輸入此命令,將運行什么可執(zhí)行文件?”的問題。它會忽略不可執(zhí)行文件,并且不會列出系統(tǒng)上帶有該名稱的所有可執(zhí)行文件 —— 列出的就是它找到的第一個。如果你想查找具有某個名稱的所有可執(zhí)行文件,則可以像這樣運行 find 命令,但是要比非常高效 which 命令用更長的時間。

  1. $ find / -name locate -perm -a=x 2>/dev/null
  2. /usr/bin/locate
  3. /etc/alternatives/locate

在這個 find 命令中,我們在尋找名為 “locate” 的所有可執(zhí)行文件(任何人都可以運行的文件)。我們也選擇了不要查看所有“拒絕訪問”的消息,否則這些消息會混亂我們的屏幕。 

whereis

whereis 命令與 which 命令非常類似,但它提供了更多信息。它不僅僅是尋找可執(zhí)行文件,它還尋找手冊頁(man page)和源文件。像 which 命令一樣,它使用搜索路徑($PATH) 來驅(qū)動搜索。

  1. $ whereis locate
  2. locate: /usr/bin/locate /usr/share/man/man1/locate.1.gz 

whatis

whatis 命令有其獨特的使命。它不是實際查找文件,而是在手冊頁中查找有關(guān)所詢問命令的信息,并從手冊頁的頂部提供該命令的簡要說明。

  1. $ whatis locate
  2. locate (1) - find files by name

如果你詢問你剛剛設(shè)置的腳本,它不會知道你指的是什么,并會告訴你。

  1. $ whatis cleanup
  2. cleanup: nothing appropriate. 

apropos

當(dāng)你知道你想要做什么,但不知道應(yīng)該使用什么命令來執(zhí)行此操作時,apropos 命令很有用。例如,如果你想知道如何查找文件,那么 apropos findapropos locate 會提供很多建議。

  1. $ apropos find
  2. File::IconTheme (3pm) - find icon directories
  3. File::MimeInfo::Applications (3pm) - Find programs to open a file by mimetype
  4. File::UserDirs (3pm) - find extra media and documents directories
  5. find (1) - search for files in a directory hierarchy
  6. findfs (8) - find a filesystem by label or UUID
  7. findmnt (8) - find a filesystem
  8. gst-typefind-1.0 (1) - print Media type of file
  9. ippfind (1) - find internet printing protocol printers
  10. locate (1) - find files by name
  11. mlocate (1) - find files by name
  12. pidof (8) - find the process ID of a running program.
  13. sane-find-scanner (1) - find SCSI and USB scanners and their device files
  14. systemd-delta (1) - Find overridden configuration files
  15. xdg-user-dir (1) - Find an XDG user dir
  16. $
  17. $ apropos locate
  18. blkid (8) - locate/print block device attributes
  19. deallocvt (1) - deallocate unused virtual consoles
  20. fallocate (1) - preallocate or deallocate space to a file
  21. IO::Tty (3pm) - Low-level allocate a pseudo-Tty, import constants.
  22. locate (1) - find files by name
  23. mlocate (1) - find files by name
  24. mlocate.db (5) - a mlocate database
  25. mshowfat (1) - shows FAT clusters allocated to file
  26. ntfsfallocate (8) - preallocate space to a file on an NTFS volume
  27. systemd-sysusers (8) - Allocate system users and groups
  28. systemd-sysusers.service (8) - Allocate system users and groups
  29. updatedb (8) - update a database for mlocate
  30. updatedb.mlocate (8) - update a database for mlocate
  31. whereis (1) - locate the binary, source, and manual page files for a...
  32. which (1) - locate a command 

總結(jié)

Linux 上可用于查找和識別文件的命令有很多種,但它們都非常有用。 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2011-12-13 14:44:41

51CTO

2019-10-24 10:19:42

5G網(wǎng)絡(luò)物聯(lián)網(wǎng)

2021-01-15 10:10:24

惡意程序包程序包惡意代碼

2024-10-23 19:47:54

2011-02-17 09:58:16

WindowsUbuntu

2016-08-08 11:31:51

Check Point收購

2010-12-20 12:33:55

2012-05-10 17:12:43

創(chuàng)新工場燈泡工場

2010-03-11 18:57:17

Python腳本

2015-03-30 10:41:37

大數(shù)據(jù)

2012-07-13 09:35:58

PHP

2012-07-13 09:38:15

項目代碼

2020-06-22 07:47:18

Linux系統(tǒng)磁盤

2021-07-14 06:40:02

矩陣路徑字符串

2021-12-04 23:00:01

人工智能數(shù)據(jù)數(shù)字化轉(zhuǎn)型

2021-04-01 16:36:07

macOS文件夾磁盤

2012-03-14 09:32:33

云計算互操作CCIF

2012-07-19 10:42:17

項目

2012-07-12 13:20:35

職場生活程序員
點贊
收藏

51CTO技術(shù)棧公眾號