How To Get The Size Of Directory In Linux From Command Line? – POFTUT

How To Get The Size Of Directory In Linux From Command Line?


While working with Linux we may need to get the size of the specific directory. In GUI there are file managers like Dolphin, Gnome, Nautilus etc. But what if we need to get the size in command line. In this tutorial we will look how to get single or multiple directories sizes and sort them.

Find Size Of Directory

We will start by simply listing the size of a directory with command du . We will use -s option for summary and -h option for human readable format. We also need to specify the directory or folder name. In this example we will get size of directory named Android .

$ du -sh Android

Find Size Of Directory
Find Size Of Directory

Find Size Of Multiple Directories

We may need to find multiple directories sizes in given path. We just need to change the directory name with a glob which will list all directories and files sizes.

$ du -sh *
Find Size Of Multiple Directories
Find Size Of Multiple Directories

Find Size Of Multiple Directories By Specifying Directory Names

In previous example we have listed multiple directories according to their sizes by using glob . But if we need to specifically provide the directory names we can just add their names by separating them with a space. In this example we will list directories named Android , Dockerfile and eclipse .

$ du -sh Android Dockerfile eclipse
Find Size Of Multiple Directories By Specifying Directory Names
Find Size Of Multiple Directories By Specifying Directory Names

Sort Multiple Directories According To Their Size

While listing the directory sizes we may need to sort them according to their size in incremental mode. We can use sort command with -h option which is for human readable format for sizes and -r option for reverse list from highest ro lowest.

$ du -sh * | sort -hr
Sort Multiple Directories According To Their Size
Sort Multiple Directories According To Their Size

Sort Multiple Directories According To Their Size

We can also list directories according to their size in a incremental manner by not using -r option in du command.

$ du -sh * | sort -h
Sort Multiple Directories According To Their Size
Sort Multiple Directories According To Their Size

LEARN MORE  Linux touch Command Tutorial with

Leave a Comment