Searching for Files in Ubuntu: A Comprehensive Guide

Find Files in Ubuntu

Are you tired of not being able to find files on your computer? Don’t worry, we’ve got you covered! In this article, we’ll show you how to use the command line in Ubuntu to find your files. Whether you’re managing servers or accessing your system through SSH, these methods will help you locate your files quickly and efficiently.

Method 1: Using the Find Command

Search for files using find command

The Find command is extremely versatile and allows you to search for files based on various conditions. You can search by file or folder name, creation date, modification date, and permissions. Plus, you can combine multiple conditions in a single Find command. Although it may be slower than other methods, it offers a wide range of search options.

To search for all files in a specific directory, simply use the following command in the Terminal:

$ find /path/to/file/

For example, if you want to find all files under the /home/tin/Downloads/ directory, type:

$ find /home/tin/Downloads/

You can also search for files in the current directory by using the command:

$ find .

To search for a specific file named “softwares” in the current directory, use the following command:

$ find . -iname Softwares

Don’t forget about using wildcards! If you want to search for files that start with the word “cent,” enter this command:

$ find /home/tin/ -iname cent*

Looking for empty files? No problem! Simply run this command to find them:

$ find /path/to/file/ -iname -empty

For instance, to find empty files under the /home/tin directory, type:

$ find /home/tin/ -empty

You can even search for files based on their date and time attributes. Use the Find command to search for files that were modified or accessed within a specific timeframe. For example, to find files that were modified less than 2 days ago, run this command:

$ find . -mtime -2

To search for files that were accessed less than 2 days ago, use this command:

$ find . -atime -2

And if you want to search for files that were changed less than 2 days ago, simply enter:

$ find . -ctime -2

Need to search for files based on their size? Use this command to find files larger than 5MB:

$ find . -size +5M

Looking for files with specific permissions? The Find command can do that too! Just use this format to search for files with a permission of 644:

$ find . -type f -perm 644

Method 2: Using the Locate Command

The Locate command allows you to search for files in Linux. While it doesn’t offer as many search conditions as the Find utility, it’s significantly faster. The reason for this is that Locate has its own database, which it regularly updates in the background to keep track of new files.

Before using the Locate command, you’ll need to install it. Open the Terminal and enter this command:

$ sudo apt-get install locate

After the installation is complete, you can start using the Locate utility right away. To search for a file, use this command:

$ locate -i filename

The -i option is used to ignore case distinctions.

For example, if you’re looking for a file named “centos,” use this command:

$ locate -i centos

You can even search for multiple files simultaneously. Simply enter this command in the Terminal:

$ locate -i sdn.txt centos

And if you want to search for files that end with the “.iso” extension, use this command:

$ locate -i *.iso

Remember to regularly update the Locate database, as it relies on this data to function effectively. To update the database, run this command in the Terminal:

$ sudo updatedb

Method 3: Using the Grep Command

While the Grep command is primarily used for text search, it can also help you find files that contain specific strings. Although it doesn’t directly search for files on your system, it displays the names of files that match your search query.

The basic syntax of the command is as follows:

$ grep [options] [pattern] [/path/to/file]

The [options] parameter allows you to control the search, while the [pattern] parameter contains the string you want to search for.

For example, if you want to find a file that contains the word “tintin” in your Downloads folder, use this command:

$ grep -r -i "tintin" /home/tin/Downloads

In this command, the -i option is used to ignore case distinctions, while the -r option searches the specified directory recursively.

You can also search for multiple strings at once by separating them with backslashes () and pipe signs (|). For example, to search for both “tintin” and “ping,” use this command:

$ grep -r -I "tintin|ping" /home/tin/Downloads

That’s it! You now have three powerful command-line methods for searching for files in Ubuntu. Choose the method that best suits your needs and start finding your files with ease.