tree
tree linux command cheatsheet by Thamizhiniyan C S
Introduction
This command is used to list contents of directories in a tree-like format.
Syntax
tree [-acdfghilnpqrstuvxACDFJQNSUX] [-L level [-R]] [-H baseHREF] [-T title] [-o filename] [-P pattern] [-I pattern] [--gitignore] [--gitā file[=]file] [--matchdirs] [--metafirst] [--ignore-case] [--nolinks] [--hintro[=]file] [--houtro[=]file] [--inodes] [--device] [--sort[=]name] [--dirsfirst] [--filesfirst] [--filelimit #] [--si] [--du] [--prune] [--charset[=]X] [--timefmt[=]format] [--fromfile] [--fflinks] [--info] [--infofile[=]file] [--noreport] [--version] [--help] [--] [directory ...]
Important Flags
Listing Options
Flag | Description |
---|---|
| All files are listed. |
| List directories only. |
| Follow symbolic links like directories. |
| Print the full path prefix for each file. |
| Stay on current filesystem only. |
| Descend only level directories deep. |
| Rerun tree when max dir level reached. |
| List only those files that match the pattern given. |
| Do not list files that match the given pattern. |
| Filter by using .gitignore files. |
| Explicitly read gitignore file. |
| Ignore case when pattern matching. |
| Include directory names in -P pattern matching. |
| Print meta-data at the beginning of each line. |
| Prune empty directories from the output. |
| Print information about files found in .info files. |
| Explicitly read info file. |
| Turn off file/directory count at end of tree listing. |
| Use charset X for terminal/HTML and indentation line output. |
| Do not descend dirs with more than # files in them. |
| Output to file instead of stdout. |
File Options
Flag | Description |
---|---|
| Print non-printable characters as '?'. |
| Print non-printable characters as is. |
| Quote filenames with double quotes. |
| Print the protections for each file. |
| Displays file owner or UID number. |
| Displays file group owner or GID number. |
| Print the size in bytes of each file. |
| Print the size in a more human readable way. |
| Like -h, but use in SI units (powers of 1000). |
| Compute size of directories by their contents. |
| Print the date of last modification or (-c) status change. |
| Print and format time according to the format . |
| Appends '/', '=', '*', '@', '|' or '>' as per ls -F. |
| Print inode number of each file. |
| Print device ID number to which each file belongs. |
Sorting Options
Flag | Description |
---|---|
| Sort files alphanumerically by version. |
| Sort files by last modification time. |
| Sort files by last status change time. |
| Leave files unsorted. |
| Reverse the order of the sort. |
| List directories before files (-U disables). |
| List files before directories (-U disables). |
| Select sort: name,version,size,mtime,ctime. |
Graphics Options
Flag | Description |
---|---|
| Don't print indentation lines. |
| Print ANSI lines graphic indentation lines. |
| Print with CP437 (console) graphics indentation lines. |
| Turn colorization off always (-C overrides). |
| Turn colorization on always. |
XML/HTML/JSON Options
Flag | Description |
---|---|
| Prints out an XML representation of the tree. |
| Prints out an JSON representation of the tree. |
| Prints out HTML format with baseHREF as top directory. |
| Replace the default HTML title and H1 header with string. |
| Turn off hyperlinks in HTML output. |
| Use file X as the HTML intro. |
| Use file X as the HTML outro. |
Input Options
Flag | Description |
---|---|
| Reads paths from files (.=stdin) |
| Process link information when using --fromfile. |
Misc Options
Flag | Description |
---|---|
| Print version and exit. |
| Print usage and this help message and exit. |
| Options processing terminator. |
Examples
Command | Description |
---|---|
Displays the tree structure of our current directory, showing all the files, folders, and sub-folders. | |
Display hidden files along with other files using tree. In the tree, the folders and files which are starting from a '.' are the hidden folders and files. | |
Display contents of a specific directory. | |
Display only directory listing through tree (print only directories). | |
Display full path prefix of files and folders using tree. It is mainly useful when we need to know what exists where. | |
Display size of files and folders using tree. With the help of the 's' flag, we can check which memory items consume more space on our system and getting rid of needless ones. | |
Display read-write permission of files and folders using tree. Thus, before performing operation on a file and folder, we can first see and edit the permissions that exist on a particular item. | |
List folder contents till a certain level/depth through tree. This command will only show the sub-directories (using -d flag) of the present directory not the additional expanded tree. | |
Sort files based on first modification | |
Sort files based on the last modification | |
List files with entered pattern | |
List those directories which have greater āNā number of files/directories | |
Prints the device number to which the file or directory belongs. |
Last updated