find + xargs + spaces in the filename

July 10th 2007 12:15 pm

So today I had to use find + xargs + grep to search for some things in cygwin, since Windows search is like a hunting dog with no sense of smell. Being Windows, there are spaces in file paths left, right, and center. xargs and grep don’t play overly nice with this.

Originally I had:

find . -name *.js | xargs grep Saving

Which didn’t work. grep was looking for weird things which did not exist. Then I found this link with Google,

find + xargs: how do I handle space in the path – comp.unix.shell | Google Groups

which provided a solution:

find . -name *.js -print0 | xargs -0 grep Saving

A friend pointed out that if there are any JavaScript files in the current directory, .js will get expanded by bash and not work too well. Final solution:

find . -name "</strong>.js" -print0 | xargs -0 grep --color=always Saving

About the author... Daniel Huckstep is a software engineer(ing student) at the University of Alberta. He enjoys all aspects of computers and their software, reptiles, guitar and music creation, reading, and macaroni salad.


Posted by darkhelmet under Linux & Programming & Windows |

Trackback URI | Comments RSS

Leave a Reply

My wishlist

 Subscribe in a reader
  • Categories

  • Tags

  • Monthly

  • Pages

  • Blogroll

  • Last.fm

  • Einstein@home

  • Word of the Day