Pages

Showing posts with label order. Show all posts
Showing posts with label order. Show all posts

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