grep -R Alternative

Ugh…

I have worked with unix/linux now going on my twelfth year.  However, I am still pretty green with AIX as I have only dabbled in it for about two years now.

Although I have grown to enjoy their implementation of logical partitions and other value adds, I have always felt that their OS is old and stuffy.  I was reminded of this recently when I could not perform a recursive grep.  There are a lot of archaic command line switches in this stodgy old OS, not to mention all of the new and cool commands that are missing.

If you find yourself needing to do a grep -R in AIX or in any other *nix OS, here is an alternative command for you using find:

find . -type f | xargs grep -i <string>

For example, if you wanted to find any file that contains the word “voova” in your current working directory and all of the child directories, you would issue:

find . -type f | xargs grep -i voova
  • find . -type f tells the command to locate all files
  • xargs allows for you to execute whatever command follows (in this case it is grep) on each individual file that the find command locates as if you grep’d each file one at a time
  • grep searches for the string where the -i makes the search case insensitive.

Hopefully, this will save you the exercise of RTFM’s

-boogybren

Tags: , , ,

Leave a Reply