Saturday, February 5, 2011
finding disk usage using 'grep' and 'du'
Jai Srila Prabhupada.
Today I was trying to find how much disk storage space was being used by files on my system. I used the following command to find disk storage space used:
du -hc / > usage_details.txt
Now I needed to analyze the information captured in the text file that got created in the above step. During my analysis, I did find that knowing the disk usage for a particular folder was easy, as the 'du' tool captures the disk usage folder-wise when used with the -c option as shown above. But, now I wanted to find the disk usage only for the top level folders i.e. /home, /tmp, /var, /usr etc. I resorted to using the 'grep' command in the following way:
grep -v "\/.*\/.*" usage_details.txt
The text within quotes is a back-slash, forward-slash, period, asterix and again the same set of characters. Here 'grep' is called with the -v option which means negation of the match condition - if the text read by 'grep' doesn't match the pattern, then print it to the standard output. That was a pretty nifty feature, eh!
Jai Sathguru Bhagavan Sridhara swamy maharaj.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment