Search Files Recursively Using Wildcard Ubuntu 2004
This simple tutorial will show you how to find/search files in Ubuntu 20.04 using command find.
We will show you how to search a specific file name ,also introduce how to search/find files recursively using wildcard match.
Search files recursively using wildcard
find /path-to-search -name "file*"
For example:
root@ubuntu2004:~# find /etc -name "file*"
/etc/apache2/mods-available/file_cache.load
root@ubuntu2004:~#
Where:
/etc
is the directory path where to search. For current directory.
(dot) could be used-name
is an optionfile*
will search all files and directories whose name started withfile
- Note
double quotes
is required
If you are not using root , you may get some permission denied
error ,to suppress it you can use command:
find /path-to-search -name "file*" 2>/dev/null
search files case-insensitive
find /path-to-search -iname "file*"
Here -iname
Like -name, but the match is case insensitive. For example, the patterns fo*' and
F??’ match the file names Foo',
FOO’, foo',
fOo’, etc. The pattern *foo*
will also match a file called ‘.foo‐bar’
j@ubuntu2004:/tmp/dir1$ ls
foo FOO
j@ubuntu2004:/tmp/dir1$ find . -name "FO*"
./FOO
j@ubuntu2004:/tmp/dir1$ find . -iname "FO*"
./FOO
./foo
Follow symbolic link
find -L /path-to-search -name "file*"
By default find doesn’t follow symbolic link , as you know symbolic link is often used in linux ,so option -L
need to be used if we want to follow symbolic link.
Search file only but not directory
find . -type f -name 'file*'
where:
.
(dot) means search in current directory-type f
stands search file only(but not directory)
Conclusion
We have showed you how to search files recursively based on wildcard match using find command in ubuntu 20.04.
More find command examples can be found Linux find command examples