Problem
How many times have you been given the job, to clear down space in a UNIX file system?
Ever wanted to see the percentage, on a directory by directory basis.
Solution
Here is a simple bit of code, to display the current directory’s percentage of over all space available
Example
(du -ks . | tr 'n' ' '; (df -k . | tail -1)) | gawk ' { printf("%0.0f%n",($1/$4)*100); } '
Here is a run through, checking /usr:
[[email protected] usr]# (du -ks . | tr 'n' ' '; (df -k . | tail -1)) | gawk ' { printf("%0.0f%n",($1/$4)*100); } '
37%
[[email protected] usr]# cd java
[[email protected] java]# (du -ks . | tr 'n' ' '; (df -k . | tail -1)) | gawk ' { printf("%0.0f%n",($1/$4)*100); } '
4%
[[email protected] usr]# cd ../X11R6
[[email protected] X11R6]# (du -ks . | tr 'n' ' '; (df -k . | tail -1)) | gawk ' { printf("%0.0f%n",($1/$4)*100); } '
2%
[[email protected] X11R6]# cd ../lib
[[email protected] lib]# (du -ks . | tr 'n' ' '; (df -k . | tail -1)) | gawk ' { printf("%0.0f%n",($1/$4)*100); } '
15%
[[email protected] local]# cd ../share
[[email protected] share]# (du -ks . | tr 'n' ' '; (df -k . | tail -1)) | gawk ' { printf("%0.0f%n",($1/$4)*100); } '
13%
Reference
[tags]UNIX, Admin, Unix Coding School[/tags]