Treemap listing the contents of a directory
tree command lists the contents of a directory in a tree view.
tree(option)(parameter)
------- List options -------
-a # Display all files and directories.
-d # Display directory names instead of files.
-l # If a directory that is a symbolic link is encountered, directly list the original directory pointed to by the link.
-f # Display the full relative path name before each file or directory.
-x # Limit the scope to the current file system. If some subdirectories under the specified directory are stored on another file system, the directory will be excluded from the search scope.
-L level # Limit the directory display level.
-R # Rerun tree when max dir level reached.
-P pattern # <template pattern> Only display file and directory names that match the template 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.
-------- File Options ---------
-q # Use "?" instead of control characters to list file and directory names.
-N # List file and directory names directly, including control characters.
-Q # Quote filenames with double quotes.
-p # List permission flags.
-u # List the owner names of files or directories. If there is no corresponding name, the user identification code is displayed.
-g # List the group names to which files or directories belong. If there is no corresponding name, the group identification code is displayed.
-s # List file and directory sizes.
-h # Print the size in a more human readable way.
--si # Like -h, but use in SI units (powers of 1000).
-D # List the change times of files or directories.
-F # Add "*", "/", "@", "|" to each of the executable files, directories, Sockets, symbolic connections, and pipe names.
--inodes # Print inode number of each file.
--device # Print device ID number to which each file belongs.
------- Sorting options -------
-v # Sort files alphanumerically by version.
-t # Sort files and directories by change time.
-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.
------- Graphics Options ------
-i # Do not list file and directory names in a ladder format.
-A # Use ASNI drawing characters to display tree diagrams instead of ASCII character combinations.
-S # Print with CP437 (console) graphics indentation lines.
-n # Turn colorization off always (-C overrides).
-C # Add colors to file and directory listings to make it easier to distinguish between types.
------- XML/HTML/JSON options -------
-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.
---- Miscellaneous options ----
--version #Enter version information.
--help #Print usage help information.
-- # Options processing terminator.
Directory: Execute the tree command, which will list all files in the specified directory, including files in subdirectories.
List first-level file names in directory /private/
tree /private/ -L 1
/private/
├── etc
├── tftpboot
├── tmp
└── var
ignore folder
tree -I node_modules # Ignore the current directory folder node_modules
tree -P node_modules # List the directory structure of the current directory folder node_modules
tree -P node_modules -L 2 # Display the two-level directory tree structure of the directory node_modules
tree -L 2 > /home/www/tree.txt # Save the current directory results to the tree.txt file
Ignore multiple folders
tree -I 'node_modules|icon|font' -L 2
Non-tree structure lists all files in the directory /private/
tree -if /private/
/private
/private/a1
/private/a2
/private/etc
/private/etc/b1
/private/etc/b2
/private/tftpboot
Show all file directories (including hidden files) and ignore the (node_modules|.git) directory, display (-L 2
) two levels.
$ tree -I 'node_modules|.git' -L 2 -a
.
├── .github
│ └── workflows
├── LICENSE
├── README.md
└── renovate.json