Linux provides different tools to find files for different attributes. We can find files according to their size, name, modification time location, etc. But one of the most used metrics is finding file according to its name. In this tutorial, we will look at different tools to find files by name in Linux.
Find Files with find Command
find is the most feature-full tool to find files according to its name.
find provides a lot more features which can be examined in the following tutorial.
Linux Find Command With Examples
We will use
-name option which is used to specify the file name we search. In this example we will look file named
db.conf in this example.
$ find . -name db.conf
Find Files As Caseinsensitive
In previous example we have searched in a case sensitive manner. Case sensitive will only list same case names. For example if we search for
db.conf it will only match
db.conf contained name but will not match
DB.conf or similar. We disable case sensitivity and match
DB.conf too with the
-iname as we ca see just prefixing with
i . In this example we will search caseinsenstive.
$ find . -iname db.conf
Find Files For Specific Location
We can also specify the location we can search. In previous example we have already specified the location by using dot which means the current working path. We can put other path. In this example, we will search in
$ find /home/ismail -name db.conf
Find Files Using locate Command
Locate is a very fast and useful tool. locate will search its database and try to match the given term. locate will match the all name and path for the given term we can only look for the name with
-b option. This will only match file or folder name not the whole path. In this example we will search for
$ locate -b db.conf
Find Files Using ls and less Commands
There is also a bit different and interesting way to search for files. ls command is used to list files and directories. We can also use ls recursively where we can list sub files and directories too. We will redirect the ls output to the less command. Then we will use
less search function which is run with
/ to search in the output.
$ ls -R /home/ismail | less
db.conf with the following command in the less screen.