LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2015, 03:33 PM   #1
tearsforhari
Member
 
Registered: Mar 2015
Posts: 79

Rep: Reputation: Disabled
How to search all sub-directories for a file or command line in a file in Ubuntu?


Hello--

I'm trying to locate a file or a command line in a file on my hard drive. I am running Ubuntu 12.05.4 linux. Is there a grep command that will search the whole tree from root down to all the sub-directories?

Thank You.
 
Old 05-11-2015, 03:40 PM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
grep searches the contents of files, it doesn't search for files.

Code:
$ locate name_of_file
Pros: Fast:
Cons: Relies upon a database which is updated daily.

Code:
$ find / -type f -name name_of_file
Pros: Doesn't rely upon a database
Cons: The more files you have the slower it probably is.
Assuming you have some idea where the file is replace / with something else

Code:
$ man find
 
Old 05-11-2015, 03:48 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
If you want to search for a specific line inside a file, you can use grep
Code:
grep -r line /
It would be best if you could narrow down where the file would be though, otherwise this is going to take a VERY long time.
 
Old 05-11-2015, 04:25 PM   #4
tearsforhari
Member
 
Registered: Mar 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thank you!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Search directories recursively and delete a file with a certain name maples Linux - Newbie 3 05-22-2014 06:03 PM
[SOLVED] Command line search in file for < date jdgr Linux - General 6 04-11-2013 08:35 AM
How to scan to file from the command line using Ubuntu Server LTS 10.04? Syllinger Linux - Hardware 1 12-24-2011 06:43 PM
Ubuntu 8.10 and want to download 2 GB file in command line. chandan766 Linux - Newbie 12 04-06-2009 09:37 AM
How to search all directories for a file in bash overlook1977 Linux - Newbie 7 04-10-2007 07:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration