Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Grep how to find files based on file contents in UNIX     - Ora-00600 [fast hot Atkins soft _ that _ Oh, of course not _less_ profile] (Database)

- How do I upgrade from Ubuntu 15.04 to Ubuntu 15.10 (Linux)

- CentOS5 installation Nodejs (Linux)

- Java precision four operations (Programming)

- Linux command Detailed chpasswd bulk edit user password (Linux)

- Linux operation and maintenance of the automated installation and deployment RHEL7.0 Cobbler (Linux)

- iOS developers - a simple factory pattern and OC reflection (Programming)

- Ubuntu install Avast antivirus software (Programming)

- 14 useful example Linux Sort command (Linux)

- Linux iostat command example explanation (Linux)

- Git Installation and Configuration (Network Agent settings) (Linux)

- Linux platform NTOP Installation and Configuration (Linux)

- CentOS 7 How to connect to a wireless network (Linux)

- C ++ Supplements - Virtual Function Principle (Programming)

- Java code JIT compiler-friendly Mody (Programming)

- To access an Oracle database using Instant Client (Database)

- Elasticsearch 2.20 Highlight (Server)

- Android screen rotation processing and ProgressDialog the best AsyncTask (Programming)

- The strings in Python reside (Programming)

- Linux Firewall Builder shorewall (Linux)

  Grep how to find files based on file contents in UNIX
  Add Date : 2018-11-21      
  To complete the course work, I write a lot of C language code and save them as /home/user/c/*.c and * .h. Then the UNIX shell window How can I pass a string or a word (for example, the function name main ()) contents of the file to find the file it?

You will need the following tools:

[A] grep command: output matching model line.

[B] find command: find files in the directory hierarchy.


Use the grep command to find files based on content

Enter the following command:

grep'string '*. txt
grep'main ( '*. c
grep '# include ' *. c
grep'getChar * '*. c
grep-i 'ultra' *. conf
grep-iR 'ultra' *. conf
among them

-i: ignore patterns (matching string valid, VALID, ValID) and the input file (matching file.c FILE.c FILE.C) case.
-R: Recursively read all files in each directory.

Highlight to match the pattern

Searching for a large number of files when you can easily highlight mode:

$ Grep - color = auto-iR 'getChar ();' * c.

It displays the file name and line number to find patterns

You may want to display the file name and line number:

$ Grep - color = auto-iRnH 'getChar ();' * c.
among them,

-n: in front of each line of output is added to the beginning of the line number 1.
-H: Print filename for each match. To search for multiple file This is the default option. (LCTT Annotation: -h option forces hide filenames; additional -l and -L option to display only matches / does not match the file name, and -H and -h for controlling the front display matching lines display / not display file name, note the distinction.)

$ Grep --color = auto-nH 'DIR' *

You can also use the find command:

$ Find.-name "* .c" -print | xargsgrep "main ("
- Linux file system structure Introduction (Linux)
- C ++ you can become a new scripting language (Programming)
- Oracle conditional select statements and looping statements (Database)
- Use Vagrant build cross-platform development environment for Python (Server)
- How to install Docker and basic usage on Ubuntu 15.04 (Server)
- Use Elasticsearch + Logstash + Kibana set up centralized log Practice Analysis Platform (Server)
- Linux environment variable configuration and save places (Linux)
- RedHat6.4 installation tutorial --- Minimal Edition (Linux)
- EChart simple and practical control on chart (Programming)
- CentOS 6/7 Series Docker Installation (Linux)
- Install Mac OS X 10.9 systems VMware10 (Linux)
- Linux System Getting Started Learning: Join cron job in Linux (Linux)
- ACL permissions Linux command (Linux)
- Linux System Getting Started tutorial: Ubuntu desktop using the command line to change the system proxy settings (Linux)
- Spring Data study notes -Helloworld (Programming)
- To set up the printer use Nagios Monitoring Server (Server)
- How to install Visual Studio Code on Ubuntu (Linux)
- Use nice, cpulimit and cgroups limit cpu usage (Linux)
- How Bluetooth turned off by default in Ubuntu 14.04 (Linux)
- MongoDB upgrade to 2.6 (Database)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.