Linux see directory tree structure using tree command

The tree command is a handy tool for visualizing the directory structure of a Linux file system. With tree, you can display the contents of a directory and all its subdirectories in a tree-like format. Here’s an example of how you can use the tree command:

$ tree

This will display the contents of the current directory, including all its subdirectories and files, in a tree-like format. The output will look something like this:

.
├── dir1
│ ├── file1.txt
│ └── file2.txt
├── dir2
│ └── dir3
│ └── file3.txt
└── file4.txt

3 directories, 4 files

If you want to display the contents of a different directory, you can specify the path to that directory as an argument to the tree command:

$ tree /path/to/directory

By default, tree will display the contents of the directory and all its subdirectories up to a depth of 15 levels. If you want to display a deeper level of the directory structure, you can use the -L option to specify the depth:

$ tree -L 2

This will display the contents of the current directory and its immediate subdirectories, but not the contents of any subdirectories of the subdirectories.

There are many other options you can use with the tree command, such as -d to only display directories, -f to display the full path of each file and directory, and --charset to specify the character set to use for the output. You can view the full list of options by running the following command:

$ tree --help

Leave a Comment