Solved

Linux:  How to find string in a file within subdirectories

Posted on 2014-11-14
4
233 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

777 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