Skip to content

Disk Usage (du) Command Examples

A comprehensive guide to using the du command for analyzing disk usage in Linux, featuring advanced and practical examples.


Show space in bytes

du -m /mnt/usb/www-20260212.tar.gz

Show space in kilobytes

du -k /mnt/usb/www-20260212.tar.gz

Show space in megabytes

du -m /mnt/usb/www-20260212.tar.gz

Show space in gitabytes

du -BG /mnt/usb/www-20260212.tar.gz

Show space in terrabytes

du -TG /mnt/usb/www-20260212.tar.gz

List all directory sizes and sort by size

du -ks * | sort -nr | cut -f2 | xargs -d '\n' du -sh

Print total size of specified files and subdirectories

du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc

Display a numbered list of 50 biggets files sorted by size (human readable)

du -ah | sort -hr | head -n50 | cat -n

Ultimate current directory usage command

du <path> -a --max-depth=1 \
	|sort -n \
	|cut -d/ -f2 \
	|sed '$d' \
	|while read i; do 
		if [[ -f $i ]]; then 
			du -h "$i"; 
		else 
			echo "$(du -h --max-depth=0 "$i")/"; 
		fi; 
	done

Easily find megabyte eating files or directories

du -cks * \
	|sort -rn \
	|while read size fname; do 
		for unit in k M G T P E Z Y; do 
			if [[ $size -lt 1024 ]]; then 
				echo -e "${size}${unit}\t${fname}"; 
				break; 
			fi; size=$((size/1024)); 
		done; 
	done

List sub dir, sort by size

du --max-depth=1 |sort -n \
	|awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) 
	{x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"iB" } 
	{gsub(/^[0-9]+/, human($1)); print}'

One line Perl Script to determine the largest file sizes on a Linux Server

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf  ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}' | more

Print total size of specified files and subdirectories

du -sk * | awk '{print $1} END {print "[+z1<y]sy\nlyx\np"}' | dc

Display a numbered list of 50 biggets files sorted by size (human readable)

du -ah | sort -hr | head -n50 | cat -n

Easily find megabyte eating files or directories

du -cks * | sort -rn | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done

List complete size of directories (do not consider hidden directories)

du --max-depth=1 | grep -v '\.\/\.'

Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes

du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'

Find the 20 biggest directories on the current filesystem

du -xk | sort -n | tail -20

List top ten files/directories sorted by size

§bash §du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh §

Find all directories on filesystem containing more than 99MB

du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'

List the size (in human readable form) of all sub folders from the current location

du --max-depth=1|sort -n|cut -f2|tr '\n' '\0'|xargs -0 du -sh 2>/dev/null

Ultimate current directory usage command

du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do 
if [ -f $i ]; then  du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; 
fi; 
done

List the size (in human readable form) of all sub folder

du -sk  * | sort -n | perl -pe '@SI=qw(K M G T P); s:^(\d+?)((\d\d\d)*)\s:$1." ".$SI[((length $2)/3)]."\t":e'

Show biggest files/directories

du --max-depth=1 | sort -r -n | awk '{split("k m g",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "v[s]"\t"$2}'

Display the human-readable with 3 decimal places

du -Lsbc * |awk 'function hr(bytes){hum[1024**4]="TiB";hum[1024**3]="GiB";
hum[1024**2]="MiB";hum[1024]="kiB";
for(x=1024**4;x>=1024;x/=1024){if(bytes>=x){return sprintf("%8.3f %s",bytes/x,hum[x]);}}return sprintf("%4d     B",bytes);}{print hr($1) "\t" $2}'

Show total size of each subdirectory

du --max-depth=1 | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 } $1 = sprintf("%.1f %s", $1, Units[u]); print $0; } '

Colored bar graph

du -x --max-depth=1|sort -rn|awk -F / -v c=$COLUMNS 'NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;32m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", $1/t*100, b, $2}'|tac

List sub dir, sort by size, the biggest at the end, with human presentation

du --max-depth=3 -x -k | sort -n | awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) {x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"iB" } {gsub(/^[0-9]+/, human($1)); print}'

Which files/dirs waste my disk space

du -xm --max-depth 2 /var/log | sort -rn | head

Easily find megabyte eating files or directories

du -cks * | sort -rn | while read size fname; do for unit in k M G T P E Z Y; do 
	if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; 
	fi; size=$((size/1024)); done; done

Find the 10 users that take up the most disk space

