File content query command

xiaoxiao2021-03-06  40

From a pirated disc, unknown

GREP, FGREP and EGREP Commands

This group of commands search files in specify mode and inform users to search for strings that match the specified mode and print out all the lines containing the string, the top of the text is the line. File name. The grep command can only search for a specified mode at a time; the EGREP command retrieves the extended regular expression (including expression groups and options); the fgrep command retrieves the fixed string, which does not identify the regular expression, is a quick search command.

This set of commands is useful in searching for specific themes in the location file. The mode to search for can be considered some keywords that you can use them to search these keywords included. When writing a program, you can use it to find a function, or the relevant phrase. The search function of the grep command is powerful than the FGRep, because the search mode of the grep command can be a regular expression, but FGREP cannot be. See the Shell chapter for regular expressions.

Each command in this group command has a set of options that can be used to change its output. For example, you can add a line number on a searched text line, or only the line number of the text line, or output all the text lines that do not match the search mode, or simply output the file name that has been searched for the specified mode, and You can specify whether you write on mode when lookup mode.

This group of commands find rows that match the pattern in the specified input file. If you do not specify a file, read it from the standard input. Normally, each matching row is displayed to the standard output. If the file to be found is multiple, add the file name before each row output.

grammar:

GREP [Option] [Find Mode] [File Name 1, File Name 2, ...]

EGREP [Options] [Find Mode] [File Name 1, File Name 2, ...]

FGREP [Option] [Find Mode] [File Name 1, File Name 2, ...]

This set of commands all the meaning of:

- E Each mode is treated as an extended regular expression.

- F Each mode is treated as a set of fixed strings (separated from a new row) without as a regular expression.

- b Displays the byte offset containing rows in the file in each line of the output.

- c shows only the number of matches.

- I don't care when comparison.

- h When looking up multiple files, indicating that GREP does not to add a file name before the output.

- l Displays the file name where the first matching string is located and disabled by the wrap. This file name is not repeated when a matching string is displayed many times in a file.

- n The line number in which the matching string is added before the output (the file first line number is 1).

- V Only rows that do not contain matching strings are displayed.

- x shows only rows of strict matching of the whole line.

- e expression specifies the mode of retrieval. The pattern used to prevent the beginning of "-" is interpreted as a command option.

- f Expfile Gets the mode to search from the ExpFile file, and a pattern occupies a row.

Use the use of the group command to pay attention to the following:

Type the search mode after the command, type the file you want to search. Among them, special characters can also be used in the file name list, such as "*", etc. to generate a list of file names. If you want to include a space in the search mode, you can use single quotes to search for the mode to search, indicating that the search is composed of a string containing spaces. Otherwise, the shell will consider the space for the delimiter of the command line parameter, and the grep command will explain the words in the search mode as part of the file name list. In the example below, the grep command search mode "text file" in the file eXample. $ GREP 'Text File' EXAMPLE

Users can generate a list of file names that will be searched with Shell special characters on the command line. In the following example, special characters "*" is used to generate a list of file names, which contains all files in the current directory. This command will search for rows that match all files in all files in the current directory.

$ GREP DATA *

Special characters are useful when searching for a set of specified files. For example, if you want to search all the specific modes in all C program source files, you can use "* .c" to specify a list of file names. Suppose the user's C program contains some unnecessary steering statements (GOTO statements), want to find these statements, can use the following command to search and display all the code containing the GOTO statement:

$ grep goto * .c

The user can type search mode on the command line, or you can use the -f option to read the mode to search from the specified file. In the file, each search mode occupies a row. This feature is very useful if you are searching for a set of common strings. In the following example, the user wants to search for the string "editor" and "create" in the file exam, put the mode to search in the file mypats, then the grep command reads the mode to search from the file mypats.

$ cat mypats

editor

Create

$ GREP -F MyPATS EXAM

File lookup command

Find command

Function: Search files in the directory structure and perform the specified operation. This command provides considerable lookup conditions, which is very powerful.

Syntax: Find start directory looking for conditions

Note: The Find command starts from the specified start directory, recursively searching its individual subdirectories, finds files that meet the search criteria and take the relevant operations.

This command is provided with a composite condition that is composed of logical operators NOT, AND, OR. Logical operators and OR, NOT meanse:

(1) AND: Logic, in the command, "-a" is represented by the system default option, indicating that the condition is satisfied when the conditions given are satisfied. E.g:

$ FIND -NAME 'TMP'-type c -user 'inin'

This command finds all the files that are all satisfied.

