Home » Linux Host, Ubuntu, SysAdmin » Linux Commands » Tree command in Linux with examples

Tree command in Linux with examples

[addthis tool="addthis_inline_share_toolbox"]

The “tree” command in Linux is a utility that displays a hierarchical tree-like structure of the contents of a directory. It shows the files and directories contained within a directory and the subdirectories contained within those, and so on. Tree command in Linux/Ubuntu is used to list contents of directories in a tree-like format. Tree command is very good to get the complete view of all files in a directory to identify the source code structure.

When used “tree” command in a directory, it shows all the files and directory in the current directory recursively but by default it doesn’t show any hidden files.

This directory only had some files, so the tree command shown all the files in a single view. Now, lets look at some directory which had more files in it.

Using command “tree -h” we can visualize the size of each files.

Using below command “tree -h –sort=size” , we can sort the files displayed according to their size. As you can see in below image, files with maximum size are displayed on top. You can also sort the files based on the time when it was created.

The tree command has several options that allow you to customize its output. For example, you can specify the maximum depth of the display, display file sizes, and exclude certain files or directories. To see a list of available options, type “tree –help” in a terminal.

In conclusion, the tree command is a useful tool for visualizing the structure of a directory and its contents in a hierarchical tree-like format. Whether you are a system administrator, a developer, or just an everyday Linux user, the tree command is a handy tool to know and use.

Leave a Comment