Examples of using the Find command in Linux

Anonim

Examples of using the Find command in Linux

Most popular file managers for operating systems on the Linux kernel have a fairly functional search tool. However, the parameters that are not always present in it are enough to search for the necessary information. In this case, a standard utility that starts through the "Terminal" is to help. It allows you to enter the command, argument and options to easily find the required data in a specific directory or throughout the system.

We use the Find command in Linux

The FIND command is designed to search for various objects, including files of any formats and directory of various depths. From the user you only need to enter the command itself, specify the desired value and assign the arguments to set the filtering parameters. The procedure of the utility itself usually does not take much time, but it depends on the volume of the scanned information. Now let's dwell on the examples of using Find in more detail.

Transition to directory through the console

First, I would like to retreat a bit from the main team and affect the topic of additional actions that will help in the future when controlling from the console. The fact is that the Linux distribution utilities are not sharpened to search for all elements on the computer. All processes should be launched only with an indication of the full location to the items or go to the location through the CD command. Make it can be enough enough:

  1. Open the installed file manager and go to the desired folder where you want to use the FIND command.
  2. Go to the desired directory via Linux file manager

  3. On any object, click PCM and find the item "Properties".
  4. Transition to object properties in the Linux operating system

  5. You will see his parent folder with a full way to indicate. Remember it to make the transition from the "Terminal".
  6. Find out the parent folder of the object through the properties in Linux

  7. Now run the console, for example, through the menu.
  8. Starting the terminal for subsequent entry commands in Linux

  9. We write there a CD / Home / User / Folder command where User is the name of the user's home folder, and Folder is the name of the required directory.
  10. Move to location in the Linux terminal

If before using Find, perform the indicated instruction above, you can not prescribe the full path to the file provided that it is in the selected location. Such a solution will significantly speed up the command in the future.

Search for files in the current directory

When executing the FIND from the most running console, you will receive the search result in your active user directory. In another case, for example, when you activate while searching by location, in the results you will see all the subfolders and the files present in them.

Using the Find command without arguments in Linux

Find Activation without arguments and options is used when it is necessary to view all the elements at once. If their name is completely not placed in the string, it is worth changing the command so that it gets the form of the Find. -Print.

Search for files in the specified directory

The command for displaying files through a specified path is practically no different from the one we mentioned above. You should also register Find, and after add ./folder, if you want to find out the directory data in the current location, or you will need to specify the full path, by entering, for example, Find ./home/user/downloads/folder, where Folder - The final directory. Each elements will be withdrawn by separate lines in the order of their depth.

Using the FIND command indicating the location of the file in Linux

Search by name

Sometimes there is a need to display objects that only satisfy the name. Then the user needs to specify a separate option for the team so that it understands the appeal. The input row acquires this type: Find. -Name "Word", where Word is a keyword for searching, which is necessarily written in double quotes and, taking into account the register of each symbol.

Search for files by name via the Find command in Linux

If you do not know the exact register of each letter or want to display all the appropriate names, without taking into account this parameter, enter in the FIND console. -IName "Word."

To filter results by keyword to the argument -Name, another is added. The team acquires the form of Find. -Name "Word", where Word is a word that needs to be excluded.

Enable Filtering by keyword FIND command in Linux

Sometimes there is a need to find objects one key, excluding the other. Then, alternately assigned several search options and the input line is obtained by the following: Find. -Name "Word" -Not Name "* .txt". Please note that in the second argument in quotes indicated "* .txt", and this means that Find works not only with names, but also with file formats that are specified in this form.

Combined search by command Find in Linux

There is an operator or. It allows you to find one or several suitable arguments immediately. Each is indicated separately, with the addition of the corresponding arguments. As a result, it turns out about the following: Find -Name "Word" -O -Name "Word1".

Application Options or Command Find Linux

Specifying the depth of search

The FIND command will help the user and then when it needs to find the contents of the directory only to the specified depth, for example, no analysis is required inside the third subfolder. To install such restrictions, enter Find. -MaxDepth N -Name "Word", where n is the maximum depth, and -name "Word" - any subsequent arguments.

Specify the scanning depth of the Find command in Linux

Search in multiple directories

Many directories at once there are several folders with different contents. If there are a large amount there, and the search must be implemented only in certain, then you will need to specify this when entering the Find ./folder command ./folder1 -Type F -Name "Word", where ./folder ./folder1 is a list of suitable directory, And -name "Word" - the rest of the arguments.

Search in multiple folders when using the Find command in Linux

Display of hidden elements

Without specifying the appropriate argument, hidden objects in scanned directories will not be displayed in the console. Therefore, the user manually prescribes an additional option so that in the end the command was like this: Find ~ -Type F -name. * ". You will receive a complete list of all files, but if some of them do not have access, before the Find word in the row, sudo sudo to activate the superuser rights.

Display hidden files command Find in Linux

Scanning Home Folders Groups and Users

Each user can create an unlimited number of directories and objects in different locations. Faster finding the information that belongs to one of the users, using the Find command and one of its arguments. In the "Terminal" register Find. -user username, where UserName is the username. After entering the scanning will start automatically.

Show files belonging to a specific user team Find in Linux

Approximately the same scheme works with user groups. Running file analysis associated with one of the groups occurs through Find / Var / WWW -Group GroupName. Do not forget that objects can be a large number and on the conclusion of them all sometimes takes a lot of time.

Show files belonging to a specific group FIND command in Linux

Filtering by date

The operating system automatically saves information about the change date of each existing file. The FIND command allows you to find them all by the specified parameter. It is only required to register Sudo Find / -Mtime N, where n is the number of days ago when the object was changed last time. The sudo prefix is ​​needed here in order to get data and files intended only for superuser.

Filtration by date of change when command Find in Linux

If you are interested in viewing the items that the last time has opened a certain number of days ago, then the string changes its view on Sudo Find / -Time N.

Filtration by opening date when command Find in Linux

File Filtering

Each object has its own size, respectively, the file search command must have a function that allows them to filter them by this parameter. Find knows how to do this, you only need to set the size through the argument itself. It is enough to enter Find / -Size N, where N is the volume in bytes, megabytes (M) or gigabytes (G).

Filtering search by size using Find in Linux

You can specify the range of the desired elements. Then the definitions fit into the command, for example, such a string: Find / -Size + 500m -Size -1000m. Such an analysis will display files of more than 500 megabytes, but less than 1000.

Set the range of files for searching through Find in Linux

Search for empty files and directories

Some of the files or folders are empty. They just occupy an excess space on the disk and sometimes interfere with the normally interact with the computer. They should be found to determine further actions, and this will help the Find / Folder -Type F -Empty, where / Folder is a place where scanning is performed.

Show empty objects with Find in Linux

Separately, I would like to briefly note other useful arguments, which from time to time become useful for users:

  • -mount - restriction only on the current file system;
  • -Type F - Display only files;
  • -Type D - show only directory;
  • -nogroup, -nouser - search for files that do not belong to no group or belong to the user;
  • -Version - find out the version of the utility used.

This familiarization with the Find team is over. If you want to study in detail other standard console tools of operating systems on the Linux kernel, we advise you to refer to the individual material according to the following link.

Read more: Frequently used commands in Terminal Linux

After searching for the required information, you can carry out any other actions with them, for example, editing, deleting or studying content. This will help other built-in utilities "Terminal". Examples of their use will find below.

READ ALSO: Examples of Grep / Cat / Ls commands in Linux

Read more