{"id":394025,"date":"2022-01-14T16:00:53","date_gmt":"2022-01-14T13:00:53","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line-cloudsavvy-it\/"},"modified":"2022-01-14T16:00:53","modified_gmt":"2022-01-14T13:00:53","slug":"how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line-cloudsavvy-it\/","title":{"rendered":"#How to View and Monitor Disk Space Usage From the Linux Command Line \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6aee9c4cada0f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6aee9c4cada0f\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line-cloudsavvy-it\/#Checking_Disk_Usage_On_Linux\" >Checking Disk Usage On Linux<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line-cloudsavvy-it\/#Monitoring_At_a_Glance\" >Monitoring At a Glance<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line-cloudsavvy-it\/#Sending_Alerts_When_Your_Disk_Usage_Is_Too_High\" >Sending Alerts When Your Disk Usage Is Too High<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to View and Monitor Disk Space Usage From the Linux Command Line \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-4038\" data-pagespeed-lazy-srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Bash Shell\" width=\"1400\" height=\"600\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>While it\u2019s usually pretty clear if your system is running out of memory or using too much CPU time, disk usage is another key metric that can sneak up on you over time if you leave your server unattended. You\u2019ll want to regular check your disk usage using these commands.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Checking_Disk_Usage_On_Linux\"><\/span>Checking Disk Usage On Linux<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The utility used to quickly check disk usage on almost all Linux systems is <code>df<\/code>, which stands for \u201cdisk filesystems.\u201d It simply prints out a list of all the filesystems on your system.<\/p>\n<pre>df -hT<\/pre>\n<p>This command here is invoked with two flags, <code>-h<\/code>\u00a0for \u201chuman readable,\u201d which prints out byte numbers in KB, MB, and GB, and <code>-T<\/code>, which displays the type of the filesystem.<\/p>\n<p><code>df<\/code>\u00a0will print out each filesystem alongside the size, how much is used and available, and where it\u2019s mounted to on your system.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15261\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2022\/01\/98b7e815.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"624\" height=\"439\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019ll quickly notice that you probably have a lot more \u201cfilesystems\u201d than you\u2019d expect. This server only has one solid state drive, but has over 20 filesystems. Most of these are backend stuff used for other programs and services, such as compressed\u00a0<code>squashfs<\/code>, virtual\u00a0<code>tmpfs<\/code>\u00a0, and Docker\u2019s <code>overlay<\/code>\u00a0systems used for containers.<\/p>\n<p>In this example, <code>ext4<\/code>\u00a0is the real drive, which is obvious because it\u2019s mounted at root, but in multi-drive systems that may not be im<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>tely clear. If you want, you can filter this list by specifying which type you want to see with the lowercase <code>-t<\/code>\u00a0flag:<\/p>\n<pre>df -hT -t ext4<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15262\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2022\/01\/cbd87bac.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"444\" height=\"62\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Or by removing what you don\u2019t want to see manually with the <code>-x<\/code>\u00a0flag:<\/p>\n<pre>df -hT -x squashfs -x overlay -x tmpfs -x devtmpfs<!--EndFragment --><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15265\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2022\/01\/9a1a652d-2.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"608\" height=\"80\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can also ask <code>df<\/code>\u00a0for info on any specific filesystem, even including wildcards to match multiple systems by name:<\/p>\n<pre>df -h \/dev\/md*<\/pre>\n<p>Or, you can ask it for info on a specific mount, which is most useful for quickly getting the info on your root system:<\/p>\n<pre>df -h \/<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Monitoring_At_a_Glance\"><\/span>Monitoring At a Glance<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Most of the time though, you probably don\u2019t want to remember and type a bunch of commands with specific flags. That\u2019s what the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/nicolargo.github.io\/glances\/\"><code>glances<\/code>\u00a0utility<\/a> was made for, and we highly recommend giving it a try.<\/p>\n<p>It\u2019s basically a replacement for built-in utilities like <code>top<\/code>\u00a0and <code>htop<\/code>, except it displays a lot of different performance metrics about your system, the disks. It\u2019s not included in most Linux distros by default, but it\u2019s open source and can be installed from <code>pip<\/code>, given it\u2019s a Python <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>.<\/p>\n<pre>sudo pip install glances<\/pre>\n<p>Then simply run the app to open up the <code>glances<\/code>\u00a0dashboard:<\/p>\n<pre>glances<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15266\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2022\/01\/d3d07e4d.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1022\" height=\"608\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You\u2019ll find in the lower left corner some info on disk usage, including current I\/O speeds, as well as each physical disk\u2019s total usage. Using this, you can easily spot problems with disks filling up before it breaks your system.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-15267\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2022\/01\/faebb352.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"334\" height=\"296\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>There are plenty of other utilities for monitoring your system, but <code>glances<\/code>\u00a0checks all the boxes, so it\u2019s a pretty nice tool to have.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Sending_Alerts_When_Your_Disk_Usage_Is_Too_High\"><\/span>Sending Alerts When Your Disk Usage Is Too High<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The main problem with command line tools is that they require you to be proactive about checking for problems. But problems can pop up unexpectedly, so it\u2019s good to get notified about them beforehand.<\/p>\n<p>So, the solution is to set up a daily <code>cron<\/code>\u00a0job that will run <code>df<\/code>\u00a0automatically to check the usage on the root system. It will compare this with a set value, and if it\u2019s greater, it\u2019ll send a message.<\/p>\n<pre>#!\/bin\/bash&#13;\nCURRENT=$(df \/ | grep \/ | awk '{ print $5}' | sed 's\/%\/\/g')&#13;\nTHRESHOLD=90&#13;\n&#13;\nif [ \"$CURRENT\" -gt \"$THRESHOLD\" ] ; then&#13;\ncurl -X POST -H 'Content-type: application\/json' --data \"{\"text\":\"Your server `$(hostname)` is currently at ${CURRENT}% disk capacity.\"}\"&#13;\nfi<\/pre>\n<p>You have plenty of options for how to get messages, and it will depend on your preferred contact. The simplest would be to set up the <code>mail<\/code>\u00a0utility to send you emails from the command line. You can read our article on setting up Postfix to handle this for you.<\/p>\n<p>A much cooler method is to send yourself a message directly on a messaging platform you\u2019re active on, such as setting up Slack notifications from your server, which can be easily done using webhooks with <code>curl<\/code>\u00a0POST requests.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-845\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/e489d8e1-3.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>You can read our article on setting up Slack webhooks for disk space alerts to learn more.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to Setup Slack Notifications for Low Disk Space On Your Server<\/em><\/strong>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/15219\/how-to-view-and-monitor-disk-space-usage-from-the-linux-command-line\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to View and Monitor Disk Space Usage From the Linux Command Line \u2013 CloudSavvy IT&#8221; While it\u2019s usually pretty clear if your system is running out of memory or using too much CPU time, disk usage is another key metric that can sneak up on you over time if you leave your server unattended&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":394026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2017\/07\/add8ac45.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-394025","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/394025","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=394025"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/394025\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/394026"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=394025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=394025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=394025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}