Linux Commands

How To Find a File in Linux

Linux is a famous OS due to its features, like its robust file management system. It lets you perform various operations such as creating, editing, moving, and renaming those files. However, these features pose no advantage if you cannot locate your desired files.

This is quite a common issue, and many users often forget a file’s location. So, this quick tutorial has all the easy methods to find a file in Linux with no hassles. In this section, we have included multiple commands such as find and locate. So let’s take a look at them one by one:

The Find Command

The find powerful command to search files based on various criteria. For example, let’s search for the Password.txt file located in the Documents directory: 

cd ~/Documents
find Password.txt

cd-command-to-open-documents-directory

In case you don’t know the directory of the file, then you can run the below command: 

find -name Password.txt

find-command-in-linux

The above command produces accurate results only if you enter the file name in proper cases. Otherwise, you can run a case-insensitive search by using the -i option:

find -iname password.txt

iname-option-in-find-command

Moreover, you can guide the system to search only for files or only for directories by using the -f or -d options, respectively.

For files:

find -type f -iname password.txt

f-and-iname-options-in-find-command-to-find-a-file

For directories:

find -type d -iname password.txt

f-and-iname-options-to-find-directory-using-find-command

The locate Command

The locate is more efficient than find as it scans your system periodically and indexes it in advance. So, whenever you use the locate command, it quickly refers to the index and returns the file location. Locate is not a pre-installed command, so please run the below command to install it: 

sudo apt install mlocate -y

apt-command-to-install-locate-command

Now, let’s find the Password.txt using the locate command:

locate Password.txt

locate-command-to-find-a-file

Similarly, you can use the -i option to make the command case insensitive: 

locate -i password.txt

i-option-in-locate-command

The File Manager

If you are a Linux beginner, we recommend you to use the File Manager to find a file. For example let’s find the Password.txt file so please open the File Manager. Here, either you can press CTRL + F or click on the search icon to open the search bar:

finding-a-file-in-file-manager

Now, you can search for the Password.txt in the search bar: 

finding-a-file-in-file-manager-using-search-bar

A Quick Wrap-up

It sometimes becomes difficult for Linux users to find a specific file due to the complex file storage. Hence, we have explained three simple methods for finding a file with no hassles. First, one explains the find and locate commands and their functionality. Lastly, we have included the easiest method for Linux beginners to find files right from the File Manager.

About the author

Prateek Jangid