tree 命令
阿新 • • 發佈:2019-01-11
部落格引用處(以下內容在原有部落格基礎上進行補充或更改,謝謝這些大牛的部落格指導):
tree 命令的使用
- 部分常用的命令:
-a 顯示所有檔案和目錄。 -A 使用ASNI繪圖字元顯示樹狀圖而非以ASCII字元組合。 -C 在檔案和目錄清單加上色彩,便於區分各種型別。 -d 顯示目錄名稱而非內容。 -D 列出檔案或目錄的更改時間。 -f 在每個檔案或目錄之前,顯示完整的相對路徑名稱。 -F 在執行檔案,目錄,Socket,符號連線,管道名稱名稱,各自加上"*","/","=","@","|"號。 -g 列出檔案或目錄的所屬群組名稱,沒有對應的名稱時,則顯示群組識別碼。 -i 不以階梯狀列出檔案或目錄名稱。 -I 不顯示符合範本樣式的檔案或目錄名稱。 -l 如遇到性質為符號連線的目錄,直接列出該連線所指向的原始目錄。 -n 不在檔案和目錄清單加上色彩。 -N 直接列出檔案和目錄名稱,包括控制字元。 -p 列出許可權標示。 -P 只顯示符合範本樣式的檔案或目錄名稱。 -q 用"?"號取代控制字元,列出檔案和目錄名稱。 -s 列出檔案或目錄大小。 -t 用檔案和目錄的更改時間排序。 -u 列出檔案或目錄的擁有者名稱,沒有對應的名稱時,則顯示使用者識別碼。 -x 將範圍侷限在現行的檔案系統中,若指定目錄下的某些子目錄,其存放於另一個檔案系統上,則將該子目錄予以排除在尋找範圍外。
- 完整的命令集:
usage: tree [-adfghilnpqrstuvxACDFNS] [-H baseHREF] [-T title ] [-L level [-R]] [-P pattern] [-I pattern] [-o filename] [--version] [--help] [--inodes] [--device] [--noreport] [--nolinks] [--dirsfirst] [--charset charset] [--filelimit #] [<directory list>] -a All files are listed. -d List directories only. -l Follow symbolic links like directories. -f Print the full path prefix for each file. -i Don't print indentation lines. -q Print non-printable characters as '?'. -N Print non-printable characters as is. -p Print the protections for each file. -u Displays file owner or UID number. -g Displays file group owner or GID number. -s Print the size in bytes of each file. -h Print the size in a more human readable way. -D Print the date of last modification. -F Appends '/', '=', '*', or '|' as per ls -F. -v Sort files alphanumerically by version. -r Sort files in reverse alphanumeric order. -t Sort files by last modification time. -x Stay on current filesystem only. -L level Descend only level directories deep. -A Print ANSI lines graphic indentation lines. -S Print with ASCII graphics indentation lines. -n Turn colorization off always (-C overrides). -C Turn colorization on always. -P pattern List only those files that match the pattern given. -I pattern Do not list files that match the given pattern. -H baseHREF Prints out HTML format with baseHREF as top directory. -T string Replace the default HTML title and H1 header with string. -R Rerun tree when max dir level reached. -o file Output to file instead of stdout. --inodes Print inode number of each file. --device Print device ID number to which each file belongs. --noreport Turn off file/directory count at end of tree listing. --nolinks Turn off hyperlinks in HTML output. --dirsfirst List directories before files. --charset X Use charset X for HTML and indentation line output. --filelimit # Do not descend dirs with more than # files in them.
比如使用tree命令生成樹形結構
分別使用以下命令:tree、tree /f 命令,就可以看到螢幕的效果了,還可以使用tree /a等命令,來生成想要的檔案目錄
匯出生成的檔案目錄
使用tree /f > tree.txt命令,就可以把生成的檔案目錄樹形結構寫入到tree.txt檔案中了,tree.txt這個檔名稱是可以修改的。開啟對應的檔案目錄,就可以看到多了一個tree.txt的檔案,其中tree檔案裡面的內容,和螢幕輸出的內容是一致的,以後就可以使用tree命令來生成檔案目錄的樹形結構了。