Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 05-11-2015, 04:33 PM   #1
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?


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
Senior Member
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,093

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

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

$ 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

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

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116
If you want to search for a specific line inside a file, you can use grep
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
Registered: Mar 2015
Posts: 79

Original Poster
Rep: Reputation: Disabled
Thank you!!


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:14 AM.

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