Instantly search files in Windows. Sleight of hand and no fraud

Sometimes you may need to find a file that contains a certain string or find a line in a file that contains a specific word. In Linux, all this is done using one very simple, but at the same time powerful utility. grep. With its help, you can search not only for lines in files, but also filter the output of commands, and much more.

In this manual, we will look at how to search for text in Linux files and look at the possible options in detail. grep, and also give several examples of working with this utility.

Team grep(stands for global regular expression print) is one of the most popular commands in the Linux terminal, which is part of the GNU project. The secret to its popularity is its power; it allows users to sort and filter text based on complex rules.

The grep utility solves many problems, it is mainly used to find strings that match a line in text or the contents of files. It can also find by pattern or regular expressions. In a matter of seconds, the command will find a file with the required line, text in the file, or filter only a couple of required lines from the output. Now let's look at how to use it.

grep syntax

The command syntax is as follows:

$ grep [options] pattern [filename...]

$ command | grep [options] pattern

  • Options- these are additional parameters that allow you to specify various search and output settings, such as the number of lines or inversion mode.
  • Sample- this is any string or regular expression that will be searched
  • File and command - this is the place where the search will be conducted. As you will see further, grep allows you to search multiple files and even a directory using recursive mode.

The ability to filter standard output is useful, for example, when you need to select only errors from the logs or find the PID of a process in a numerous utility report ps.

Options

Let's look at the most basic utility options that will help you search for text in files more efficiently grep:

  • -b- show the block number before the line;
  • -c- count the number of occurrences of the pattern;
  • -h- do not display the file name in search results inside Linux files;
  • -i- ignore case;
  • - l- display only the names of files in which the template is found;
  • -n- show the line number in the file;
  • -s- do not show error messages;
  • -v- invert the search, return all lines except those containing a pattern;
  • -w- search for a pattern as a word surrounded by spaces;
  • -e- use regular expressions when searching;
  • -An- show the occurrence and n lines before it;
  • -Bn- show the entry and n lines after it;
  • -Cn- show n lines before and after the entry;

We've covered all the most basic options and even more, now let's move on to examples of the command's work grep Linux.

Examples of using

The theory is over, now let's move on to practice. Let's look at some basic examples of searching inside Linux files using grep, which you may need in everyday life.

Finding text in files

In the first example, we will look for the user User in the Linux password file. To search for text grep In the /etc/passwd file, enter the following command:

grep User /etc/passwd

As a result, you will get something like this, assuming such a user exists, of course:

User:x:1000:1000:User,:/home/User:/bin/bash

Now let's not take case into account during the search. Then the combinations ABC, abc and Abc from the point of view of the program will be the same:

grep -i "user" /etc/passwd

Print multiple lines

For example, we want to select all errors from a log file, but we know that the next line after the error may contain useful information, then we will use grep to display several lines. We will look for errors in Xorg.log using the “EE” pattern:

grep -A4 "EE" /var/log/xorg.0.log

Will output the line with the occurrence and 4 lines after it:

grep -B4 "EE" /var/log/xorg.0.log

Prints the target line and 4 lines before it:

grep -C2 "EE" /var/log/xorg.0.log

Will output two lines from the top and bottom of the entry.

Regular expressions in grep

Regular Expressions grep- a very powerful tool that greatly expands the possibilities of searching for text in files. To activate this mode, use the option -e. Let's look at a few examples:

Search for an occurrence at the beginning of a line using the special character "^", for example, we will display all messages for November:

grep "^Nov 10" messages.1

Nov 10 01:12:55 gs123 ntpd: time reset +0.177479 s
Nov 10 01:17:17 gs123 ntpd: synchronized to LOCAL(0), stratum 10

Search at the end of the line - special character "$":

grep "terminating.$" messages

Jul 12 17:01:09 cloneme kernel: Kernel log daemon terminating.
Oct 28 06:29:54 cloneme kernel: Kernel log daemon terminating.

Let's find all lines that contain numbers:

grep "" /var/log/Xorg.0.log

