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

Here’s the unix command for the day:
du -h | grep "[0-9]M" | sort -n -r > du.txt
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).

2 Responses 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


  2. duh Says:

    gth linux!

sell diamonds