od Exbi-Tech: List Files and Directories by Size on Linux
Powered by Blogger.

List Files and Directories by Size on Linux

Posted on
  • Thursday 19 May 2011
  • by
  • exbitech
  • in
  • Labels:

  • To get a list with the size of each item in a folder, we can use the du command like this:
    du -sm *
    The -m argument will return the listing in megabytes (note that you can use -h for human readable, but it won’t sort correctly)
    Now we will want to run this through the sort command, sorting in reverse order -r and numeric -n:
    du -sm * | sort -nr
    The only problem here is that we’ll get way too much output if there are a lot of files and folders, so we can either pipe it through the more command:
    du -sm * | sort -nr | more
    Or we can just return the top 15 largest items:
    du -sm * | sort -nr | head -15
    This will return a listing something like this:
    2907 Files1
    993 Files2
    38 Somefile.txt

    Use this command to find the directories taking up the most space:
    du -k | sort -nr | more
    The du command along with the -k switch lists all directories and their respective size in kilobytes.
    The sort command sorts the output so that the largest directory is shown first in the list. The -nr switch reverses the list and uses only numbers when sorting.
    Here’s an example of the output:
    12939451 .
    1814892 ./abcdef
    1219582 ./abcde
    839586 ./abcd
    718330 ./abc
    695610 ./ab
    690380 ./a

    For human-readable output use the following command:
    du -sh /*

    0 comments:

    Post a Comment

     
    Copyright (c) 2011 Exbi Tech
    Twitter Bird Gadget