Home How can I recursively find all files in current and subfolders based on wildcard matching?
Reply: 11

How can I recursively find all files in current and subfolders based on wildcard matching?

john
1#
john Published in 2011-05-05 23:01:34Z

How can I recursively find all files in current and subfolders based on wildcard matching?

Iridann
2#
Iridann Reply to 2016-07-13 15:45:12Z

Use find for that:

find . -name "foo*"

find needs a starting point, and the . (dot) points to the current directory.

the Tin Man
3#
the Tin Man Reply to 2014-10-16 16:58:21Z

find will find all files that match a pattern:

find . -name "*foo"

However, if you want a picture:

tree -P "*foo"

Hope this helps!

Andy Lester
4#
Andy Lester Reply to 2014-02-03 22:56:42Z

Piping find into grep is often more convenient; it gives you the full power of regular expressions for arbitrary wildcard matching.

For example, to find all files with case insensitive string "foo" in the filename:

~$ find . -print | grep -i foo
kenorb
5#
kenorb Reply to 2017-11-30 13:01:41Z

If you shell supports a new globbing option (enable it by: shopt -s globstar), you can use:

echo **/*foo*

to find any files or folders recursively. This is supported by Bash 4, zsh and similar shells.

toddcscar
6#
toddcscar Reply to 2017-01-14 02:47:53Z
find -L . -name "foo*"

In a few cases, I have needed the -L parameter to handle symbolic directory links. By default symbolic links are ignored. In those cases it was quite confusing as I would change directory to a sub-directory and see the file matching the pattern but find would not return the filename. Using -L solves that issue. The symbolic link options for find are -P -L -H

P_Jain
7#
P_Jain Reply to 2017-02-05 13:32:47Z
find <directory_path>  -type f -name "<wildcard-match>"

In the wildcard-match you can provide the string you wish to match e.g. *.c (for all c files)

Alberto
8#
Alberto Reply to 2017-05-31 08:47:01Z

for file search
find / -xdev -name settings.xml --> whole computer
find ./ -xdev -name settings.xml --> current directory & its sub directory

for files with extension type

find . -type f -name "*.iso"
Aleksandar Pavić
9#
Aleksandar Pavić Reply to 2017-08-09 06:45:11Z

Default way to search for recursive file, and available in most cases is

find . -name "filepattern"

It starts recursive traversing for filename or pattern from within current directory where you are positioned. With find command, you can use wildcards, and various switches, to see full list of options, type

man find

or if man pages aren't available at your system

find --help

However, there are more modern and faster tools then find, which are traversing your whole filesystem and indexing your files, one such common tool is locate or slocate/mlocate, you should check manual of your OS on how to install it, and once it's installed it needs to initiate database, if install script don't do it for you, it can be done manually by typing

sudo updatedb

And, to use it to look for some particular file type

locate filename

Or, to look for filename or patter from within current directory, you can type:

 pwd | xargs -n 1 -I {} locate "filepattern"

It will look through its database of files and quickly print out path names that match pattern that you have typed. To see full list of locate's options, type: locate --help or man locate

Additionally you can configure locate to update it's database on scheduled times via cron job, so sample cron which updates db at 1AM would look like:

0 1 * * * updatedb

These cron jobs need to be configured by root, since updatedb needs root privilege to traverse whole filesystem.

Benjamin W.
10#
Benjamin W. Reply to 2017-12-24 07:39:29Z

You can use:

# find . -type f  -name 'text_for_search'

If you want use REGX use -iname

# find . -type f  -iname 'text_for_search'
Aakash Wadhwa
11#
Aakash Wadhwa Reply to 2017-12-24 07:29:52Z
$ find . -type f -name “pattern-to-search”

This will print all files with pattern recursively from current directory to sub folders

Reza Harasani
12#
Reza Harasani Reply to 2018-02-05 02:52:19Z

If you want to search special file with wildcard, you can used following code:

find . -type f -name "*.conf"

Suppose, you want to search every .conf files from here:

. means search started from here (current place)
-type means type of search item that here is file (f).
-name means you want to search files with *.conf names.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303127 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO