Wednesday, January 13, 2016

More day to day one liners


List directories and sort them by largest:


du -hcx –max-depth=5 | grep [0-9]G | sort -rnk1,1

This goes to a depth of 5 directories and sorts largest, only if they are in gigs, and takes into account decimals.

If you need more drive space, you can reduce your reserve space, but you probably don't want to reduce that space to 0 their is a chance your system could grind to a halt. To reduce reserve space to 2 percent:

sudo tune2fs -m 2 /dev/sda1

Now if you need to check what your reserve space is currently set at:

sudo dumpe2fs -h /dev/sda1 2> /dev/null | awk -F ':' '{ if($1 == "Reserved block count") { rescnt=$2 } } { if($1 == "Block count") { blkcnt=$2 } } END { print "Reserved blocks: "(rescnt/blkcnt)*100"%" }'

I didn't write that one, I first encountered it at a hosting gig, but I had to look it up and found it at commandlinefu.

Parsing an html table using perl:

perl -pe "s/.*<tr><th><b>(.*): <\/b><\/th><th.*<\/th><td>(.*)<\/td><\/tr>/\"\1\":\"\2\"/gi"

I'm not going to explain this one, because I wrote it a long time ago and it's perl regex so I would essentially have to rewrite it to understand it.


I have another list of one liners, particularly related to hosting.

No comments: