1

I use this command to find the disk usage:

du -sh ~/* | sort -r

But it messes up with with the K, M, and G suffixes added by du -h.

956M    /Users/shinokada/Docker
9.2G    /Users/shinokada/RustProjects
856M    /Users/shinokada/Bitbucket
8.2M    /Users/shinokada/Desktop
708M    /Users/shinokada/Medium-articles
596K    /Users/shinokada/Movies
480M    /Users/shinokada/Sites
415M    /Users/shinokada/MyProjects
4.1M    /Users/shinokada/jupyter-work
4.0M    /Users/shinokada/powerlevel9k
4.0K    /Users/shinokada/sys_info_page.html
4.0K    /Users/shinokada/requirements.txt
4.0K    /Users/shinokada/package-lock.json
4.0K    /Users/shinokada/mypath.txt
4.0K    /Users/shinokada/cecilieo
4.0K    /Users/shinokada/bin
258M    /Users/shinokada/Github
256M    /Users/shinokada/Calibre Library
228K    /Users/shinokada/LaTeX
2.7G    /Users/shinokada/nltk_data
2.2G    /Users/shinokada/Projects
2.1G    /Users/shinokada/DataScience
170M    /Users/shinokada/Applications
157M    /Users/shinokada/Pictures
1.8G    /Users/shinokada/virtualenvs
...

How can I put them in order?

I used -m and -k flag but it still sort by number not size.

1 Answer 1

6

This worked.

du -sh ~/* | sort -rh

sort has -h flag:

-h, --human-numeric-sort, --sort=human-numeric
             Sort by numerical value, but take into account the SI suffix, if present.
...
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .