Common commands for searching File Content in Linux

Source: Internet
Author: User
Tags squid proxy

#> Find.-type f-exec grep 'mingtianc'-l {}\; grep-l: indicates the name of the file that displays the Matching content! The above-mentioned link file type after the find parameter-type,-name '*. c' connection file name-exec executes a program. Or: #> find. -type f-name "*. * "| xargs grep 'xiaoshou '-l (this method is not good, messy, and slow. We recommend the previous method !) 1. Find the row matching the specified string from the file content: $ grep "searched string" file name 2. Find the row matching the regular expression from the file content: $ grep-e "Regular Expression" file name www.2cto.com 3. Case Insensitive during search: $ grep-I "searched string" file name 4. Search for matched lines: $ grep-c "searched string" file name 5. Search for rows that do not match the specified string from the file content: $ grep-v "searched string" file name 6. Search for all extensions from the root directory. log, and find the line "find/-type f-name" * containing "ERROR "*. log "| xargs grep" ERROR "www.2cto.com 7. Example: Search for/SqLogs/access. the log file contains ". method 1 for recording exe "or" TCP_DENIED ": grep/SqLogs/access. lo G-e ". exe "grep/SqLogs/access. log-e "TCP_DENIED" Method 2: find/SqLogs-type f-name access. log | xargs grep ". exe "find/SqLogs-type f-name access. log | xargs grep "TCP_DENIED" because the company uses the SQUID Proxy Server to share the Internet, sometimes for some reason, the new version of the application or financial tax return software will not be available, so only view access. log File, find the reason! Because the LOG file is too large, even though the LOG file is compressed and rebuilt every day, there are too many contents in the LOG file of dozens of MB. It is a waste of time and effort to directly open it and look for it again! Previously, tail-n 100/SqLogs/access was used. log commands are also very difficult to find. The two commands above have helped me a lot, and I can find the problem in a short time! Share with you! Author: zhuizhuziwo

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.