This article is going to take you through on how to check the size of various directories in Linux. We are going to use three main used commands to check size of various directories in Linux which include.
- How to check the size of various directories in Linux using du command
- How to check the size of various directories in Linux using ncdu command
- How to check the size of various directories in Linux using tree command
How to check the size of various directories in Linux using du command
The du
command stands for disk usage, it comes installed with most Linux distributions by default.
- To display the size of the current directory run the command below.
du
Sample output
76 ./.cache/thumbnails/normal 20 ./.cache/thumbnails/fail/gnome-thumbnail-factory 24 ./.cache/thumbnails/fail 292 ./.cache/thumbnails/large 396 ./.cache/thumbnails 4 ./.cache/ibus-table 4 ./.cache/gnome-desktop-thumbnailer/gstreamer-1.0 8 ./.cache/gnome-desktop-thumbnailer 24 ./.cache/update-manager-core 8 ./.cache/ubuntu-report 380 ./.cache/gstreamer-1.0 4 ./.cache/tracker3/files/errors 12332 ./.cache/tracker3/files 12336 ./.cache/tracker3 16 ./.cache/gnome-calculator 4 ./.cache/thunderbird/z4kv9qzx.default 16 ./.cache/thunderbird/o2au4xnw.default-release/cache2/entries 4 ./.cache/thunderbird/o2au4xnw.default-release/cache2/doomed 24 ./.cache/thunderbird/o2au4xnw.default-release/cache2 5216 ./.cache/thunderbird/o2au4xnw.default-release/startupCache 5244 ./.cache/thunderbird/o2au4xnw.default-release 5252 ./.cache/thunderbird 176 ./.cache/ibus/bus 180 ./.cache/ibus 64 ./.cache/fontconfig 4 ./.cache/evolution/memos/trash 8 ./.cache/evolution/memos 4 ./.cache/evolution/sources/trash 8 ./.cache/evolution/sources 4 ./.cache/evolution/mail/trash 8 ./.cache/evolution/mail 4 ./.cache/evolution/calendar/trash 8 ./.cache/evolution/calendar 4 ./.cache/evolution/addressbook/trash 8 ./.cache/evolution/addressbook 4 ./.cache/evolution/tasks/trash 8 ./.cache/evolution/tasks 52 ./.cache/evolution
- To output the size in human readable format i.e. K for kilobyte, M for megabyte, G for gigabyte etc. add
-h
to the command as shown below.
du -h
Sample output
6K ./.cache/thumbnails/normal 20K ./.cache/thumbnails/fail/gnome-thumbnail-factory 24K ./.cache/thumbnails/fail 292K ./.cache/thumbnails/large 396K ./.cache/thumbnails 4.0K ./.cache/ibus-table 4.0K ./.cache/gnome-desktop-thumbnailer/gstreamer-1.0 8.0K ./.cache/gnome-desktop-thumbnailer 24K ./.cache/update-manager-core 8.0K ./.cache/ubuntu-report 380K ./.cache/gstreamer-1.0 4.0K ./.cache/tracker3/files/errors 13M ./.cache/tracker3/files 13M ./.cache/tracker3 16K ./.cache/gnome-calculator 4.0K ./.cache/thunderbird/z4kv9qzx.default 16K ./.cache/thunderbird/o2au4xnw.default-release/cache2/entries 4.0K ./.cache/thunderbird/o2au4xnw.default-release/cache2/doomed 24K ./.cache/thunderbird/o2au4xnw.default-release/cache2 5.1M ./.cache/thunderbird/o2au4xnw.default-release/startupCache 5.2M ./.cache/thunderbird/o2au4xnw.default-release 5.2M ./.cache/thunderbird 176K ./.cache/ibus/bus 180K ./.cache/ibus 64K ./.cache/fontconfig 4.0K ./.cache/evolution/memos/trash 8.0K ./.cache/evolution/memos
- You can determine the size of a file in a specified directory using the
du -h
command followed by directory path
sudo du -h /etc
Sample output
4.0K /etc/polkit-1/localauthority/90-mandatory.d 4.0K /etc/polkit-1/localauthority/10-vendor.d 4.0K /etc/polkit-1/localauthority/30-site.d 4.0K /etc/polkit-1/localauthority/50-local.d 4.0K /etc/polkit-1/localauthority/20-org.d 24K /etc/polkit-1/localauthority 12K /etc/polkit-1/localauthority.conf.d 40K /etc/polkit-1 8.0K /etc/apm/scripts.d 4.0K /etc/apm/resume.d 4.0K /etc/apm/suspend.d 20K /etc/apm 44K /etc/wpa_supplicant 4.0K /etc/rcS.d 4.0K /etc/rc1.d 12K /etc/pm/sleep.d 16K /etc/pm 16K /etc/bluetooth 80K /etc/logrotate.d 8.0K /etc/depmod.d 4.0K /etc/postgresql-common/pg_upgradecluster.d 24K /etc/postgresql-common 8.0K /etc/pcmcia 40K /etc/sysctl.d
- Check disk consumption of a specific directory using the command below.
sudo du -hc /etc
Sample output
76K /etc/brltty/Input/al 132K /etc/brltty/Input/bm 8.0K /etc/brltty/Input/np 8.0K /etc/brltty/Input/vs 8.0K /etc/brltty/Input/vr 8.0K /etc/brltty/Input/ba 64K /etc/brltty/Input/eu 40K /etc/brltty/Input/fs 8.0K /etc/brltty/Input/tn 8.0K /etc/brltty/Input/lt 12K /etc/brltty/Input/ec 60K /etc/brltty/Input/ts 1.2M /etc/brltty/Input 924K /etc/brltty/Text 1.4M /etc/brltty/Contraction 16K /etc/brltty/Attributes 40K /etc/brltty/Keyboard 3.6M /etc/brltty 4.0K /etc/postgresql/13/main/conf.d 60K /etc/postgresql/13/main 64K /etc/postgresql/13 68K /etc/postgresql 28K /etc/gnome 76K /etc/speech-dispatcher/modules 8.0K /etc/speech-dispatcher/clients 104K /etc/speech-dispatcher 16M /etc 16M total
- To view total size of directory e.g.
var
run the following command.
sudo du -hs /var
How to check the size of various directories in Linux using ncdu command
The ncdu command stands for NCurses Disk Usage. Unlike du command, ncdu command doesn’t come installed by on most Linux distro by default.
- Run the command below to install on Debian / Ubuntu.
sudo apt install ncdu
- For CentOS / RedHat run the following command.
sudo yum install ncdu
- To view the size of current directory simply type the command below.
ncdu
- To view size of specific directory type the command
ncdu
followed by directory path.
ncdu /etc
How to check the size of various directories in Linux using tree command
- Start by installing tree command. Use the command below for Debian / Ubuntu
sudo apt-get install tree
- Use the following command for CentOS / RedHat
sudo yum install tree
- To check the size of the current directory run the command below.
tree -d -h
Sample output
. ├── [4.0K] demo ├── [4.0K] Desktop ├── [4.0K] Documents ├── [4.0K] Downloads │ └── [4.0K] firefox.tmp │ └── [4.0K] Temp-b2d5ec19-10b7-4fe1-a2e3-1ce76fc59968 ├── [4.0K] Music ├── [4.0K] Pictures │ └── [4.0K] demodata ├── [4.0K] Public ├── [4.0K] snap │ ├── [4.0K] firefox │ │ ├── [4.0K] 1154 │ │ ├── [4.0K] 1188 │ │ ├── [4.0K] common │ │ └── [ 4] current -> 1188 │ └── [4.0K] snap-store │ ├── [4.0K] 558 │ ├── [4.0K] common │ └── [ 3] current -> 558 ├── [4.0K] Templates └── [4.0K] Videos
- To check the file of specific directory run the following command.
tree -d -h /etc
- This marks the end of our article, congratulations. You have learned how to check the size of various directories in Linux.
Read more on some of the commands here
Other Tutorials
How to setup user password expiry date on Linux