du -sm /home/* | sort -nr | head -n 10

Get the 10 biggest files/folders for the current direcotry

du -sh * | sort -rh | head

Get the 10 biggest files/folders for the current direcotry

du -s * | sort -n | tail

Find the biggest files

du -sk * | sort -rn | head

Sort the size usage of a directory tree by gigabytes, kilobytes, megabytes, then bytes.

du -b --max-depth 1 | sort -nr | perl -pe 's{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($1, "")}e'

Easily find megabyte eating files or directories

du -hs *|grep M|sort -n

Numerically sorted human readable disk usage

du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0

Nice disk usage, sorted by size, see description for full command

du -sk ./* | sort -nr

List the size (in human readable form) of all sub folders from the current location

du -sch ./*

List by size all of the directories in a given tree.

du -h /path | sort -h

List 10 largest directories in current directory

du -hs */ | sort -hr | head

Show biggest files/directories, biggest first with 'k,m,g' eyecandy

du --max-depth=1 | sort -r -n | awk '{split("K m g",v); s=1; while($1>1024){$1/=1024; s++} print int($1)" "V[s]"\t"$2}'

Sort the output of the 'du' command by largest first, using human readable output.

du -h --max-depth=1 |sort -rh

Du with colored bar graph

du -x --max-depth=1|sort -rn|awk -F / -v c=$COLUMNS 'NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", $1/t*100, b, $2}'|tac

Provide the ten largest subfolders in the current folder

du -hsx * | sort -rh | head -10

Shows size of dirs and files, hidden or not, sorted.

du -cs * .[^\.]* | sort -n

Quickly get summary of sizes for files and folders

du -sh *

List the size (in human readable form) of all sub folders from the current location

du --max-depth=1|sort -n|cut -f2|tr '\n' '\0'|xargs -0 du -sh 2>/dev/null

List the size of all sub folders and files from the current location, with sorting

du -a --max-depth=1 | sort -n

Get the 10 biggest files/folders for the current direcotry

du -sk * |sort -rn |head

Ultimate current directory usage command

du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '$d' | while read i; do if [ -f $i ]; then du -h "$i"; else echo "$(du -h --max-depth=0 "$i")/"; fi; done

Get the size of all the directories in current directory

du -hd 1

Alternative size (human readable) of files and directories (biggest last)

du -ms * .[^.]*| sort -nk1

List complete size of directories (do not consider hidden directories)

du -hs */

Easily find megabyte eating files or directories

du -cks * | sort -rn | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done

List the largest directories & subdirectoties in the current directory sorted from largest to smallest.

du -k | sort -r -n | more

Show sorted list of files with sizes more than 1MB in the current dir

du | sort -nr | cut -f2- | xargs du -hs

Sum file sizes

du -scb

List the size (in human readable form) of all sub folders from the current location

du -sh */

Get the size of all the directories in current directory

du --max-depth=1

Alternative size (human readable) of files and directories (biggest last)

du -ms * | sort -nk1

Find the 20 biggest directories on the current filesystem

du -xk | sort -n | tail -20

List the top 15 folders by decreasing size in MB

du -xB M --max-depth=2 /var | sort -rn | head -n 15

Shows size of dirs and files, hidden or not, sorted.

du --max-depth=1 -h * |sort -n -k 1 |egrep 'M|G'

List top ten files/directories sorted by size

du -sb *|sort -nr|head|awk '{print $2}'|xargs du -sh

Find all directories on filesystem containing more than 99MB

du -hS / | perl -ne '(m/\d{3,}M\s+\S/ || m/G\s+\S/) && print'

Outputs a sorted list of disk usage to a text file

du | sort -gr > file_sizes

List the size (in human readable form) of all sub folders from the current location

du -sk  * | sort -n | perl -pe '@SI=qw(K M G T P); s:^(\d+?)((\d\d\d)*)\s:$1." ".$SI[((length $2)/3)]."\t":e'

Sort contents of a directory with human readable output

du -hs * | sort -h

Simplest way to get size (in bytes) of a file

du -b filename

Sort disk usage from directories

du --max-depth=1 -h . | sort -h

Du and sort to find the biggest directories in defined filesystem

du -x / | sort -rn | less

List subfolders from largest to smallest with sizes in human readable form

du -hd1 | sort -hr

A sorted summary of disk usage including hidden files and folders

du -hs .[^.]* * | sort -h

Show sorted list of files with sizes more than 1MB in the current dir

du -hs * | grep '^[0-9,]*[MG]' | sort -rn

List directories sorted by (human readable) size

du -h time --max-depth=1 | sort -hr

View disk usage

du -hL --max-depth=1

Summary of disk usage, excluding other filesystems, summarised and sorted by size

du -xks * | sort -n

Get total of inodes of root partition

du total inodes / | egrep 'total$'

Sort content of a directory including hidden files.

du -sch .[!.]* * |sort -h

List all files/folders in working directory with their total size in Megabytes

du --max-depth=1 -m

List the biggest accessible files/dirs in current directory, sorted

du -ms * 2>/dev/null |sort -nr|head

Display the size of all your home's directories

