Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Grep how to find files based on file contents in UNIX     - Java memory mechanism Description (Programming)

- Linux serial debugging tools xgcom install (Linux)

- Install MATE desktop environment adjustment tools Mate Tweak 3.3.6 (Linux)

- Install OpenGL development environment in Fedora and Ubuntu (Linux)

- Getting CentOS Learning Notes (Linux)

- Detailed Linux network security policies and protection measures (Linux)

- Use SecureCRT to transfer files between Linux and Windows (Linux)

- Use PDFBox processing PDF documents (Linux)

- PHP file upload methods exist in the database (Programming)

- Use top to monitor the remote server (Server)

- MySQL database under Linux to achieve automatic backup scheduled backup day (Database)

- Linux, MySQL root privilege escalation another method (Linux)

- Oracle inverted reverse function (Database)

- Logging information through the web GUI (LogAnalyzer) (Server)

- How to set up HTTPS policies for older browsers (Server)

- php for Linux the MySQL extension module installation and configuration (Database)

- Talk about the Linux ABI compatibility Application (Linux)

- UNIX file permissions in the "set user ID bit" (Linux)

- Network Security: SYN attacks against under linux (Linux)

- MySQL use benchmarking tool sysbench (Database)

  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 ("
- MyCAT read and write separation of MySQL (Database)
- Boost - Memory Management - smart pointers (Programming)
- Talking about the implementation and the JVM garbage collection mechanism (Programming)
- Linux installation Jetty deployment under RedHat5 8 (Linux)
- Pydev installed and configured on the Eclipse (Linux)
- Deployment Kubernetes manage Docker example cluster on Ubuntu (Server)
- CentOS install pip (Linux)
- Linux User Rights Study Notes (Linux)
- How to Create a file can not be changed under Linux (Linux)
- VMware Workstation virtual machine Ubuntu achieve shared with the host (Linux)
- Log4Net (Linux)
- RabbitMQ tutorial examples: the Hello RabbitMQ World Java realization (Linux)
- OpenJDK7 source compiler installation on CentOS 6.5 (Linux)
- Use the top command (Linux)
- Installation through the network Debian 7 (Wheezy) (Linux)
- MYSQL root password for the database user passwords are weak attack analysis (Linux)
- Python implementation restart the router (Programming)
- How to limit network bandwidth usage in Linux (Linux)
- Ubuntu install video conversion tool Selene (Linux)
- Java Annotation Comments (Programming)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.