Working on the Linux command line: Use the `tree` command instead of repeated `cd` and `ls`

Updated . Posted . Visible to the public.

The tree command will show you the contents of a directory and all its sub directories as a tree:

>tree
.
├── a
│   ├── file_1.txt
│   └── file_2.txt
└── b
    ├── c
    │   └── even_more.txt
    └── more.txt

3 directories, 4 files

If you have deeply nested directories, the output will be quite long though. To avoid that, you can limit the depth, e.g. tree -L 2 will only go 2 directories deep.

If you use that regularly, consider adding aliases for that to your ~/.bashrc:

alias tree2='tree -L 2'
alias tree3='tree -L 3'
Last edit
Paul Demel
Keywords
bash, console
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2021-09-17 17:14)