Computer

Find any document, folder or file in Linux

via terminal

Finding documents that include certain words and are located in the Softzone directory using the Linux command line is as simple as using the following command:

grep -iRl palabras-que-buscamos /home/softzone

  • Parameter -Yo will search for the text regardless of whether it is uppercase or lowercase text.
  • with the modifier Ra search will be performed in all subdirectories of the location that we set at the end of the line.
  • The variable he will replace the document text that matches the search with the file name, which is what we’re really looking for.

We must replace the final location, in this case /softzone with the location where we want to search for the files.

With the graphical interface

When using the Linux graphical interface to search for part of a text found in a document, the first thing we must do is access the drive where the file is located.

If we only have one unit, we must click on the Files application. Next, click on the magnifying glass located at the top and then on the down arrow that is shown on the left.

Find text in Linux

Click on What and select the type of document we want to search for, which, in this case, would be Documents (the full text option must be selected).

Finally, we enter the text of the file we want to find and wait for the results to be displayed, results that will include the location of the document.

Find the folders you are looking for

All Linux distributions allow us to do folder searches both through the terminal command line and using the graphical interface.

With the command line

Linux, through the find command, allows us to filter the type of results it shows depending on the type of file it is. The results of the find command show both files and folders.

If we want to reduce the number of results to only folders, we must add the variable -type d

find / -type d -iname nombre-del-archivo

From GUI

In the taskbar, we must select the drive where the folder we want to search is located. If we only have one partition in the system, we can search directly from the Files application.

From the Files app window, click on the magnifying glass located at the top and enter the words that are included in the name of the folder.

Find Linux files

Unlike carrying out this process using commands, the interface does not allow us to filter the type of content that will be displayed, so the resulting list will show as many files as there are folders.

Folders are represented by a folder while files show the icon of the application they are associated with, if any.

Locate the file you need

The search for files through the terminal in Linux puts at our disposal a large number of tools and variables to filter the content as much as possible, eliminating other possible matches.

From terminal with find

If we search for files in Linux, we have two tools: find Y locate. While the first is available natively, the second must be installed, although the command syntax is simpler.

with find

In order to find a file by its name, it is necessary that the name includes words that help us find it. If you usually save documents as Document1, Document 2… it will be useless to use either the command line or the graphical interface to find the files you are looking for.

The command that we are going to use to search for files from terminal is find. Using the following command, the system will take care of searching and showing us all the results that match the name of the file and that are found in the directory home and above.

find /home -iname nombredelarchivo

If we want the search to be performed throughout the system, the code to use is:

find / -iname nombredelarchivo

To perform the search in a directory, without searching in higher levels, we must replace the / with a period «.»

find . -iname nombredelarchivo

If we only remember part of the document name, we will rely on the use of asterisks “*”.

find .-iname *nombrequerecordamos*

Asterisks can also be used if we do not know the file extension.

the modifier -iname forces the system to be case insensitive. If we add -not to the search command, all the files that do not match the established search will be displayed.

find . -not nombredelarchivo

The command find also allows us search and delete directly all files with the search name by adding -delete at the end of the command.

find .-iname nombredelarchivo -delete

Using Locate

The Locate command offers us faster results, as long as we are looking for files that we have created and that we have located somewhere in the system. This is because it only searches the file base, not the entire system.

The first thing we need to do is install it using the command

sudo apt-get install mlocate

To perform a search using this command, we will use the following command

locate nombredelarchivo

This command also includes a series of variables that allows us to refine the search results. If we add the variable -r and the symbol $ next to the name of the file, only that specific file will be displayed.

locate -r nombredelarchivo$

To make the command case-insensitive, we add the variable -i

locate -i nombredelarchivo

When the number of results is very high, locate allows us to set the maximum number of results to be displayed with the -n command, followed by the number of files.

locate nombredelarchivo n 10

If the Linux file search results obtained with locate refer to files that have already been deleted, we must update the database using the command

sudo updatedb

Through the user interface

To search for files in Linux using the graphical interface, we must use the file manager to the drive where the file is located, or where we think it should be.

Find Linux files

Next, click on the magnifying glass located at the top of the window and enter the name of the file. That same window will show us, seconds later, all the files and
folders that match the name we have specified. Next to the name, the file location

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *