How To Find File By Name In Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/find-file-name-linux/
PINTEREST
PINTEREST
INSTAGRAM

Linux provides different tools to find file for different attributes. We can find files according to their size, name, modification time location etc. But one of the most used metric is finding file according to its name. In this tutorial we will look different tools to find files by name in Linux.

Using find

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.

Using find
Using find

Using find Caseinsenstive

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.

Using find Caseinsenstive
Using find Caseinsenstive

Specifying Location

We can also specify the location we can to search. In previous example we have all ready specified the location by using .  which means current working path. We can put other path. In this example we will search in /home/ismail

Specifying Location
Specifying Location

Using locate

Locate is very fast and useful tool. locate will search its database and try to match given term. locate will match the all name and path for 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 db.conf .

LEARN MORE  Python String Find Tutorial with Examples

Using locate
Using locate

Using ls and less

There is also a bit different and interesting way to search 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. Than we will use less search function which is run with / to search in the output.

then search db.conf with the following command in the less screen.

Using ls and less
Using ls and less

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/find-file-name-linux/
PINTEREST
PINTEREST
INSTAGRAM