How To Find a File in Linux

0

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 How To Find a File in Linux How To Find a File in Linux 1713853806 528 How To Find a File in Linux

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

find-command-in-linux How To Find a File in Linux How To Find a File in Linux 1713853806 584 How To Find a File in Linuxfind-command-in-linux How To Find a File in Linux How To Find a File in Linux 1713853806 584 How To Find a File 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:

iname-option-in-find-command How To Find a File in Linux How To Find a File in Linux 1713853806 257 How To Find a File in Linuxiname-option-in-find-command How To Find a File in Linux How To Find a File in Linux 1713853806 257 How To Find a File in Linux

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 How To Find a File in Linux How To Find a File in Linux 1713853806 711 How To Find a File in Linuxf-and-iname-options-in-find-command-to-find-a-file How To Find a File in Linux How To Find a File in Linux 1713853806 711 How To Find a File in Linux

For directories:

find -type d -iname password.txt

f-and-iname-options-to-find-directory-using-find-command How To Find a File in Linux How To Find a File in Linux 1713853807 594 How To Find a File in Linuxf-and-iname-options-to-find-directory-using-find-command How To Find a File in Linux How To Find a File in Linux 1713853807 594 How To Find a File in Linux

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 How To Find a File in Linux How To Find a File in Linux 1713853807 506 How To Find a File in Linuxapt-command-to-install-locate-command How To Find a File in Linux How To Find a File in Linux 1713853807 506 How To Find a File in Linux

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

locate-command-to-find-a-file How To Find a File in Linux How To Find a File in Linux 1713853807 39 How To Find a File in Linuxlocate-command-to-find-a-file How To Find a File in Linux How To Find a File in Linux 1713853807 39 How To Find a File in Linux

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

i-option-in-locate-command How To Find a File in Linux How To Find a File in Linux 1713853807 909 How To Find a File in Linuxi-option-in-locate-command How To Find a File in Linux How To Find a File in Linux 1713853807 909 How To Find a File in Linux

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 How To Find a File in Linux How To Find a File in Linux 1713853808 949 How To Find a File in Linuxfinding-a-file-in-file-manager How To Find a File in Linux How To Find a File in Linux 1713853808 949 How To Find a File in Linux

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

finding-a-file-in-file-manager-using-search-bar How To Find a File in Linux How To Find a File in Linux 1713853808 89 How To Find a File in Linuxfinding-a-file-in-file-manager-using-search-bar How To Find a File in Linux How To Find a File in Linux 1713853808 89 How To Find a File in Linux

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.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More