How to find a file in linux
Finding by Name
The most obvious way of searching for files is by name.
To find a file by name, type:
find -name "query"
This will be case sensitive, meaning a search for "file" is different than a search for "File".
To find a file by name, but ignore the case of the query, type:
find -iname "query"
If you want to find all files that don't adhere to a specific pattern, you can invert the search with "-not" or "!". If you use "!", you must escape the character so that bash does not try to interpret it before find can act:
find -not -name "query_to_avoid"
Or
find \! -name "query_to_avoid"
Finding by Type
You can specify the type of files you want to find with the "-type" parameter. It works like this:
find -type type_descriptor query
Some of the most common descriptors that you can use to specify the type of file are here:
-
f: regular file
-
d: directory
-
l: symbolic link
-
c: character devices
-
b: block devices
For instance, if we wanted to find all of the character devices on our system, we could issue this command:
find / -type c
/dev/parport0
/dev/snd/seq
/dev/snd/timer
/dev/autofs
/dev/cpu/microcode
/dev/vcsa7
/dev/vcs7
/dev/vcsa6
/dev/vcs6
/dev/vcsa5
...