David Wyde

Unix Tricks

Here are a few Unix command line tricks that I’ve learned recently.

... | vim -

Edit search results by piping text into vim - instead of less.

grep file.log | less

grep file.log | vim -

tr -s ' '

Squeeze consecutive spaces into a single space. Also works for other characters.

ps aux | tr -s ' ' | cut -f1,2,3 -d' '

grep -B/-A

Display lines before (-B) and after (-A) a matching line.

I find these flags confusing, since they could be “Above” and “Below”.

grep -A3 '<Directory' /etc/apache2/apache2.conf