File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes Seraching for files in directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Seraching for files in directory" Watch "Seraching for files in directory" New topic

Seraching for files in directory

Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
How do I serach for all the files contaning ,
in a particular directory?
I tried
grep -l name="vvvvv" *
but seems like due to " this is not giving correct output.
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012
use: find /path filename

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

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" *

An IDE is no substitute for an Intelligent Developer.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

I think he wants files that contain the exact string
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.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Seraching for files in directory
It's not a secret anymore!