2005-10-26

command 檔案及文件搜尋

無可否認的在 UNIX-LIKE 上要搜尋指令,檔案或是文件, 較 WINDOWS 上較為複雜, 但這並不意謂著在這方面的功能較為切缺, 反而個人以為較 M$ 上的相關功能有彈性多了, 且功能更不是 WINDOWS 所能比得上的.

一般我們可透過以下來達到我們的目的:

1. 好男人 man

我想 man 是進入 UNIX-LIKE WORLD 的一個重要指令, 有時不妨多和這個好男人接觸

2. find

這個指令有著許多參考資料, 不妨自行搜尋一下

3. which

which 是在 PATH 這個系統變數中, 找尋相關的執行檔, 如以下是搜尋 ls

# which ls
/bin/ls

4. whatis

whatis 會顯示該指令的簡略說明, 如以下是 ls 的說明

# whatis ls
ls (1) - list directory contents

4. whereis

whereis 不但能查詢執行檔, 更可搜尋 source 及 man 資料

5. locate

locate 可快速的找到檔案, 因為是使用更新檔案資料庫的方式. 在使用上時要注意, 如果剛建立的檔案會找不到, 這時不妨使用:

# sudo updatedb

來更新一下你的檔案資料庫.

6. apropos

這可說是 whatis 的另一種應用, 採用 "亂槍打鳥" 的方式, 只要顯示的字串中有符合的資料, 一律顯示出來.

如下(截取部份資料):

# apropos ls

logrotate (8) - rotates, compresses, and mails system logs
ls (1) - list directory contents
lsattr (1) - list file attributes on a Linux second extended file system

另外有時可能要知道一個檔案的性質, 這時不妨用 file 這個指令, 如下是 ls 的 file 說明:

# file `which ls`
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), stripped


了解了以上, 如何應用, 就存乎一心了.

沒有留言 :

張貼留言