Pages

Showing posts with label File Size. Show all posts
Showing posts with label File Size. Show all posts

Friday, November 1, 2013

Find largest files

Type the following command at the shell prompt to find out top 10 largest file/directories:
# du -a /var | sort -n -r | head -n 10

If you want more human readable output try:
$ cd /path/to/some/where
$ du -hsx * | sort -rh | head -10

Where,
  • du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G).
  • du command -s option : show only a total for each argument (summary).
  • du command -x option : skip directories on different file systems.
  • sort command -r option : reverse the result of comparisons.
  • sort command -h option : compare human readable numbers. This is GNU sort specific option only.
  • head command -10 OR -n 10 option : show the first 10 lines.
The above command will only work of GNU/sort is installed. Other Unix like operating system should use the following version (see comments below):
 
for i in G M K; do du -ah | grep [0-9]$i | sort -nr -k 1; done | head -n 11
 

This is also a good one ... here this returns the top 40:
find  -type f -printf '%s %p\n'| sort -nr | head -40



also see: http://linuxcountry.blogspot.com/2013/05/find-and-sort-all-files-by-size-save.html

Wednesday, May 1, 2013

Find and sort all files by size, save results to a text file on a Linux system

Find and order all files by size, save the result to a text file on a Linux system

du -k | sort -nr | awk '
     BEGIN {
        split("KB,MB,GB,TB", Units, ",");
     }
     {
        u = 1;
        while ($1 >= 1024) {
           $1 = $1 / 1024;
           u += 1
        }
        $1 = sprintf("%.1f %s", $1, Units[u]);
        print $0;
     }
    ' > result_list_ordered.txt




Tuesday, February 19, 2013

Find the Size of Directory in Suse Linux

Try these


du -h ./


For the most part this works. If you have spaces in file/directory
names than you may get some errors, but I'm sure you can work around
those if needed:

ls -1drt *| xargs du -h --summarize



You could also try

du -hc --max-depth=1

This will give you all the directories in the current directory, and a total at the bottom. Play with the --max-depth to dig down further in the structure and get more fine-grained results.

You can run this with a pipe to grep "G" to do a quick search of folders that are large enough to be measured in gigabytes. It will pull any directories with a capital G in them, but there aren't many of those so it works for me.

du -hc --max-depth=1 | grep "G"