Linux file Lookup

Source: Internet
Author: User

The Linux file lookup related commands generally involve two commands:

    • Locate
    • Find

Locate

Format:

Locate file name

Locate Regular expressions

Description

Instead of searching the file system, locate searches from a database. So the locate command searches very fast.

However, the locate command cannot find the new file that was just created. The information for the new file is not saved to the database in real time. With the UpdateDB command, the file system information is saved to the database, UpdateDB is usually run once a day.

The UpdateDB command can be run manually, but the UpdateDB command is only run by the root user.

Cases:

Locate VIMRC

Find

The Find command is used to find files in the current directory.

Cases:

Find all content in the current directory, including directories and files:

Find.

Find all txt files in the current directory:

Find. | grep. txt

Find all files in the current directory:

Find. -type F

Find all directories in the current directory:

Find. -type D

To execute a command against a collection of searched files:

Find. -type f-exec ls-l ' {} '; '

Content lookup for a collection of searched files:

Find. -type f-exec grep hello ' {} '; '

Find the contents of the searched file collection and output the file that matches the content:

find.-type f-exec grep hello ' {} '; ' -print

Finds the contents of the searched collection of files and outputs the file where the match is located, and outputs the line number of the matching content:

find.-type f-exec grep-n Hello ' {} '; ' -print

The search for a collection of files for content lookup, the content lookup ignores case, the output matches the file, and output the line number of matching content:

find.-type f-exec grep-ni Hello ' {} '; ' -print

Description

' {} ': Represents the result set of the Find command search.

The output of the Find command searches and outputs the memory in a depth-first manner.

Linux file Lookup

Related Article

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.