In general, regular expressions grep- This is a very broad topic, in this article I just showed a few examples. As you have seen, searching for text in grep files becomes even more efficient. But a full explanation of this topic would require an entire article, so let’s skip it for now and move on.

Recursive use of grep

If you need to search for text in multiple files located in the same directory or subdirectories, for example in the Apache configuration files - /etc/apache2/, use a recursive search. To enable recursive search in grep there is an option -r. The following command will search text in Linux files in all subdirectories of /etc/apache2 for the string mydomain.com:

grep -r "mydomain.com" /etc/apache2/

In the output you will get:

grep -r "zendsite" /etc/apache2/
/etc/apache2/vhosts.d/zendsite_vhost.conf: ServerName zendsite.localhost
/etc/apache2/vhosts.d/zendsite_vhost.conf: DocumentRoot /var/www/localhost/htdocs/zendsite
/etc/apache2/vhosts.d/zendsite_vhost.conf:

Here, the found string is preceded by the name of the file in which it was found. It is easy to disable the file name output using the option -h:

grep -h -r "zendsite" /etc/apache2/

ServerName zendsite.localhost
DocumentRoot /var/www/localhost/htdocs/zendsite

Finding words in grep

When you are looking for the string abc, grep will also output kbabc, abc123, aafrabc32 and similar combinations. You can force the utility to search the contents of files in Linux only for those lines that exclude the search words using the option -w:

grep -w "abc" filename

Search two words

You can search the contents of a file not for one word, but two at once:

egrep -w "word1|word2" /path/to/file

Number of occurrences of a string

Utility grep can tell you how many times a particular string was found in each file. To do this, use the option -c(counter):

grep -c "word" /path/to/file

Using the option -n You can display the line number in which the occurrence was found, for example:

grep -n "root" /etc/passwd

1:root:x:0:0:root:/root:/bin/bash

Inverted search in grep

Team grep Linux can be used to find lines in a file that do not contain a specified word. For example, print only those lines that do not contain the word pair:

grep -v steam /path/to/file

File name output

You can specify grep display only the name of the file in which the specified word was found using the option -l. For example, the following command will display all file names whose contents were searched to find an occurrence of primary:

grep -l "primary" *.c

Color output in grep

You can also force the program to highlight occurrences in the output with a different color:

grep --color root /etc/passwd

It will turn out:

conclusions

That's all. We looked at using the command grep to search and filter command output in the Linux operating system. When used correctly, this utility will become a powerful tool in your hands. If you have any questions, write in the comments!

Searching for files may seem difficult for novice users and take a long time. In this article we will look at all the ways to search for files on your computer.

Important: Search results through the Start menu display not only files, but search results will also display Windows system commands of the same name. For example, entering the search query “cmd” will result in a command (program) that launches the command line.

Main search window


Explorer window

The next way to search for files is to use any Explorer window. To search for files using Explorer, you must enter a request to the appropriate section of any open window (for example, “My_computer”).

This method is more convenient than others because, using Explorer, you can search for files directly inside specified (open) hard drive partitions (folders) without the need to enter appropriate restrictions using a search filter. What is significant is the process of searching for files.

Search filters

In addition to how you search for files, it's also important how you can narrow your search results to find exactly the file you need. This is done by using special search filters; you can use them by searching for files in the Explorer window. Because the submariner uses the most filters to filter out unnecessary search results.

Search settings

Sometimes the search is unable to find the file of interest, this happens if it is located inside an unindexed partition of the hard drive. This can be fixed if you configure and expand the search parameters. To do this, follow the instructions described below.

Search operators

Operators are symbols/words that include additional search results filter parameters. In other words, these symbols are used to quickly filter out results, similar to how it is done in Internet search engines (Yandex, Google, Yahoo).

The most popular operators:

  • Quotes “” – finds files containing the exact phrase of the search query in the name (for example, “rules of the game”);
  • Asterisk * - finds files with the extension specified after the asterisk (for example, *.doc);
  • Logical “AND” “AND or +” - finds files containing all the listed words, between which “AND or +” is written. (for example – “rules+game+football”, “rules AND football+game”);
  • Comparison relative to the specified file parameters >, 1GB, color depth:
  • Exact value = - searches for files equal to the specified parameters (for example, dimensions:>=”800 x 600″);

