Search

Viewing the contents of a directory in tree format

There are number of differnt ways to view the contents of a directory on the command line using the command "ls". But in case you want to view the contents in a tree format, that is starting from the parent directory every file and folder getting listed under its repective directory in the form a tree then the command tree comes to the rescue.

The command might not be available by default in many distros in which case you will have to install the relevan packge. For eg in case of debian based systems, search for the packge "tree" in the package manager and install the same.

Once installed, you can view the contents of any directory in the "tree" format using the command " tree ".

Example :

Let us create a directory "temp1" and in that we will create a file "file1" .



Now in the directory temp1 create two directories temp2 and temp3



In temp2 and temp3 create files file2 and file3 respectively



Now use the command "tree" on temp1



The output should look like this


The directories and files are displayed in their respective colors, and at the end of the output the total number of files and directories present is also displayed.

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete