tree

樹狀圖列出目錄的內容

補充說明

tree命令 以樹狀圖列出目錄的內容。

語法

1tree(選項)(參數)

選項

 1------- 列表選項 -------
 2-a            # 顯示所有文件和目錄。
 3-d            # 顯示目錄名稱而非文件。
 4-l            # 如遇到性質爲符號連接的目錄,直接列出該連接所指向的原始目錄。
 5-f            # 在每個文件或目錄之前,顯示完整的相對路徑名稱。
 6-x            # 將範圍侷限在現行的文件系統中,若指定目錄下的某些子目錄,其存放於另一個文件系統上,則將該目錄予以排除在尋找範圍外。
 7-L level      # 限制目錄顯示層級。
 8-R            # Rerun tree when max dir level reached.
 9-P pattern    # <範本樣式> 只顯示符合範本樣式的文件和目錄名稱。
10-I pattern    # Do not list files that match the given pattern.
11--ignore-case # Ignore case when pattern matching.
12--matchdirs   # Include directory names in -P pattern matching.
13--noreport    # Turn off file/directory count at end of tree listing.
14--charset X   # Use charset X for terminal/HTML and indentation line output.
15--filelimit # # Do not descend dirs with more than # files in them.
16--timefmt <f> # Print and format time according to the format <f>.
17-o filename   # Output to file instead of stdout.
18-------- 文件選項 ---------
19-q            # 用“?”號取代控制字符,列出文件和目錄名稱。
20-N            # 直接列出文件和目錄名稱,包括控制字符。
21-Q            # Quote filenames with double quotes.
22-p            # 列出權限標示。
23-u            # 列出文件或目錄的擁有者名稱,沒有對應的名稱時,則顯示用戶識別碼。
24-g            # 列出文件或目錄的所屬羣組名稱,沒有對應的名稱時,則顯示羣組識別碼。
25-s            # 列出文件和目錄大小。
26-h            # Print the size in a more human readable way.
27--si          # Like -h, but use in SI units (powers of 1000).
28-D            # 列出文件或目錄的更改時間。
29-F            # 在執行文件,目錄,Socket,符號連接,管道名稱名稱,各自加上"*","/","@","|"號。
30--inodes      # Print inode number of each file.
31--device      # Print device ID number to which each file belongs.
32------- 排序選項 -------
33-v            # Sort files alphanumerically by version.
34-t            # 用文件和目錄的更改時間排序。
35-c            # Sort files by last status change time.
36-U            # Leave files unsorted.
37-r            # Reverse the order of the sort.
38--dirsfirst   # List directories before files (-U disables).
39--sort X      # Select sort: name,version,size,mtime,ctime.
40------- 圖形選項 ------
41-i            # 不以階梯狀列出文件和目錄名稱。
42-A            # 使用ASNI繪圖字符顯示樹狀圖而非以ASCII字符組合。
43-S            # Print with CP437 (console) graphics indentation lines.
44-n            # Turn colorization off always (-C overrides).
45-C            # 在文件和目錄清單加上色彩,便於區分各種類型。
46------- XML / HTML / JSON選項 -------
47-X            # Prints out an XML representation of the tree.
48-J            # Prints out an JSON representation of the tree.
49-H baseHREF   # Prints out HTML format with baseHREF as top directory.
50-T string     # Replace the default HTML title and H1 header with string.
51--nolinks     # Turn off hyperlinks in HTML output.
52---- 雜項選項 ----
53--version     # 輸入版本信息。
54--help        # 打印使用幫助信息。
55--            # Options processing terminator.

參數

目錄:執行tree指令,它會列出指定目錄下的所有文件,包括子目錄裏的文件。

實例

列出目錄/private/ 第一級文件名

1tree  /private/ -L 1
2/private/
3├── etc
4├── tftpboot
5├── tmp
6└── var

忽略文件夾

1tree -I node_modules # 忽略當前目錄文件夾node_modules
2tree -P node_modules # 列出當前目錄文件夾node_modules的目錄結構
3tree -P node_modules -L 2 # 顯示目錄node_modules兩層的目錄樹結構
4tree -L 2 > /home/www/tree.txt # 當前目錄結果存到 tree.txt 文件中

忽略多個文件夾

1tree -I 'node_modules|icon|font' -L 2

非樹狀結構列出目錄/private/下的所有文件

1tree -if /private/
2/private
3/private/a1
4/private/a2
5/private/etc
6/private/etc/b1
7/private/etc/b2
8/private/tftpboot

顯示所有文件目錄(包括隱藏文件)並忽略(node_modules|.git)目錄,展示(-L 2)兩層。

1$ tree -I 'node_modules|.git' -L 2 -a
2
3.
4├── .github
5│   └── workflows
6├── LICENSE
7├── README.md
8└── renovate.json

來源:https://github.com/jaywcjlove/linux-command

最後修改於: Wednesday, January 31, 2024

相關文章:

翻譯: