Solved

Linux:  How to find string in a file within subdirectories

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Guacamole and browser performance 1 63
My bash alias isn't executing 5 47
What language/protocol is the Angular Chat? 2 57
wipe a usb using python 5 26
Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

910 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

22 Experts available now in Live!

Get 1:1 Help Now