Finding the biggest directories on Linux

Note, a very nice and small interactive program is ncdu.
sudo apt-get install ncdu

It will “graphically” show you the biggest directories and let you navigate your directories and delete large files.

If you can’t install ncdu, try the process below using built-in functions.
———————————————————–
To find the biggest directories on your Linux system, in the example below, your home directory as indicated by the tilde, in Terminal type:

du -a ~ | sort -n -r | head -n 25

This will list the 25 biggest directories in home.

———
Here is a Bash script to do the same:

#!/bin/bash
# finds the biggest files in a directory you specify
#
# example #1:
# findbig ~ 15
# would tell you the biggest 15 files under your HOME directory (including all subfolders)
#
# example #2:
# findbig
# just finds the 10 biggest files in your current directory
#
# tested on bash 4.2.25 (ubuntu 12.04)
# Michael Hirsch BSD License July 2013

if [ $# -gt 0 ]; then fDir=$1; else fDir=".";fi
if [ $# -gt 1 ]; then nFile=$2; else nFile=10; fi

# NOT -execdir, or else you can't see the directory the big files are in!
find $fDir -type f -exec ls --size {} \; | sort --numeric-sort --reverse | head --lines=$nFile

Reference: http://www.unixmen.com/how-to-find-large-files-and-directories-in-linux/

Post a Comment

Your email address is never shared.