1. Home
  2. Linux

How to find Linux directory size

Are you trying to find the size of a directory on your Linux PC but can’t figure out how to do it? We can help! Follow along in this guide as we go over exactly how you can find a Linux directory’s size!

Find Linux directory size – du command

The fastest way to find a directory’s size on the Linux desktop is with the terminal-based application called Du. Du can tell the user how big or small any given directory or file is, and you can even save the size output to a file for later! Here’s how to use Du.

First, open up a terminal window on the Linux desktop. There are many ways to open up a terminal. On most desktops, the keyboard shortcut Ctrl + Alt + T should launch it. 

With the terminal window open and ready to go, enter the du command alongside the directory you wish to find the exact size of. In this example, we’ll use the home (~) folder.

Note: be sure to customize the command below to the directory you wish to scan.

du ~/

After executing the above du ~/ command, you’ll see a command-line readout telling you exactly how large the ~/ (home) folder is, as well as every subfolder’s size. Scroll through this long list of files to learn how big each directory is. The home directory is at the very bottom of the list.

You may have noticed that the command-line output for du is in bits, while useful, isn’t exactly easy to understand for the average user. If you’d like an easier time reading the output, run du with the -h command-line switch. It’ll print everything in Kilobyte/Megabyte/Gigabyte, etc.

du -h ~/

Want to save your du command-line readout to a text file for storage purposes? Pipe it to a text file with the following command in the terminal.

du -h ~/ > ~/my-du-readout.txt

Find Linux directory size – NCDU tool

If you’re trying to find Linux directory sizes but want a more comfortable to use a terminal program, NCDU is the way to go. NCDU is a text-based disk usage analyzer, and it can easily be used to find Linux directory sizes.

To start, you must install the NCDU app on your Linux PC. To do that, launch a terminal window by pressing Ctrl + Alt + T on the keyboard (or search for it in the app menu). Then, install it using the instructions down below that corresponds with your Linux OS.

Ubuntu

sudo apt install ncdu

Debian

sudo apt-get install ncdu

Arch Linux

sudo pacman -S ncdu

Fedora

sudo dnf install ncdu

OpenSUSE

sudo zypper install ncdu

Once the NCDU app is installed, use the following command to launch a scan against a directory to check the size of the subfolders inside. In this example, we will be scanning the home directory (~), so NCDU will tell us how big every subfolder contained in home (~)  is.

Note: be sure to change the directory in the command below to suit your needs.

ncdu ~/

NCDU should run for a couple of seconds (or minutes if you have a slow PC). When it is complete, you’ll see a descending list with the largest folders being on top, denoted by directory size.

Find Linux directory size – Tree app

If DU and NCDU don’t do it for you, Tree is another app that you can use on Linux to view directory sizes. To start, you must install the app. You must install Tree because it is not a default app on any mainstream Linux OS. 

To install Tree, start by launching a terminal window on the desktop. Once the terminal window is open, follow the command-line installation instructions outlined below that corresponds with the OS you currently use.

Ubuntu

sudo apt install tree

Debian

sudo apt-get install tree

Arch Linux

sudo pacman -S tree

Fedora

sudo dnf install tree

OpenSUSE

sudo zypper install tree

With the app open, it is time to use it to find directory file sizes. Using the tree command, scan a directory. It’ll tell you the folder sizes of the scanned directory, as well as all subfolders.

Note: be sure to change the command below to suit your needs!

tree -d -h ~/ 

By executing the command above, you’ll see a tree structure of the folder you scanned, along with each subfolder inside of it, and their subfolders, etc. It’ll also show the size of each directory next to the name of each folder.

Want to make the tree command-line output more readable? Consider executing it with the less command. It’ll make the entire tree output scrollable with the mouse.

tree -d -h ~/ | less

Do you want to save your tree command-line output to a text file for later? Pipe it to a text file using the command below! 

tree -d -h ~/ > ~/my-tree-output.txt

3 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.