Linux commands to list folders with their corresponding sizes

Simple du command lists all folders with their corresponding size of disk plus to start with.
DU – Disk Usage

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du
du
du

It takes given path as an argument

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du ~/inimist/docs
du ~/inimist/docs
du ~/inimist/docs

Aggregate total of sizes of all files and folder underneath

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du -s
du -s
du -s

Aggregate command works well with h option to display size in human readable format. For example, 2M, 1.3G etc.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du -sh
du -sh
du -sh

To sort by file or folder size

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du | sort -n -r | less
du | sort -n -r | less
du | sort -n -r | less

To find the largest files or folders on a file system

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du -a | sort -n -r | head -n 10
du -a | sort -n -r | head -n 10
du -a | sort -n -r | head -n 10

List all files greater than a threshold, sorted files by size

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
du -h --threshold=10M | sort -h
du -h --threshold=10M | sort -h
du -h --threshold=10M | sort -h

Leave a Reply