Cyberithub

How to Install tree command on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install tree command on Ubuntu 20.04 LTS (Focal Fossa). tree is a free and open source command line program used for listing directory contents recursively in a depth-indented listing manner. It allows us to see all the files and directory recursively without actually going into that path.

This makes sometimes very convenient for developers and programmers to see all the project files and its path without using any IDE but just using a simple command line terminal utility. This obviously saves the overhead of installing an IDE into the system. It is also very easy to install tree utility in almost all the linux and Unix systems. Here we will see the steps to install tree utility on Ubuntu 20.04 LTS based systems. Check more about tree command.

 

How to Install tree command on Ubuntu 20.04 LTS (Focal Fossa)

How to Install tree command on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: Solved "Error while dialing dial unix /var/run/dockershim.sock"

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS Server.

b) You should have sudo or root access to run privileged commands.

c) You should have apt or apt-get or snap utility available in your Server.

 

Step 2: Update Your Server

In the first step, you need to first download and install all the available updates by using sudo apt update command and then upgrade packages to the latest version by using sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:2 https://dl.winehq.org/wine-builds/ubuntu focal InRelease [8,041 B]
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:4 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:7 https://download.sublimetext.com apt/stable/ InRelease
Get:8 https://dl.winehq.org/wine-builds/ubuntu focal/main amd64 Packages [400 kB]
Get:9 https://dl.winehq.org/wine-builds/ubuntu focal/main i386 Packages [401 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [811 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [2,085 kB]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,497 kB]
Get:14 http://in.archive.ubuntu.com/ubuntu focal-updates/main Translation-en [424 kB]
Get:15 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]
Get:16 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 c-n-f Metadata [16.4 kB]
................................................................

 

Step 3: Install tree command

You can use any of the below method to install tree command on your system depending on your requirements and tools availability.

a) From default repo

If you are looking to install tree package from default Ubuntu repo then you need to use sudo apt install tree command as shown below.

cyberithub@ubuntu:~$ sudo apt install tree
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
tree
0 upgraded, 1 newly installed, 0 to remove and 46 not upgraded.
Need to get 43.0 kB of archives.
After this operation, 115 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 tree amd64 1.8.0-1 [43.0 kB]
Fetched 43.0 kB in 1s (44.2 kB/s)
Selecting previously unselected package tree.
(Reading database ... 211967 files and directories currently installed.)
Preparing to unpack .../tree_1.8.0-1_amd64.deb ...
Unpacking tree (1.8.0-1) ...
Setting up tree (1.8.0-1) ...
Processing triggers for man-db (2.9.1-1) ...

b) From Snap store

If you are looking to install tree utility as a snap package from Snap store then you need to use sudo snap install tree command as shown below.

cyberithub@ubuntu:~$ sudo snap install tree
[sudo] password for cyberithub:
tree 1.8.0+pkg-3fd6 from 林博仁(Buo-ren, Lin) (brlin) installed

 

Step 4: Verify Installation

If you installed tree utility from default Ubuntu repo then you can check the installed files path by using dpkg -L tree command as shown below.

cyberithub@ubuntu:~$ dpkg -L tree
/.
/usr
/usr/bin
/usr/bin/tree
/usr/share
/usr/share/doc
/usr/share/doc/tree
/usr/share/doc/tree/README.gz
/usr/share/doc/tree/TODO
/usr/share/doc/tree/changelog.Debian.gz
/usr/share/doc/tree/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/tree.1.gz

 

Step 5: Check Version

You can check the current installed version by using tree --version command as shown below.

cyberithub@ubuntu:~$ tree --version
tree v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro

 

Step 6: Using tree command

Now that tree command is installed, we can test it by listing all the files and directory under sampleapp directory using tree sampleapp command as shown below. You can see the indented results on the output. Without any arguments, tree will list all the files from the current working directory. To check all the options available with tree utility, you can use tree --help command.

cyberithub@ubuntu:~$ tree sampleapp
sampleapp
└── kustomize
    ├── bases
    │   ├── fscm
    │   │   └── kustomization.yaml
    │   ├── hcm
    │   │   └── kustomization.yaml
    │   └── portal
    │       └── kustomization.yaml
    └── overlays
        ├── fscm
        │   └── kustomization.yaml
        ├── hcm
        │   └── kustomization.yaml
        └── portal
            └── kustomization.yaml

9 directories, 6 files

 

Step 7: Uninstall tree command

Once you are done using tree command, you can also choose to uninstall it from your system by using one of the below method depending on how you have installed it.

a) Using apt or apt-get

If you installed tree utility from default ubuntu repo then you need to use sudo apt remove tree command to uninstall it from your system.

cyberithub@ubuntu:~$ sudo apt remove tree
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
tree
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 115 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 211974 files and directories currently installed.)
Removing tree (1.8.0-1) ...
Processing triggers for man-db (2.9.1-1) ...

b) Using snap 

If you installed tree utility as snap package then you need to use sudo snap remove tree command to uninstall it from your system.

cyberithub@ubuntu:~$ sudo snap remove tree
tree removed

Leave a Comment