cancel
Showing results for 
Search instead for 
Did you mean: 
Trevor
Commander Commander
Commander
  • 197 Views

Directory Using Most Disk Space

How can I learn which directory on my Linux system is using/consuming 
the most disk space?

Trevor "Red Hat Evangelist" Chandler
Labels (3)
4 Replies
shashi01
Moderator
Moderator
  • 172 Views

@Trevor 

du -sh /* 2>/dev/null      # shows you the size of all the main folders, but you have to find the biggest one yourself.

du -h --max-depth=1 / 2>/dev/null | sort -hr | head -n 5   # It finds the sizes, automatically sorts them from biggest to smallest, and shows you just the top 5. It does all the work for you

Trevor
Commander Commander
Commander
  • 163 Views

Thanks shashi01 for that 2nd option, cause I just wanted to be able to 
add water and stir

 

Trevor "Red Hat Evangelist" Chandler
0 Kudos
shashi01
Moderator
Moderator
  • 160 Views

@Trevor 

Glad it helped!

0 Kudos
Chetan_Tiwary_
Community Manager
Community Manager
  • 37 Views

@Trevor you have mutliple options here. Three of famous options you can use are :

1. 

du / -hxd 1 -t 1M | sort -hr | head -n5

this simply comes to mean : On the root filesystem (/), list all first-level subdirectories whose aggregated disk usage is ≥ 1 MB, show them in human-readable sizes, then sort them with the largest first.

or simply use this : du -ahx / | sort -hr | head

or use this same du command along with find  command to check those large files : 

find / -type f -exec du -Sh {} + | sort -rh | head -n5

2. use find command 

find /dir-path/ -printf '%s %p\n'| sort -nr | head -10

3. use for loop in a bash script for finding largest size of all files and directories in the current directory and its subdirectories. You need to grep with numeric size in G( GB) , M( MB) and K ( KB) using same du command just tat grep part is grep [0-9]$i  where i can be G/M/K 

0 Kudos
Join the discussion
You must log in to join this conversation.