find DIRECTORY EXPRESSION
As an example, here is the command that looks for a file with "captcha" somewhere in the name and the file name ends in "html".
find ./ -name '*captcha*html'
./math-captcha.html
You can also search using some basic regexp functionality. It uses bash's Shell Pattern Matching, which is
match any 0 or more characters.
matches any 1 character
This is a character class. It matches one character in the string. [aA]
will match both "a" and "A". [a-zA-Z]
matches all letters. If the character class starts with the "!" in "^" it will match 1 character that is not in the string. So [^0-9]
will find any non-numbers.
find ~/programming/html/ -name '*[gG][nN][uU]*'
/home/joshua/programming/html/assign-copyright-to-GNU /home/joshua/programming/html/my-wordpress-blog/images/GNUGuileLogo.png /home/joshua/programming/html/GNUSites /home/joshua/programming/html/my-portfolio-site/images/gnu.png
The above command was a bit cumbersome to write. Luckily, find lets you search case insensitively.
find ~/programming/html/ -iname '*gnu*'
/home/joshua/programming/html/assign-copyright-to-GNU /home/joshua/programming/html/my-wordpress-blog/images/GNUGuileLogo.png /home/joshua/programming/html/GNUSites /home/joshua/programming/html/my-portfolio-site/images/gnu.png
Find also lets you combine options together.
find ~/programming/html/ -iname '*gnu*' -path '*images*'
/home/joshua/programming/html/my-wordpress-blog/images/GNUGuileLogo.png /home/joshua/programming/html/my-portfolio-site/images/gnu.png
find ~/manuals/ -regex '.*manuals.*yas.*org'
/home/joshua/manuals/cheatsheets/yasnippet.org
You can also have find print like ls -l
does.
find . -name '*arch.org' -ls
8260652 60 -rw-r--r-- 1 joshua home 57385 Sep 20 12:01 ./arch.org
Find also supports running commands on the files that are found. For example here I am looking for a particular manual with the word keyboard in it.
find ~/manuals -name '*arch*' -execdir grep 'keyboard' '{}' ';'
* Change the virtual console keyboard layout * Configuring Xorg Settings (keyboard layout) ** change the X keyboard layout & swap caps Identifier "libinput keyboard catchall" * Change the virtual console keyboard layout * Configuring Xorg Settings (keyboard layout) ** change the X keyboard layout & swap caps Identifier "libinput keyboard catchall"