• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / How To / How to Sort Directories by Size in Linux Ubuntu Command Line

How to Sort Directories by Size in Linux Ubuntu Command Line

By Sourabh / February 27, 2024 Category: How To, Ubuntu

Here is way to check which directory is taking more space in Linux. You can sort directories by size in Linux Ubuntu command line to find which is the largest directory by size.

List Directories In Linux

du -h --max-depth=1

NOTE:

  1. The du command by default lists all the directories and subdirectories recursively.
  2. -h option signifies ‘Human Readable’.

List Directories In Linux Sort By Size

To list all directories and sort them by size, you can pipe the output of this command and pass it through the sort utility like this :

du -h --max-depth=1 | sort -h

Similarly you can specify any directory using the following command:

du -h --max-depth=1 /path/to/directory

List 10 Biggest Directories In Linux Sort By Size

To only list, let’s say, the 10 biggest directories, you can use the du command along with the head command. We will also use the tail command to avoid listing the size of the current directory like this :

du -h --max-depth=1 2> /dev/null | sort -hr | tail -n +2 | head

NOTE: Command Arguments

  • -h, –human-readable: print sizes in human readable format (e.g., 1K 234M 2G)
  • -d, –max-depth=N: print the total for a directory (or file, with –all) only if it is N or fewer levels below the command line argument.

The ‘sort’ command is used to sorts, merges, or compares all the lines from the given files, or
standard input if none are given or for a FILE of ‘-’.

  • ‘-h’ is used to sort numerically, first by numeric sign (negative, zero, or positive); then by SI suffix and finally by numeric value.

For example, ‘1023M’ sorts before ‘1G’ because ‘M’ (mega) precedes ‘G’ (giga) as an SI suffix.

Primary Sidebar

Latest Posts

Job Scheduling Using At Command In Linux With Examples

How To Check Permissions Of A Directory In Linux Command

Delete Directory And Contents Recursively Without Prompt On Linux

Check User Login History In Ubuntu Linux Command Line

Use Locate Command To Find File In Linux Terminal By Name

How To Change Terminal Color In Ubuntu Command Line

How To Run Fsck Manually In Linux To Fix Unexpected Inconsistency

How To Fix Broken Packages On Ubuntu From Terminal

Re Execute The Previous Command In Linux Ubuntu Command Line

How Much RAM Is Needed For Ubuntu PC

© 2026 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap