LinuxQuestions.org
Register a domain and help support LQ
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, 04: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, 04:40 PM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,078

Rep: Reputation: 195Reputation: 195
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, 04:48 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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, 05:25 PM   #4
tearsforhari
Member
 
Registered: Mar 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thank you!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:03 PM
[SOLVED] Command line search in file for < date jdgr Linux - General 6 04-11-2013 09:35 AM
How to scan to file from the command line using Ubuntu Server LTS 10.04? Syllinger Linux - Hardware 1 12-24-2011 07:43 PM
Ubuntu 8.10 and want to download 2 GB file in command line. chandan766 Linux - Newbie 12 04-06-2009 10:37 AM
How to search all directories for a file in bash overlook1977 Linux - Newbie 7 04-10-2007 08:00 AM


All times are GMT -5. The time now is 08:33 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration