• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Seraching for files in directory

 
Gemini Moses
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I serach for all the files contaning ,
name="vvvvv"
in a particular directory?
I tried
grep -l name="vvvvv" *
but seems like due to " this is not giving correct output.
Thanks!
 
Greg Harris
Ranch Hand
Posts: 1012
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use: find /path filename
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's a bit of a split in meaning there. That can be read as either "In a directory, filenames containing "vvvvv'", or it can be read as "files in a directory containing the value "vvvvv".
One way to match simple patterns is via globbing:
ls **vvvvv**
Will show all files where "vvvvv" is anywhere in the filename. For more complex patterns, pipe the output of the "find" command into grep:
find . | grep "vvvvv"
To find occurrances of "vvvvv" IN files in a directory, just use grep:
grep "vvvvv" *
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think he wants files that contain the exact string
name="vvvvv"
quotes and all. The easiest way to do this would be to use single quotes to
surround the grep pattern:
grep 'name="vvvvv"' *
Single quotes prevent the shell from doing anything with the double quotes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic