Tuesday, February 28, 2012

Bash command that save my ass over and over again

The following linux commands are really no brainer stuff that every elementary course would have taught us, and it saved my butt many times over and over again.

   find . -iname <some file name>
To find files recursively

   find . -iname <some file name> | xargs
To find files recursively and list them out horizontally separated by space and doing escaping when necessary

  find . -iname <some file name> | xargs <some other bash commands>
To find files recursively and list them out as arguments such that we could perform other commands on it like rm -f (force delete) for example

  grep -ir 'some text' .
Find all files recursively starting with the current directory

We could do interesting stuff like

  find . -iname '*.xml' | xargs grep -i "testing"
Find all xml files recursively starting with current directory that has text 'testing' contains in it.

Bash commands ROCKS! It's always worthwhile if you are using a windows machine to install Cygwin, it comes with bash by default so you could dig up code segment quickly rather than relying on the pathetic doggy search that comes with Windows. Just me 2 cents !