How to use find command with grep command
Manages arguments passed to another command. This is often used either to increase efficiency (avoiding calling a command once for each argument) or to overcome shell environment limits (“Argument list too long”). It works by collecting arguments and invoking your command.
xargs is used to pass command arguments to the other process . So if we want to transfer output of the find command to the grep command we can use xargs.
find . -type f -print | xargs grep ‘oldmonk”
This command will search for all file in the current directory recusively (only file not directory) which contain ‘oldmonk’
How to recursive search in the directory
The wrong grep command would be
> grep 192.168.1.1 /etc/*.* The above command would search in only one directory etc The right command to search in the directory and recursively in subdirectory would begrep '192.168.1.1' /etc -d recurse
Explain grep command ?
GREP COMMAND INTERVIEW QUESTIONS UNIX SHELL COMMAND
GREP is a powerful tool to search a pattern in the files
Usage/Synatax:
1. grep “search pattern” “filename”
2. cat filename | grep “search pattern”
By default grep prints all the line containing the patterns
e.g to find telephone no : like 454-6746
grep "[[:digit:]]\{3\}[ -]\?[[:digit:]]\{4\}" file
//Spaces with hello and spaces …
grep "^[[:space:]]*hello[[:space:]]*$" file
