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*"
root@ubuntu2004:~# find /etc -name "file*" /etc/apache2/mods-available/file_cache.load root@ubuntu2004:~#
/etcis the directory path where to search. For current directory
.(dot) could be used
-nameis an option
file*will search all files and directories whose name started with
double quotesis 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*"
-iname Like -name, but the match is case insensitive. For example, the patterns
fo*' and F??’ match the file names
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*'
.(dot) means search in current directory
-type fstands search file only(but not directory)
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