X
X
The Best Tech Newsletter Anywhere

Join 250,000 subscribers and get a daily digest of news, geek trivia, and our feature articles.

List Files and Directories by Size on Linux

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
Lowell Heddings Lowell Heddings
Lowell is the founder and CEO of How-To Geek. He’s been running the show since creating the site back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work.
Read Full Bio »

The above article may contain affiliate links, which help support How-To Geek.
How-To Geek is where you turn when you want experts to explain technology. Since we launched in 2006, our articles have been read more than 1 billion times. Want to know more?

x

The Best Tech Newsletter Anywhere

Join 250,000 subscribers and get a daily digest of news, comics, trivia, reviews, and more.