Reference

If after reading the article you have any questions about searching for files, you can find answers to them in the specially created help section of the operating system. The help menu will open after pressing the F1 key. To obtain information regarding searching for files, enter the search query - “search”.

This way you will find all Windows Help topics related to file search.

In order to find any object on your computer, just enter the name of the file or folder you need in the Start menu. The computer will search for all files containing this name in whole or in part. But this is not always enough to find all the necessary information on your computer. There are times when you need to find document(s) with certain words in the text, for example: “free computer courses”, but by default in Windows 7 this function is disabled.

Setting up file search in Windows 7

To do this, open “Computer”, click on the “Arrange” button on the left and select “Folder and Search Options”.

After such a small setup, the search will work by file names, as well as by its contents.

Finding files in Windows 7 in practice [check]

Let's check if everything works correctly. To do this, open “Computer”, enter in the search field the word that you need to find in the files. For example, I chose the word “quality”. When you enter a word or phrase, the search will begin automatically (no need to click anything).

After the search completes the task on this word, files containing the word “quality” will appear below. You should also know that after searching for the information you need, you need to change the default settings (which were). This is due to the fact that the search will take much longer, since it searches not only the file name, but also its contents.

For quick search in Windows 7 by content, it is best to go to the folder where your file may be located and search from there.

Over a long period of time working with a computer, a huge number of files and documents accumulate on it. To avoid cluttering the desktop, files are transferred to other storage locations. As a result, a huge number of folders and subfolders appear and it becomes increasingly difficult to find the desired file. After all, it’s difficult to remember exactly which “new folder” it is in. Fortunately, Windows has a convenient search system built into it that will help you find a file on your computer, even if you don’t remember its exact name.

If you can’t find the file you need, the first thing you should do is look at the “Trash” system folder on your desktop. Suddenly you accidentally deleted it, and because of this you cannot find it in its usual place. It’s better to check right away so that you don’t later clear all the files, permanently deleting the information. Although, in fact, information deleted from the recycle bin can be restored using special programs. But this is a completely different topic, so if you are interested, read this article.

To search for files on a computer running Windows XP, do the following:

  1. Give the command “Start - Search”.
  2. Click on "Files and Folders" to launch the Find Files and Folders Wizard.
  3. Select a category, for example "Video". You can select one, several or all categories at once. Click the Find button.

Windows will find all of the above files on any PC disk partitions and external storage devices (including network ones). For example, when you put together all the movies and videos, it's time to use the search, for example, only for video files. It is also worth refining the search in order to quickly find a specific file by entering at least part of its name.

The asterisk character replaces any number of letters and numbers in the file name. For example, instead of the keyword “asterisk” you can enter “sound” - all variants of this word in the name of the searched file will be searched, for example, a file named “No sound.mp3”. Specifying only the file name extension, for example, *.docx, will detect all your Word documents in this format, for example, the file “resume.docx”.

It is also possible to assign a file search on a Windows PC to hidden files and folders.

To find files based on a keyword in a document, do the following:

  1. Give the already familiar command “Start - Search” and in the “Word or phrase in file” column, indicate a keyword, for example, “abstract”.
  2. In the file name, specify the extension, for example, “.doc”.
  3. Also specify the search location, for example, drive C. Check the desired options, for example, search in hidden and system folders, and click the “Find” button.

All documents containing the word “abstract” in DOC file format will be found.

How to find files on a PC with Windows 8/8.1/10/10.1

Having updated the version of Windows to 8 or 10, the user will notice that the search tools are assembled and configured more conveniently than in previous versions of this OS. Although at first it may be inconvenient to use them.

Search files on PC by name

  1. Give the command “This PC – Search” (search tab). In the Windows search box, enter part of the file name (or the whole name, if you remember it). Press "Enter" on your keyboard.
  2. The required file (or files) will be found (or will be found).

Search files by name extension