du -sh ~/*

List 10 largest directories in current directory

du . -mak|sort -n|tail -10

Recursively find disk usage, sort, and make human readable (for systems without human-readable sort command)

du -x ${SYMLINKS} -k "$@" | sort -n | tail -100 | awk 'BEGIN { logx = log(1024); size[0]= "KB"; size[1]= "MB"; size[2]= "GB"; size[3]= "TB" } { x = $1; $1 = ""; v = int(log(x)/logx); printf ("%8.3f %s\t%s\n",x/(1024^v), size[v], $0) }'

Human readable directory sizes for current directory, sorted descending

du -hsx * | sort -rh

List the size (in human readable form) of all sub folders from the current location

du -h -d1

Display the human-readable sizes of all files and folders in the current directory with 3 decimal places

du -Lsbc * |awk 'function hr(bytes){hum[1024**4]="TiB";hum[1024**3]="GiB";hum[1024**2]="MiB";hum[1024]="KiB";for(x=1024**4;x>=1024;x/=1024){if(bytes>=x){return sprintf("%8.3f %s",bytes/x,hum[x]);}}return sprintf("%4d     B",bytes);}{print hr($1) "\t" $2}'

Simple du command to give size of next level of subfolder in MB

du --max-depth=1 -B M |sort -rn

Find directories over 50MB in the home directory

du -k ~/* | awk '$1 > 50000' | sort -nr

Shows size of dirs and files, hidden or not, sorted.

du --max-depth=1 -h * |sort -h -k 1 |egrep '(M|G)\s'

Show total size of each subdirectory, broken down by KB,MB,GB,TB

du --max-depth=1 | sort -nr | awk ' BEGIN { split("KB,MB,GB,TB", Units, ","); } { u = 1; while ($1 >= 1024) { $1 = $1 / 1024; u += 1 } $1 = sprintf("%.1f %s", $1, Units[u]); print $0; } '

List the size (in human readable form) of all sub folders from the current location

du -hs *|sort -h

Calculate the total size of files in specified directory (in Megabytes)

du -sm $dirname

Display total Kb/Mb/Gb of a folder and each file

du -hc *

Find top 10 largest files

du -a /var | sort -n -r | head -n 10

Which files/dirs waste my disk space

du -Sh | sort -h | tail

Du command without showing other mounted file systems

du -h --max-depth=1 one-file-system /

Get the size of all the directories in current directory (Sorted Human Readable)

du -h | sort -hr

List the Sizes of Folders and Directories

du -h --max-depth=1 /path/folder/

List the Sizes of Folders and Directories

du -hs /path/to/folder/*

One line Perl Script to determine the largest file sizes on a Linux Server

du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf  ("%6.1f\t%s\t%25s  %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"X (1.5*$l),$2);}' | more

Directory size with subdirectories, sorted list

du -m --max-depth=1 [DIR] | sort -nr

Shows major directories in ascending order

du . | sort -n

Find the path of biggest used space

du -a / | sort -n -r | head -n 10

Which files/dirs waste my disk space

du -aB1m|awk '$1 >= 100'

Get date time of foler/file created with du -csh

du -csh time *|sort -n|tail

List size and directies in curretn folder

du -sh ./*/

Display sorted, human readable list of file and folders sizes in your current working directory

du -had 1 | sort -h

Numerically sorted human readable disk usage

du -s * | sort -n | cut -f2 | tr '\n' '\0' | xargs -0 -I {} du -sh "{}"

Human readable total directory size

du -cah /path/to/folder/ | grep total

List the size (in human readable form) of all sub folders from the current location

du -h --max-depth=1 | sort -hr

List the size (in human readable form) of all sub folders from the current location

du -hd1 |sort -h

List only X byte files in the current directory

du -hs * |egrep -i "^(\s?\d+\.?\d+G)"

Histogram of file size

du -sm *| sort -nr | awk '{ size=4+5*int($1/5); a[size]++ }; END { print "Size(from->to)    number  graph"; for(i in a){ printf("%d         %d      ",i,a[i]) ; hist=a[i]; while(hist>0){printf("#") ; hist=hist-5} ; printf("\n")}}'

List the top 15 folders by decreasing size in MB

du -mx [directory] | grep -P '^\d{4}' | sort -rn

Total sum of directories

du -sh

Sum of directories

du -sh *

List the size (in human readable form) of all sub folders from the current location

du -sh *

Gets directory size on sub directories in current dir with human readable size

du -h --max-depth=1

List the size (in human readable form) of all sub folders from the current location

du . | sort -nr | awk '{split("KB MB GB TB", arr); idx=1; while ( $1 > 1024 ) { $1/=1024; idx++} printf "%10.2f",$1; print " " arr[idx] "\t" $2}' | head -25

