Small blog about system administration.

Bash tips & tricks

I know that bash is not really a scripting language but there are times when you just want to do things on a single command line.

So, if you want for example drop some databases from a folder list:

ls /var/lib/mysql | grep dbmatch* | while read i; do echo “drop database $i”; done | mysql


Or, if you want to change same content on multiple files:

cd folder ; grep “oldvalue” * -l | while read f; do cat $f | sed s/oldvalue/newvalue/ > /tmp/x; cat /tmp/x > $f; done

No comments :

Post a Comment