By remembering the file name extension you were working with, you can search for it by that name. For example, archive files most often have the extension .rar or .zip, program files (including installation packages) - .exe or .msi, etc. As a result, when searching for files by extension, you will most likely discover your loss.

It happens that you do not remember the file extension, because the Windows system does not display any file extensions by default. To enable them, do the following:

  1. Give the command “Start – Control Panel – Folder Options”.
  2. Go to the command “View – Options – Change settings for files and folders”.
  3. Uncheck "Hide extensions for known file types." For more experienced users, the “Hide protected system files” feature may be useful.
  4. Click the “Apply” and “OK” buttons successively.

Windows Explorer will restart and display file extensions. Having matched the one you are looking for with the extensions of similar files (by the type of file icon), enter its extension in the already familiar search bar and press the “Enter” key. Windows will find the missing file.

For example, a video clip in AVI format has disappeared. Open the familiar file search panel and enter the file extension .avi. Press Enter and review the files found.

Search files by occupied disk space

Having guessed that, for example, a two-hour movie has a large volume, for example, a video file in UltraHD format (“rip” from a Blu-Ray disc), you can enter, for example, a command to search for files larger than 10 GB.

Windows uses a command format to search for a file by size: “System.Size:>size_in_megabytes”. For example, in this case it will be the command “System.Size:>10240MB”.

With a high degree of probability, this movie will be found, for example, on an external (network) drive.

How to find hidden files

To gain access to hidden files, enable the function to show them.

  1. Go to the familiar Windows Folder Options settings window.
  2. Give the already familiar command to change folder and search settings.
  3. Enable the "Show hidden files, folders and drives" option.
  4. Click the "Apply" and "OK" buttons.

Repeat the search for the file using already familiar attributes: name and/or extension, size, etc.

Search files by keywords

Keywords in the file content (letters, documents, books, etc.) can be specified directly in the “File Name” field. So, if you are looking for course projects, write “coursework” in the file name.

Windows will display files with the available keywords (or phrases).

Third-party file search programs

The functionality of a file manager is endowed not only with the built-in Windows Explorer. In the past, these were Norton/Volkov Commander, Far File Manager, Total Commander, File Explorer and their analogues.

Searching for files using the Total Commander example

Text documents, regardless of their formatting, are searched by Total Commander by name, size and keywords (or phrases).


Windows will find the files you are looking for.

Finding a file on a Windows PC is not a problem. The main thing is that you do not erase it permanently by using other applications for this purpose. The Windows system already has the necessary tools for searching files, folders and disks, but if for some reason it does not suit you, use a third-party file manager, which may contain additional functions for searching files on disks.

In this article you will learn very interesting things about the built-in Windows file search and after reading the material you will be able to find even files lost in folders about which you know bits of information.

It is not difficult to guess that this article will talk about advanced search in Windows. Undoubtedly, every computer user periodically uses a form of the standard Windows “search engine,” but not everyone knows that this search engine can be used much more productively and is a difficult tool, as it might seem at first glance.

Options and parameters that expand search capabilities

Despite the fact that the title contains the word “expanding”, these same options will help us put additional screening filters on our search query for files and folders in Windows and will actually narrow the number of files found, which is to our benefit.

* - Means any sequence of any characters, i.e. all characters.

? - Any one character

~<" something" - Search for a name (File name, author, etc., depending on where to put it) which should begin with the one in quotes. The example searches for the name where the beginning is something.

~>" something" - Search for a name that must end with the one in quotes.

=" Course work" - Search for an exact match with what is in quotes.

~=" Well" - Search for names that contain the exact set of characters like the one in quotes. Those. on request filename:~="course" there will be files not only with the word Well, but also simply containing this sequence of characters (Kursovoy, Kursach).

~!" Well" - Search for files that do not contain what is in quotes. Those. this parameter is completely opposite to the previous one.

<> - Means like “neither is”, “not”. Those. request where it will be view:<>picture , will search everything except pictures.

() - Brackets serve to separate and clarify the combining group where the operators operate.

"" - Quotes are used to accurately find the order of characters inside quotes. Because of this, operators inside quotes do not work at all, as do filters.

