tree command alternatives in Linux, Ubuntu, Docker

Tree command is a useful Linux utility to list files and directories graphically,

Tree command example:

[[email protected] ~]# tree
.
├── test
│   ├── files1.txt
│   ├── files8.txt
│   └── files9.txt
├── codetryout.sh
└── zipfile.zip

1 directory, 5 files

There are situations such as,

  • You want to keep the number of packages to the minimum, such as a docker image/container.
  • Installation of the package is not permitted, or you do not have sudo or root access

There you can use inbuilt Linux commands instead of tree. Solutions mentioned here will not require sudo access package installation.

#1. First alternative for the tree command: find

Use the find command. Let us see an example for find command:

[[email protected] ~]# find
.
./test
./test/files1.txt
./test/files8.txt
./test/files9.txt
./codetryout.sh
./zipfile.zip

Just CD to the directory you want to get a tree view and execute the find command

#2. Second alternative for the tree command: ls -lR

Use the ls -lR command. Let us see an example usage of ls -lR

[[email protected] ~]# ls -lR
.:
-rwxr--r--. 1 root root    0 Jun 29 18:45 codetryout.sh
-rw-r--r--. 1 root root  990 May 17 17:06 zipfile.zip

./test:
total 0
-rw-r--r-- 1 root root 0 Nov  2 03:10 files1.txt
-rw-r--r-- 1 root root 0 Nov  2 03:10 files8.txt
-rw-r--r-- 1 root root 0 Nov  2 03:10 files9.txt

Find and ls should be part of your system and no installation would be required. Hope this helps!