{"id":171,"date":"2023-10-16T17:52:03","date_gmt":"2023-10-16T09:52:03","guid":{"rendered":"https:\/\/blog.quantoyo.com\/?p=171"},"modified":"2023-10-17T12:00:09","modified_gmt":"2023-10-17T04:00:09","slug":"linux-%e6%9f%a5%e7%9c%8b%e7%a1%ac%e7%a2%9f%e7%8b%80%e6%85%8b","status":"publish","type":"post","link":"https:\/\/blog.quantoyo.com\/?p=171","title":{"rendered":"Linux \u67e5\u770b\u786c\u789f\u72c0\u614b"},"content":{"rendered":"\n<!--more-->\n\n\n\n<p>du\u6307\u4ee4 (\u6383\u63cf\u76ee\u9304\u7d50\u69cb)<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>-a | \u986f\u793a\u76ee\u9304\u4e2d\u500b\u5225\u6a94\u6848\u7684\u5927\u5c0f\n-b | \u4ee5bytes\u70ba\u55ae\u4f4d\u986f\u793a\n-c | \u986f\u793a\u500b\u5225\u6a94\u6848\u5927\u5c0f\u8207\u7e3d\u548c\n-D | \u986f\u793a\u7b26\u865f\u93c8\u7d50\u7684\u4f86\u6e90\u6a94\u5927\u5c0f\n-h | Human readable\n-H | \u8207-h\u985e\u4f3c, \u4f46\u662f\u4ee51000\u70bak\u7684\u55ae\u4f4d\u800c\u975e1024 bytes\u70ba\u5340\u584a\u7684\u55ae\u4f4d\n-l | \u91cd\u8907\u8a08\u7b97\u93c8\u7d50\u9ee8\u6240\u5360\u7a7a\u9593\n-L \u7b26\u865f\u93c8\u7d50 | \u6307\u5b9a\u7b26\u865f\u93c8\u7d50\u6a94\u7684\u5927\u5c0f\n-m | \u4ee5 MB \u70ba\u986f\u793a\u55ae\u4f4d\n-s | \u53ea\u986f\u793a\u7e3d\u548c\n-S | \u986f\u793a\u76ee\u9304\u5167\u5bb9\u6642, \u4e0d\u5305\u542b\u5b50\u76ee\u9304\u5927\u5c0f.\n-x | \u82e5\u76ee\u9304\u4e2d\u6709\u4e0d\u540c\u7684\u6a94\u6848\u7cfb\u7d71, \u4e0d\u986f\u793a\u76f8\u7570\u7684\u6a94\u6848\u7cfb\u7d71\n--exclude | \u5ffd\u7565\u6307\u5b9a\u7684\u6a94\u6848\u6216\u76ee\u9304\n--max-depth | \u50c5\u641c\u5c0b\u6307\u5b9a\u7684\u76ee\u9304\u5c64\u7d1a<\/code><\/pre>\n\n\n\n<p>df\u6307\u4ee4 (\u5f9e\u6a94\u6848\u7cfb\u7d71\u7372\u53d6\u7a7a\u9593\u8cc7\u8a0a)<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>-a : \u5217\u51fa\u6240\u6709\u7684\u6a94\u6848\u7cfb\u7d71\uff0c\u5305\u542b\u7cfb\u7d71\u6301\u6709\u7684 \/proc \u7b49\u6a94\u6848\u7cfb\u7d71\u3002\n-k : \u4ee5 KB \u7684\u683c\u5f0f\u986f\u793a\u3002\n-m : \u4ee5 MB \u7684\u683c\u5f0f\u986f\u793a\u3002\n-h : \u81ea\u52d5\u4ee5 GB, MB, KB \u7b49\u683c\u5f0f\u986f\u793a\u3002\n-H : \u4ee5 M=1000K \u53d6\u4ee3 M=1024K\u3002\n-T : \u986f\u793a\u6a94\u6848\u7cfb\u7d71\u985e\u578b\u3002\n-i : \u4ee5 inode \u7684\u6578\u91cf\u986f\u793a\u3002\n-t : \u53ea\u5370\u51fa\u6307\u5b9a &lt;\u985e\u578b&gt; \u7684\u6a94\u6848\u7cfb\u7d71\u8cc7\u8a0a<\/code><\/pre>\n\n\n\n<p>sort\u6307\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>-n \u2013number-sort \u4f9d\u5b57\u4e32\u6578\u503c\u6392\u5e8f\uff0c\u8207-g\u5340\u5225\u70ba\u4e0d\u8f49\u70ba\u6d6e\u9ede\u6578\n-g \u2013general-number-sort \u6309\u901a\u7528\u8a55\u5206\u6392\u5e8f\uff0c\u652f\u63f4\u79d1\u5b78\u8a08\u6578\u6cd5\n-f \u2013ignore-case \u5ffd\u7565\u5927\u5c0f\u5beb\uff0c\u9810\u8a2d\u5927\u5c0f\u5beb\u5b57\u6bcd\u4e0d\u540c\n-k \u2013key=POS1&#91;,POS2] \u6392\u5e8f\u5f9ePOS1\u958b\u59cb\uff0c\u82e5\u6307\u5b9aPOS2\uff0c\u5247POS2\u7d50\u675f\uff0c\u5426\u5247\u4ee5pos\u200b\u200b1\u6392\u5e8f\n-t \u2013field-separator=SEP \u6307\u5b9a\u5217\u7684\u5206\u5272\u7b26\n-r \u2013\u53cd\u5411\u964d\u5e8f\u6392\u5e8f\uff0c\u9810\u8a2d\u70ba\u5347\u5e8f\n-h \u2013 human-numeric-sort \u4f7f\u7528\u6613\u8b80\u6027\u6578\u5b57(\u4f8b\u5982\uff1a 2K 1G)\n-u \u2013unique \u53bb\u6389\u91cd\u8907\u7684\u884c\n-o \u2013output=FILE \u5c07\u8f38\u51fa\u5beb\u5165\u6587\u4ef6<\/code><\/pre>\n\n\n\n<p>\u770b\u76ee\u524d\u8cc7\u6599\u593e\u7684\u524d\u5341\u7b46\u8cc7\u6599&nbsp; &nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>du -hs * | sort -hr| head -n 10\n\n\u8a73\u89e3\uff1a\n1. du \u6307\u4ee4\uff0c\u53d6\u5f97\u76ee\u524d\u8cc7\u6599\u593e\u4e0b\u6240\u6709\u6a94\u6848\u8207\u8cc7\u6599\u593e\u7684\u8a0a\u606f\uff0c\u8f49\u63db\u6210\u6613\u8b80\u7684\u6a94\u6848\u5927\u5c0f\u8cc7\u8a0a\u4e26\u53ea\u986f\u793a\u7576\u524d\u8cc7\u6599\u593e\u6240\u770b\u7684\u5230\u7684\u6a94\u6848\u6216\u8a72\u5c64\u7684\u8cc7\u6599\u593e(\u4e0d\u6703\u986f\u793a\u4e0b\u5c64\u8cc7\u6599\u593e)\n2. \u5c07\u7b2c\u4e00\u9ede\u7684\u8cc7\u6599\u4e1f\u5230sort\u6307\u4ee4\uff0c\u4e26\u6839\u64da\u525b\u525b\u6240\u4f7f\u7528\u7684 -h \u5f97\u5230\u7684\u6a94\u6848\u5927\u5c0f\u6392\u5e8f\uff0c\u4e14\u964d\u5e8f\u6392\u5e8f\n3. \u53d6\u6700\u5148\u51fa\u73fe\u768410\u7b46\u4f86\u986f\u793a\n\ndu -shc .\n\n\u8a73\u89e3\uff1a\n\u6307\u5b9a\u4e00\u500b\u8cc7\u6599\u593e\uff0c\u770b\u4f54\u591a\u5c11\u5bb9\u91cf<\/code><\/pre>\n\n\n\n<p>\u770b\u6574\u53f0\u6a5f\u5668\u7684\u786c\u789f\u72c0\u614b<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>df -h\n\n\u8a73\u89e3\uff1a\n\u4ee5\u5bb9\u6613\u770b\u61c2\u7684\u5bb9\u91cf\u8cc7\u8a0a\u986f\u793a\u6240\u6709\u639b\u8f09\u7684\u786c\u789f\u8cc7\u8a0a\n\ndf -h| awk '{ print $4 \"   \"$5 \"  \" $1 }'\n\n\u8a73\u89e3\uff1a\ndf \u53d6\u5f97\u8cc7\u8a0a\u5f8c\uff0c\u4f7f\u7528 awk \u8f38\u51fa Avail   Use%  Filesystem \u9019\u4e09\u500b\u8cc7\u8a0a<\/code><\/pre>\n\n\n\n<p>\u53ef\u4ee5\u5bebshellscript\u4f86\u5075\u6e2c\u6a5f\u5668\u662f\u5426\u8d85\u904e\u76ee\u6a19\u503c<\/p>\n\n\n\n<pre class=\"wp-block-code has-light-gray-background-color has-background has-small-font-size\"><code>#!\/bin\/sh\ndf -t ext4 -t vfat | tail -n +2 | awk '{ print $5 \" \" $1 }' | while read output;\ndo\n  # \u53d6\u51fa\u4f7f\u7528\u91cf\uff08\u767e\u5206\u6bd4\uff09\n  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )\n  # \u6a94\u6848\u7cfb\u7d71\n  partition=$(echo $output | awk '{ print $2 }' )\n  # \u82e5\u7528\u91cf\u5927\u65bc 90% \u5247\u7528 Email \u767c\u51fa\u8b66\u544a\u8a0a\u606f\n  if &#91; $usep -ge 90 ]; then\n    echo \"Running out of space \\\"$partition ($usep%)\\\" on $(hostname) as on $(date)\" |\n      mail -s \"Alert: Almost out of disk space $usep%\" you@somewhere.com\n  fi\ndone<\/code><\/pre>\n\n\n\n<p>\u53c3\u8003\u8cc7\u6599\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/blog.csdn.net\/shuanghujushi\/article\/details\/51344215\">https:\/\/blog.csdn.net\/shuanghujushi\/article\/details\/51344215<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/hackmd.io\/@tienyulin\/linux-disk-management\">https:\/\/hackmd.io\/@tienyulin\/linux-disk-management<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/blog.gtwang.org\/linux\/linux-df-command-check-disk-space-usage-tutorial-script-example\/\">https:\/\/blog.gtwang.org\/linux\/linux-df-command-check-disk-space-usage-tutorial-script-example\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[32,31,37],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-technology","tag-df","tag-du","tag-linux"],"_links":{"self":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":2,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"predecessor-version":[{"id":173,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions\/173"}],"wp:attachment":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}