OR- Operator OR. For example, request filename: kcoursework OR work will search for files where words occur either coursework or Job well, or both. In the English version OR.

AND- Operator AND. For example, request filename: k ursovaya and work will look for files where both words are present, and it makes no difference in what places they are located and not necessarily next to each other. In the English version AND.

NOT- Operator NOT. For example, request filename: coursework NOT work will search for files containing the word coursework but there is no word Job. In the English version NOT.

Here are some examples of using operators:

size:10MB and- Finds Ivan’s files of 10 megabytes, which were changed after 2009.

filename: (*156*) AND type:(PNG OR JPEG) - Finds files where the name contains 156 and its extension is PNG or JPEG.

Now filtering options.

Below we present what filtering options you can use when searching for files and folders.

file name:- The name of the file you are looking for. Analogue on English-language Windows - filename.

type: Indicates what type of file is currently being searched. Can take both file extension values ​​(For example, type: PNG), and their logical definition (For example: type: music or type: picture ). Analogue on English-language Windows - type.

view:- Same thing as type:. Analogue on English-language Windows - kind :

Date of change:- Indicates when the files were modified. Can take exact values, ranges, as well as verbal meanings (long ago, yesterday, etc.). Analogue on English-language Windows - datemodified.

modified date: 05/25/2010

date modified: >2009

date modified: 21.01.2001 .. 05.01.2014 (Required two points in the range)

date of creation:- Indicates when the file was created. The values ​​are the same as for Date of change. English equivalent datecreated.

size:- Indicates the size of the searched files. Can take both exact values ​​up to decimal numbers and a range of sizes. The units of measurement are KB, MB, GB. English language option - size:.

size:<=7Мб >1.5MB - files larger than 1.5 megabytes, but less than or equal to 7.

attributes:- Sets an additional search mask by tags. The parameter is not often used due to the fact that tags are rarely used.

owner:- Search for files of a specific owner.

executor:- Specifying this attribute is relevant when searching for music of a particular artist.

Combining filtering options

You can use several different options at once when searching, and this will even be better, because it will reduce the list of found files, while increasing their relevance. When using several search filters, place a space between them; in fact, it replaces the AND operator.

Attention! The AND and OR NOT operators are never highlighted in blue in the search bar. If yours is highlighted, it means you forgot either quotes or brackets or something else. Please note that some filters may not work with certain operators. For example it cannot be type:(BMP AND PNG), since any file can only be of one type.

For example, you can use the query:

size:5KB..20 KB type:picturefilename:~<"m" *little* датаизменения:‎01.‎03.‎2014 .. ‎31.‎03.‎2014

This app ros looks for images between 5 and 20 kilobytes in size with a file name that begins with a letter m and in which the word appears little. In this case, the file should have been changed during March 2014.

As you can see for yourself, with such capabilities you can easily search for files from many years ago, remembering at least some little details about it.

Several templates

In order for you to understand everything better and be able to try Windows advanced search yourself, we decided to make several of the most commonly used advanced search templates that can often come in handy.

How to find all files in a folder?

Sometimes a person wants to count how many files are in a particular folder and he is faced with the question of how to do this. Using Windows Search? But then what should I introduce? The input originates from regular expressions, and those who know first-hand what it is have already guessed what kind of character needs to be entered into the search field.

In the search field you need to enter: * (Star).

How to find all files of the same type (Extensions)?

If you want to find, for example, only pictures, use the filter type:picture, and if you want to find files of a specific extension, then you can use either *.jpeg or type:JPEG.

How to find files created at a specific time?

For this you need to use a filter creation date:DD/MM/YYYY. It is written about above. You can also set a filter not by the exact time the file was created, but by the interval. For example, from September 2011 to December 2012. The correct formulation of a search query with such a filter is described above.

How to find files of a certain size?

You need to use a filter size: and indicate the required file size in kilobytes, megabytes or gigabytes. You can read above about how you can search in a range of sizes and how to correctly indicate the size of the files you are looking for.

We really hope that this material will be useful to you, and if you have anything to add, then write in the comments.