linux學習100篇57:tree -L 1

image.png
root 01:02:29 ~
$ tree -L 2
.
|-- a.txt
|-- data
|   |-- a.txt
|   |-- clusterprofilier注蚲07\212
|   |-- Data
|   |-- Data.tar.gz
|   |-- file1
|   `-- file2
|-- miniconda3
|   |-- bin
|   |-- compiler_compat
|   |-- condabin
|   |-- conda-meta
|   |-- envs
|   |-- etc
|   |-- include
|   |-- info
|   |-- lib
|   |-- LICENSE.txt
|   |-- pkgs
|   |-- share
|   |-- shell
|   |-- ssl
|   `-- x86_64-conda_cos6-linux-gnu
|-- rstudio-server-1.4.1106-amd64.deb
|-- software
|   |-- Miniconda3-latest-Linux-x86_64.sh
|   `-- Miniconda3-latest-Linux-x86_64.sh.1
|-- temp
`-- test_file1
    `-- test_file2

24 directories, 7 files
root 01:08:44 ~
$ 

tree
樹狀圖列出目錄的內(nèi)容

補充說明
tree命令 以樹狀圖列出目錄的內(nèi)容。

語法
tree(選項)(參數(shù))
選項
------- 列表選項 -------
-a # 顯示所有文件和目錄。
-d # 顯示目錄名稱而非文件。
-l # 如遇到性質(zhì)為符號連接的目錄,直接列出該連接所指向的原始目錄。
-f # 在每個文件或目錄之前,顯示完整的相對路徑名稱。
-x # 將范圍局限在現(xiàn)行的文件系統(tǒng)中,若指定目錄下的某些子目錄,其存放于另一個文件系統(tǒng)上,則將該目錄予以排除在尋找范圍外。
-L level # 限制目錄顯示層級。
-R # Rerun tree when max dir level reached.
-P pattern # <范本樣式> 只顯示符合范本樣式的文件和目錄名稱。
-I pattern # Do not list files that match the given pattern.
--ignore-case # Ignore case when pattern matching.
--matchdirs # Include directory names in -P pattern matching.
--noreport # Turn off file/directory count at end of tree listing.
--charset X # Use charset X for terminal/HTML and indentation line output.
--filelimit # # Do not descend dirs with more than # files in them.
--timefmt <f> # Print and format time according to the format <f>.
-o filename # Output to file instead of stdout.
-------- 文件選項 ---------
-q # 用“?”號取代控制字符,列出文件和目錄名稱。
-N # 直接列出文件和目錄名稱,包括控制字符。
-Q # Quote filenames with double quotes.
-p # 列出權(quán)限標示。
-u # 列出文件或目錄的擁有者名稱,沒有對應(yīng)的名稱時,則顯示用戶識別碼。
-g # 列出文件或目錄的所屬群組名稱,沒有對應(yīng)的名稱時,則顯示群組識別碼。
-s # 列出文件和目錄大小。
-h # Print the size in a more human readable way.
--si # Like -h, but use in SI units (powers of 1000).
-D # 列出文件或目錄的更改時間。
-F # 在執(zhí)行文件,目錄,Socket,符號連接,管道名稱名稱,各自加上"*","/","@","|"號。
--inodes # Print inode number of each file.
--device # Print device ID number to which each file belongs.
------- 排序選項 -------
-v # Sort files alphanumerically by version.
-t # 用文件和目錄的更改時間排序。
-c # Sort files by last status change time.
-U # Leave files unsorted.
-r # Reverse the order of the sort.
--dirsfirst # List directories before files (-U disables).
--sort X # Select sort: name,version,size,mtime,ctime.
------- 圖形選項 ------
-i # 不以階梯狀列出文件和目錄名稱。
-A # 使用ASNI繪圖字符顯示樹狀圖而非以ASCII字符組合。
-S # Print with CP437 (console) graphics indentation lines.
-n # Turn colorization off always (-C overrides).
-C # 在文件和目錄清單加上色彩,便于區(qū)分各種類型。
------- XML / HTML / JSON選項 -------
-X # Prints out an XML representation of the tree.
-J # Prints out an JSON representation of the tree.
-H baseHREF # Prints out HTML format with baseHREF as top directory.
-T string # Replace the default HTML title and H1 header with string.
--nolinks # Turn off hyperlinks in HTML output.
---- 雜項選項 ----
--version # 輸入版本信息。
--help # 打印使用幫助信息。
-- # Options processing terminator.
參數(shù)
目錄:執(zhí)行tree指令,它會列出指定目錄下的所有文件,包括子目錄里的文件。

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

tree /private/ -L 1
/private/
├── etc
├── tftpboot
├── tmp
└── var
忽略文件夾

tree -I node_modules # 忽略當前目錄文件夾node_modules
tree -P node_modules # 列出當前目錄文件夾node_modules的目錄結(jié)構(gòu)
tree -P node_modules -L 2 # 顯示目錄node_modules兩層的目錄樹結(jié)構(gòu)
tree -L 2 > /home/www/tree.txt # 當前目錄結(jié)果存到 tree.txt 文件中
忽略多個文件夾

tree -I 'node_modules|icon|font' -L 2
非樹狀結(jié)構(gòu)列出目錄/private/下的所有文件

tree -if /private/
/private
/private/a1
/private/a2
/private/etc
/private/etc/b1
/private/etc/b2
/private/tftpboot

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容