I want to search for all files with the .sql extension in folders and sub-folders (recursive).
How can I do this?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
find $directory_name -name \*.sql
find / -name \*.sql
find ~ \*.sql
(where ~ equates to /home/your_username/), or...
find /usr/local/share/ \*.sql
and so forth.
Run this in the command line:
cd / && find | grep '\.sql$'
Change '/' to the directory you want to search.
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:
| grep '\.sql$')
findhas already filter capabilities
I know that this is an old post, but i am pretty new at this and i've found an easy way to find all files of a certain extension in a directory and its children subdirectories.
Well you first navigate to the
parent Directory then
find . -name '*.sql' and that will find you all files with .sql extension in the directories and its subdirectories.
In my case i wanted to delete all .xml files in the directory and its subdirectories, so what i did more is that i added remove as in here
find . -name '*.xml' | xargs rm
Hope this help someone :)
-deletecommand. No need to involve
rm. Or you can use the
-execcommand to invoke it directly without the detour through a pipe and
xargs. Feb 23, 2018 at 14:41
locate -br \\.sql$ | egrep '^/folder/path/'
If it is not installed, then previously install it with:
sudo apt install mlocate
mlocate.dbinstance which is not set up out-of-the box in Ubuntu (I blieve). Also, why not simply
locate '/folder/path/*.sql'? Feb 23, 2018 at 11:45
locatehas some different setting from regex used in
locatematches glob expressions like
/folder/path/*.sql, not regular expressions. Feb 23, 2018 at 14:37
man locateI get
-r, --regexp REGEXP - Search for a basic regexp REGEXPso I assumed it was a regex. Anyway I tried your "global expression" but doesn't work, I'm sorry
--regexis not specified,
PATTERNs can contain globbing characters.” (source) Feb 24, 2018 at 1:21