Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to search for all files with the .sql extension in folders and sub-folders (recursive).

How can I do this?

share|improve this question
add comment

2 Answers

Run this in the command line:

cd / && find | grep '\.sql$'

Change '/' to the directory you want to search.

The find command is able to accomplish the task without grep (using extra options), but I find the above usage more convenient.

In order, the above command:

  1. Changes the current directory to the root directory (cd /)
  2. Lists all files and directories at and below the current directory (find)
  3. Filters the files and directories for anything that ends with '.sql' (| grep '\.sql$')
share|improve this answer
    
thanks, can you explain it? your using grep and passing its output to find? –  Blankman Dec 11 '11 at 1:50
    
Vice versa, actually. I'm using find and passing its output to grep. I added a more detailed explanation above. –  Barbarrosa Dec 11 '11 at 2:00
    
would this work on a Mac also? I tried 'find | grep '\.sql$' and it outputted the usage help info. –  Blankman Dec 11 '11 at 3:14
    
find is a powerful tool and you really do not need to pipe the output to grep. This is a nice link - content.hccfl.edu/pollock/unix/findcmd.htm –  bodhi.zazen Dec 11 '11 at 3:52
    
find has already filter capabilities –  enzotib Dec 11 '11 at 12:04
add comment

Or...

find $directory_name -name \*.sql

For example

find / -name \*.sql

Or

find ~ \*.sql

(where ~ equates to /home/your_username/), or...

find /usr/local/share/ \*.sql

and so forth.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.