Solved

Linux:  How to find string in a file within subdirectories

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now