(2) OR: Logic or represented by "-o" in the command. The operator indicates that the search is satisfied as long as there is a satisfaction in the conditions given. E.g:

$ FIND -NAME 'TMP' -O -NAME 'MINA *'

This command query file name is 'TMP' or matches all files of 'mina *'.

(3) NOT: Logic is not used in the command. The operator represents the file that is not satisfied with the condition. E.g:

$ FIND! -NAME 'TMP'

This command query file name is not all files of 'TMP'.

It should be noted that when using a lot of logical options, these options can be enclosed in parentheses. In order to avoid the shell itself cause misunderstandings, it is necessary to increase the meaning of the parentheses before the voice number.

Example: $ find (-name 'tmp'-type c -user 'inin') Searching has the following options:

First, the n values ​​in the following options can have three input methods, assuming that n is 20, then:

20 is represented after 20 (21, 22, 23, etc.)

-20 indicates 20 before (19, 18, 17, etc.)

20 indicates just 20

1. Find in name and file properties.

- Name 'String' Find all files of the file name match the string of the string, the string can be used in wildcard *, [].

- Lname 'String' Find File Name Matches All Symbol Link Files of the String String, and the wildcards available in the string *,?, [].

-gid n Find all files for user groups belonging to the ID number N.

-UID N looks out all files of users belonging to the ID number N.

-group 'String' looks into all files that belong to the user group name as the string.

-user 'String' looks up all files belonging to the username as a given string.

-empty looks for directory or files of size zero.

-path 'String' Find all files of the path name match the string of the string, wildcards available in the string *,?, [].

-Perm Permissions Find files and directories with specified permissions, and privileges may be as 711,644.

-Size n [bckw] Find files for specified file size, n, indicating units, defaults B, represents 512 bytes of blocks.

-type x Find the file of the type X, X is one of the following characters:

B block device file

C character device file

d Directory file

p Named Pipe (FIFO)

f normal file

l Symbolic link file (Symbolic Links)

s socket file

-xtype x is basically the same as -type, but only looks for symbolic link files.

2. Find time for time

- Amin n looks for all the files previously visited before.

- Atime N looks for all the files previously visited before.

- cmin n Find all the files modified by N minutes.

- CTIME N looks for all files modified by N days before file status.

- Mmin N looks for N minutes before the file content modified all files.

- Mtime N looks for all files that have been modified by N days.

3. Executable operation

- Exec Command Name {} Performs the Linux command to which the eligible file is performed without asking the user if the user needs to be executed. {} Indicates the parameter of the command is the file found; the end of the command must end.

- OK command name {} The Linux command given to the eligible file is different from the EXEC, which will ask if the user needs to execute the command.

- LS details all the files found.

- The FPRINTF file name writes the file name to the specified file.

- Print displays the file name that looks out on the standard output device.

- Please refer to the book about C language, please refer to the book about the C language.

Example 1: Find all the files starting with main directory and display the contents of these files.

$ FIND. - Name 'main *' - exec More {};

Example 2: Delete the a.out or * .o file that has not been accessed within all weeks in the current directory.

$ FIND. (- Name a.out - o - name '* .o')

> - ATIME 7 - EXEC RM {};

described as follows:

"." In the command represents the current directory, at this time, Find will start from the current directory, and find the file that satisfies the subsequent condition in its subdirectory. (And) indicate parentheses (), "" "called escape character. The reason why writing is due to the other meaning of the shell, rather than the use of combination conditions here. "- Name a.out" refers to the file you want to find named A.out; "- Name '* .o'" means the file to find all the names to end .o. These two-name-o represents logic or (or), that is, the lookup name is a.out or name to end files ending with .o, find after the current directory and its subdirectories, then find this file Judgment, see if its last access time is 7 days (condition -Atime 7), if so, the file is executed command RM (- EXEC RM {};). The {} represents the currently available file name, which is required by the syntax. The last one of the first lines in the above command is the continuation. When the command is too long and you can't write, you can enter one, then the system will display a>, indicating that the user continues to enter the command. Locate command

The LOCATE command is used to find a file, which is fast than the search speed of the FIND command, which requires a database, which is created by a routine work (CRONTAB) program. When we establish this database, you can easily search for the required files.

The general form of this command is:

LOCATE related words

For example: Find related words ISSUE

$ locate issu

/ ETC / ISSUE

/etc/issue.net

/usr/man/man5/issue.5

/usr/man/man5/issue.net.5

转载请注明原文地址:https://www.9cbs.com/read-69740.html

New Post(0)