Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Commands»How to sort du -h command output by size

    How to sort du -h command output by size

    RahulBy RahulMay 10, 20191 Min ReadUpdated:June 5, 2019

    Question – How do I sort du -h command output by there sizes?

    In the GNU Coreutils >= 7.5 package, sort command provides -h parameter allows to compare human-readable numbers (e.g., 10K 15M 1G etc). This helps up to compare the results of `du -h` and short them.

    du -h * | sort -h
    

    The above will show the results in the ascending order by size. You can reverse this using -r to show results in descending order.

    du -h * | sort -rh
    
    15M     btmp.1
    7.2M    apache2
    2.2M    auth.log.1
    1.9M    btmp
    1.5M    auth.log
    1.3M    redis
    656K    letsencrypt
    468K    auth.log.4.gz
    264K    auth.log.2.gz
    260K    cloud-init.log
    240K    auth.log.3.gz
    168K    mail.log.1
    
    command short size
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Setup Laravel File Permissions Correctly
    Next Article How to Convert String to Uppercase in Python

    Related Posts

    How to Search Recently Modified Files in Linux

    2 Mins Read

    Bash Printf Command

    Updated:December 23, 20212 Mins Read

    (Resolved) -bash: /bin/mv: Argument list too long

    Updated:January 13, 20222 Mins Read

    tee Command in Linux with Examples

    Updated:July 1, 20224 Mins Read

    How to Scan Open Ports with Nmap

    5 Mins Read

    Handling filenames with spaces in Linux

    3 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How To Install Docker on Ubuntu 22.04
    • How to Install Bower on Ubuntu 22.04 & 20.04
    • How to run “npm start” through Docker
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.