Linux grep search for strings in files

Source: Internet
Author: User

Search for keywords from files
Grep 'linux 'text.txt // search for keywords containing Linux

[Root @ localhost ~] # Grep 'root'/etc/group
Root: X: 0: Root
Bin: X: 1: Root, bin, daemon

Search for keywords from multiple files

[Root @ localhost ~] # Grep 'root'/etc/group/etc/My. CNF
/Etc/group: Root: X: 0: Root
/Etc/My. CNF: User = root

Search for all files containing the STR string in the current directory and the subdirectories under its jurisdiction. The file names and contents of the row and the row number are listed.

-N indicates the row number, and-R indicates the row number to be queried in the subdirectory.

Grep-n "str"-R ./

Case sensitivity can be ignored when searching with-I

Perform corresponding searches under all subdirectories and use-R to complete

Use-L to print all the results.

Grep-RIL 'str './

Find is a common command for searching files.

Search for all files with mail in the/etc directory.

[Root @ localhost] # Find/etc/-name '* mail *'
/Etc/mail. RC
/Etc/rc. d/rc5.d/k30sendmail
/Etc/rc. d/rc4.d/k30sendmail

Find the file whose size exceeds the specified value
[Root @ localhost] # Find./-type F-size + 100 m
./Test. SQL

Files modified in recent days
Find.-mtime-2

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.