{"id":731,"date":"2010-01-07T16:15:28","date_gmt":"2010-01-07T21:15:28","guid":{"rendered":"http:\/\/www.gamescheat.ca\/?p=731"},"modified":"2019-09-04T19:57:39","modified_gmt":"2019-09-05T00:57:39","slug":"list-files-by-size-in-reverse-numerical-order-in-linux-or-unix","status":"publish","type":"post","link":"http:\/\/www.gamescheat.ca\/?p=731","title":{"rendered":"List files by size in reverse numerical order in Linux or Unix."},"content":{"rendered":"<p>The root drive on my Solaris server was full and I needed to find out what file was the largest. The du command can list the size of the files in a directory, you can then use the sort command to display the results in numerical order (by size).<\/p>\n<p>Below is an example of the commands used to list the files by size, from the largest to the smallest, in the \/ directory.<\/p>\n<blockquote><p>du -akd \/ | sort -nr | more<\/p><\/blockquote>\n<div style=\"float: right;\"><div style=\"margin: 15px 15px 15px 15px\";><script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"pub-3319935785736004\";\ngoogle_alternate_color = \"FFFFFF\";\ngoogle_ad_width = 336;\ngoogle_ad_height = 280;\ngoogle_ad_format = \"336x280_as\";\ngoogle_ad_type = \"text_image\";\ngoogle_ad_channel =\"\";\ngoogle_color_border = \"cccccc\";\ngoogle_color_link = \"cc0000\";\ngoogle_color_bg = \"ffffff\";\ngoogle_color_text = \"000000\";\ngoogle_color_url = \"008000\";\n\/\/--><\/script>\n<script type=\"text\/javascript\"\n  src=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><\/div><\/div><p>The -a option of the du command means to report the file size.  Whthout this option du will just display the amount of space used in each directory.<\/p>\n<p>-k means to display the file in kilobytes, the default is 512 bytes block.  You can also substitute it with -h which means human redable format, the output will be in kilobytes, megabytes and gigabytes.<\/p>\n<p>-d option keeps the du command from crossing the partition boundries.<\/p>\n<p>The -n option with the sort command, filters the results in numerical order and the -r means reverse numerical order.<\/p>\n<p>The | symbol separates the different commands.  In this case the three commands are du, sort and more.<\/p>\n<p>The more command simply means to display the result one screen at a time, otherwise it will scroll off the top.<\/p>\n<p>If you wanted to capture the results in a file for later viewing, then use the redirect > symbol as in the below example.<\/p>\n<blockquote><p>$ du -akd \/ | sort -nr > \/export\/home\/results<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The root drive on my Solaris server was full and I needed to find out what file was the largest. The du command can list the size of the files in a directory, you can then use the sort command&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.gamescheat.ca\/?p=731\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[19],"tags":[55,64,35],"_links":{"self":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/731"}],"collection":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=731"}],"version-history":[{"count":1,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions"}],"predecessor-version":[{"id":732,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions\/732"}],"wp:attachment":[{"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gamescheat.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}