LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to search all sub-directories for a file or command line in a file in Ubuntu? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-search-all-sub-directories-for-a-file-or-command-line-in-a-file-in-ubuntu-4175542300/)

tearsforhari 05-11-2015 03:33 PM

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.

arizonagroovejet 05-11-2015 03:40 PM

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

suicidaleggroll 05-11-2015 03:48 PM

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.

tearsforhari 05-11-2015 04:25 PM

Thank you!!


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