{"id":19558,"date":"2016-03-03T03:01:03","date_gmt":"2016-03-02T17:01:03","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=19558"},"modified":"2017-10-08T09:45:27","modified_gmt":"2017-10-07T23:45:27","slug":"linux-disk-usage-statistics-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-disk-usage-statistics-primer-tutorial\/","title":{"rendered":"Linux Disk Usage Statistics Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/linux_du.jpg\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Linux Disk Usage Statistics Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/linux_du.jpg\" title=\"Linux Disk Usage Statistics Primer Tutorial\"  style=\"float:left;\"  \/><\/a><p class=\"wp-caption-text\">Linux Disk Usage Statistics Primer Tutorial<\/p><\/div>\n<p>There are occasions when using a Linux or Unix operating system when it is gobsmacking how a two letter command can do so much.  And so it is the case with our use of the <a target=_blank title='Computerhope information for du' href='http:\/\/www.computerhope.com\/unix\/udu.htm'>&#8220;du&#8221;<\/a> to display disk usage statistics via the incarnation &#8230;<\/p>\n<p><code>$ du -a \/<\/code><\/p>\n<p> &#8230; to display a whole disk from its root directory ( \/ ) and up, reporting on the disk usage for all the files it encounters.<\/p>\n<p>Putting this in context for how it could be useful to track down, perhaps, major inode usage (ie. lots of files being created) somewhere.  In this scenario we say that we might want to narrow the search to the top 15 files (which are perhaps directories, as you might know from your Unix and\/or Linux training) via &#8230;<\/p>\n<p><code>$ du -a \/ 2> \/dev\/null | sort -n -r | head -15<\/code><\/p>\n<p> &#8230; and on our local MAMP web server (of a MacBook Pro) we got<\/p>\n<p><code>$ du -a \/ 2> \/dev\/null | sort -n -r | head -15<br \/>\n463218232\t\/<br \/>\n183397888\t\/Users<br \/>\n183393240\t\/Users\/user<br \/>\n173735704\t\/Library<br \/>\n155636160\t\/Library\/pgAgent<br \/>\n139676416\t\/Users\/user\/Desktop<br \/>\n139661920\t\/Users\/user\/Desktop\/NS15148<br \/>\n109587848\t\/Users\/user\/Desktop\/NS15148\/robertmetcalfe<br \/>\n66994504\t\/Library\/pgAgent\/Downloads<br \/>\n48401968\t\/Applications<br \/>\n44435304\t\/Library\/pgAgent\/Library<br \/>\n27955056\t\/Users\/user\/Desktop\/NS15148\/robertmetcalfe\/Downloads<br \/>\n27639928\t\/opt<br \/>\n26857192\t\/opt\/local<br \/>\n26839216\t\/Library\/pgAgent\/VirtualBox VMs<br \/>\n<\/code><\/p>\n<p> &#8230; and just to put a little intelligence into this have a look at the <a target=_blank title='Computerhope information for file' href='http:\/\/www.computerhope.com\/unix\/ufile.htm'>&#8220;file&#8221;<\/a> command as a means to show a file type, and the marvellous <a target=_blank title='Computerhope information for awk' href='http:\/\/www.computerhope.com\/unix\/uawk.htm'>&#8220;awk&#8221;<\/a> integration of all this via its &#8220;system()&#8221; method &#8230;<\/p>\n<p><code>$ du -a \/ 2> \/dev\/null | sort -n -r | head -15 | awk -F\"\\t\" '{ print $1, FS, system(\"file \\\"\" $2 $3 $4 $5 \"\\\"\"); }' | grep -v '^[0| ]' | sed '\/:\/s\/\/ ... is a\/g'<br \/>\n463218232 \t \/ ... is a directory<br \/>\n183397888 \t \/Users ... is a directory<br \/>\n183393240 \t \/Users\/user ... is a directory<br \/>\n173735704 \t \/Library ... is a directory<br \/>\n155636160 \t \/Library\/pgAgent ... is a directory<br \/>\n139676416 \t \/Users\/user\/Desktop ... is a directory<br \/>\n139661920 \t \/Users\/user\/Desktop\/NS15148 ... is a directory<br \/>\n109587848 \t \/Users\/user\/Desktop\/NS15148\/robertmetcalfe ... is a directory<br \/>\n66994504 \t \/Library\/pgAgent\/Downloads ... is a directory<br \/>\n48401968 \t \/Applications ... is a directory<br \/>\n44435304 \t \/Library\/pgAgent\/Library ... is a directory<br \/>\n27955056 \t \/Users\/user\/Desktop\/NS15148\/robertmetcalfe\/Downloads ... is a directory<br \/>\n27639928 \t \/opt ... is a directory<br \/>\n26857192 \t \/opt\/local ... is a directory<br \/>\n26839216 \t \/Library\/pgAgent\/VirtualBox VMs ... is a directory<br \/>\n<\/code><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d19558' onclick='var dv=document.getElementById(\"d19558\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/linux\/\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d19558' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>There are occasions when using a Linux or Unix operating system when it is gobsmacking how a two letter command can do so much. And so it is the case with our use of the &#8220;du&#8221; to display disk usage &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-disk-usage-statistics-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,29,37],"tags":[122,234,2346,1752,707,885,997,1319,1339],"class_list":["post-19558","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-awk","tag-command-line","tag-diskspace","tag-inode","tag-linux","tag-operating-system-2","tag-programming","tag-tutorial","tag-unix"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/19558"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=19558"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/19558\/revisions"}],"predecessor-version":[{"id":19559,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/19558\/revisions\/19559"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=19558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=19558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=19558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}