Solved

Linux:  How to find string in a file within subdirectories

Posted on 2014-11-14
4
235 Views
Last Modified: 2014-11-14
What command do I use to find a string within a file that is possibly contained within a subdirectory

The string I want to find is 8585

Thanks
0
Comment
Question by:Anthony Lucia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40442693
To search the current directory and all directories below it for files containing "8585":

grep -R "8585" .

Note the dot "." as the last parameter! It means: "start at the current directory".
"-R" means: recursive search.

If the directory where you want to start your search is not your current directory either "cd" to it first:

cd /path/to/start_dir

or replace the dot with the name of this directory:

grep -R "8585" /path/to/start_dir
0
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 40442699
grep is your friend...

grep - r "8585"

more on grep
0
 
LVL 25

Expert Comment

by:madunix
ID: 40442717
find ./ -type f -exec sed -i -e 's/old/new/g' {} \;
it goes  through sub directories.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40442732
@madunix: Anthony Lucia asked for a way to find the string, not to find and replace it with some other string.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
UM7 Stop Sending packets with GPS Sensor 1 42
How to check if the Cron job is running or not ? 12 78
Issue when using 'yum update' 4 22
Linux 6 32
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question