Subscribe to How-To Geek

List Files and Directories by Size on Linux

From HowToGeek

Jump to: navigation, search

This page will show us how to create a list of files and folders ordered by size using standard Linux commands.

Command

To get a list with the size of each item in a folder, you'll want to use the du command like this:

du -sm *

The -m argument will return the listing in megabytes (note that you can use -h for human readable, but it won't sort correctly)

Now we will want to run this through the sort command, sorting in reverse order -r and numeric -n:

du -sm * | sort -nr

The only problem here is that we'll get way too much output if there are a lot of files and folders, so we can either pipe it through the more command:

du -sm * | sort -nr | more

Or we can just return the top 15 largest items:

du -sm * | sort -nr | head -15

This will return a listing something like this:

2907    Files1
993     Files2
38      Somefile.txt
Our Friends
Getting Started
About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
Cmd.exe
Dpupdchk.exe Adobe_Updater.exe

All content on the How-To Geek Wiki is licensed under a Creative Commons License