How to find file contents in Linux

Source: Internet
Author: User

Linux finds common command methods for file content.

Find the line matching the specified string from the file contents:

$ grep "string found" file name
Example: Looking for the. In file containing the specified string in the first level folder in the current directory
grep "Thermcontact" */*.in

Find the line that matches the regular expression from the file contents:
$ grep–e "Regular expression" file name

Find is case insensitive:
$ grep–i "string found" file name

To find the number of matching rows:
$ grep-c "string found" file name


Find rows that do not match the specified string from the file contents:
$ grep–v "string found" file name


From the root directory, look for all text files with a. log extension and find the line that contains "ERROR"
Find/-type f-name "*.log" | Xargs grep "ERROR"
Example: Starting from the current directory, find all text files with an. in extension and find the line containing "Thermcontact"
Find. -name "*.in" | Xargs grep "Thermcontact"

How to find file contents in Linux

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.