Current sub-folders sizes

du -sh *

List size of individual folder in current directory

du -hs *

Find directories on your machine that are taking up greater than 1G

du -h -d 1 | ack '\d+\.?\d+G' | sort -hr

Find the 10 users that take up the most disk space

du -sm /home/* | sort -n | tail -10

List all files or directories consuming 1Mb or more

du -sc .[!.]* * |grep '^[0-9]{4}'

Sort all files and directories by size, rounded to the nearest megabyte. (Substitute custom path for *.)

du -ms * | sort -nr

IBM AIX: List directory size with max depth

du -g | perl -ne 'print if (tr#/#/!!! Example "== <maximum depth>)'

List sub dir, sort by size, the biggest at the end, with human presentation

du --max-depth=1 -x -k | sort -n | awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) {x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"IB" } {gsub(/^[0-9]+/, human($1)); print}'

List Big Files/Directories

du -h |grep -P "^\S*G"

BIGGEST Files in a Directory

du -k . | sort -rn | head -11

List the size (in human readable form) of all sub folders from the current location

du -hs * | sort -h

Sort contents of a directory by size

du -akx ./ | sort -n

Show what's taking space in a partition

du -ax | sort -n

Show size of in MB of the current directory.

du -sh `pwd`

A sorted summary of disk usage including hidden files and folders

du -ks .[^.]* * | sort -n

List all directory sizes and sort by size

du -ks * | sort -nr | cut -f2 | xargs -d '\n' du -sh

Which files/dirs waste my disk space

du -ah | sort -h | tail

Displays working directories 10 largest files in bytes and quickly

du -sk * | sort -n | tail

Get biggest directories

du -kh --max-depth=1 | sort -n |head

Find directories in pwd, get disk usage, sort results

du -a | sort -nr | head -10

-h means human readable

du -h

Size dir

du -s *|sort -nr|cut -f 2-|while read a;do du -hs $a;done

Sort subdirectories by size

du -h --max-depth=1 | sort -hr

Shows the size of folders and files, sorted from highest to lowest

du -sh * | sort -rh

Which files/dirs waste my disk space

du -h / | grep -w "[0-9]*G"

Du show hidden files all files

du -sch .[!.]* * |sort -h

Find and sort out folders by size

du -s $(ls -l | grep '^d' | awk '{print $9}') | sort -nr

See how much space is used by a file or directory

du -hs /path/to/target

View disk usage

du -hsL */

Calculate file as describe in one txt file

du -ch `cat test_file.txt`

Which files/dirs waste my disk space

du -xm --max-depth 2 /var/log | sort -rn | head

Sort the size usage of a directory tree

du --max-depth=1 -h apparent-size | sort -rh

Display a numbered list of 50 biggets files sorted by size (human readable)

du -ah | sort -hr | head -n50 | cat -n

Recursively remove directories less than specified size

du | awk '{if($1<1028)print;}' | cut -d $'\t' -f 2- | tr "\n" "\0" | xargs -0 rm -rf

Find the 10 lusers winners of the "I take up the most disk space" award

du -sh /home/*|sort -rh|head -n 10

Count files and directories disk space usage

du -ahc

Current directory files and subdirectories ordered by size

du -ks * | sort -n

Get size of a file

du -hs file-name

Easily find megabyte eating files or directories

du -kd | egrep -v "/.*/" | sort -n

List directories sorted by size

du -sh * | sort -h

Centos list directories sorted by size

du -h --max-depth=1 /home/ | sort -n

List the size (in human readable form) of all sub folders from the current location

du -sch *

List complete size of directories (do not consider hidden directories)

du --max-depth=1 | grep -v '\.\/\.'

List complete size of directories (do not consider hidden directories)

du -sh * | grep -v '\.\/\.'

List complete size of directories (do not consider hidden directories)

du -sh `ls -p | grep /`

List the size (in human readable form) of all sub folders from the current location

du -hs *

Identify big file

du -s * | sort -nr | head

Sort and show disk space (largest first) with human readable sizes

du -hs `du -sk * | sort -rn | cut -f2-`

Top ten of biggest files/dirs in $PWD

du -sm *|sort -rn|head -10

List top ten files/directories sorted by size

du -s * | sort -nr | head | cut -f2 | parallel -k du -sh

Show large folders and files, including hidden

du -shc .[^.]* * | grep [MG]

Find dis1k space

du -s `find . --maxdepth 1 \! -name '.'` | sort -n | tail

Outputs size of /example/folder in human readable format.

du -hs /example/folder/

List all files in current directory by size

du -sh *

Get top 10 largest directories under cwd

du | sort -n | tail -11 | head

Show the size of a directory

du -sh some/directory

Calculate the total size of files in specified directory (in Megabytes)

du -h <Directory>