Unix command for the day: du -h | grep “[0-9]M” | sort -n -r > du.txt

Here’s the unix command for the day:
du -h | grep "[0-9]M" | sort -n -r > du.txt
or
du -h | grep "[0-9]M" | sort -n -r | less

This will:
1) Do a disk usage (human readable) du -h
2) pipe the results to grep to search for all instances of a number followed by M (for Megabyte)
3) sort the results (numerically) and in (reverse)
4) write the results into a file called du.txt

Then, using less du.txt will display a nice sorted list of all the directories starting in your current one that have a megabyte of data in them or more. Which might be very helpful if you’re wondering, where did all my disk space go? What can I safely delete and free up some diskspace? This did the trick.

P.S. I started the process with a du -h | grep "[0-9]G" to get the process started (show me all the directories that have a gigabyte or more of data in them.) Now instead of 1.+ G of free disk space I’ve got 7.7GB available (df -h).

Popularity: 2% [?]

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

One Response to “Unix command for the day: du -h | grep “[0-9]M” | sort -n -r > du.txt”

  1. Lyle Says:

    I would have thought you wanted:-
    du -h | grep "[0-9]+M" | sort -n -r > du.txt

    Lyle