Linux Learning Log-File Search command

Source: Internet
Author: User

Opening summary:            learn the files in Linux Search command find and locate, System Search command Whereis and which, string Search command Grep,find and locate the difference and usage format, what is the PATH environment variable and its benefits, Whereis and which use, the difference is the query system command content, grep and find the difference, why to introduce a wildcard character? What is the use of wildcard characters or regular expressions? LocateFile Search Command:

1) format:

Locate [ file name ]

2) Update the database

UpdateDB

Benefits:

Compared to the find command,Locate consumes less resources and searches faster.

Principle:

Locate search file name is under the specified background database search, generally is the/var/lib/mlocate directory , but the database is updated once a day, so you're building a new file today, with Locate can't find it, but You can force updates by updatedb commands , you can find it.

The Find command is traversed on the file system as a whole. So the speed is relatively slow, the cost of large resources.

Command Search commandWhereisand thewhich(much like the two)

: Only system commands can be searched

1)

Example:whereis ls

Displays the position of ls and the position of the help document for LS.

2)

When you add- b , you just look at the position of LS. Don't look at the location of the Help document

Whereis-b ls

3)

Add- m to see only the location of the help document without looking at The location of Ls

Where-m ls


Which see the command's location and alias ( with the exception ) The help document for the command is not visible.

4) What is the path environment variable?

is the path to the defined system command search.

Such a benefit?

When you enter a command, you do not specify the absolute path to which it resides. Script commands that are written later can be placed in path and used directly.

path is defined,( manually, it is not necessary to enter the path, because it is configured in path ) to play ls will be found in these paths, find the function that will execute its command, cannot find the information thatcannot be found,command not found.

FindCommand(very powerful command.):

1) format

Find [ search scope ] [ search criteria ]



In the root directory, search for files named Install.log . ( resources are expensive because of the search in the directory )

2) wildcard character What is a wildcard?

Symbols born to make fuzzy queries

* match any Content

? match any one character

[] matches any one of the characters in brackets

Matches any character after Install.log file and matches all files



Matches any previous file ending with g




3) match is not case-sensitive

Find/root-iname Install.log

Note: Find is an exact match to be found and the original file must be a name, if you want to make a fuzzy query, then you need to use a wildcard character.

4) Owner files and junk files

In general, we make files that do not have owners as junk files. Manual removal is required. Use the command:

Find/root-nouser ( common )

Except for kernel generation and external (u - disk) files.

5) Search by file size
Find/root-size 25k

Find files equal to 25k

Find/root-size +25k

Find files that are larger than 25K

find/root-size-25k

Find files that are less than 25k

6) query by the file's node number

Find-inode 26543

Look for files with node 26543 .

7) Expansion

Find/root-size +20k-a-size--50k

- A is logical with find larger than 20k and less than 50k files.

Find/root-size +20k-a-size-50k-exec ls lh {}\;

Show the detailed results of the found files

Standard format:
-exec [ command ] {}\;

Grepstring Search command:(contains matching)

1) grep [ options ] string to find the file

2) plus - v is to find the contents of a file that does not contain a string

3) plus - i is case insensitive

Grepand theFindThe difference:

1) The Find command searches the system for eligible files, and the grep command searches the file for content that matches the string;

2) to match the Find command, a wildcard character is required, and the wildcard is exactly the match.       Grep uses regular expressions to match and is to include matches.

3) When is a wildcard or regular expression used?

If the match is the name of the file, then the wildcard character, if the search is the contents of the file, then you should use a regular expression.





Linux Learning Log-File Search command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.