find . -name "rc.conf" -print
This command will search in the current directory and all sub directories for a file named rc.conf.
Note: The -print option will print out the path of any file that is found with that name. In general -print wil print out the path of any file that meets the find criteria.
How to search for a string in a selection of files (-exec grep ...).
Examples:
find . -exec grep -s "GMAC reset complete" '{}' \; -print
find . -exec grep -s "GMAC reset complete"#space#'{}'#space#\;#space#-print
Output:
printk(KERN_INFO "GMAC reset complete\n");
./vendor/linux-kernel/arch/arm/mach-oxnas/gmac-napi.c
Very important point to remember is to have a space between the end of the } and \; otherwise bash will complain cannot use the -exec option in find. The -s option in grep is used to suppress all the error message in traditional grep. For newer version of grep, use the -q option.
find . -exec grep "GMAC reset complete" '{}'
This command will search in the current directory and all sub directories. All files that contain the string will have their path printed to standard output.
If you want to just find each file then pass it on for processing use the -q grep option. This finds the first occurrance of the search string. It then signals success to find and find continues searching for more files.
find . -exec grep -q "www.athabasca" '{}' \; -print
This command is very important for process a series of files that contain a specific string. You can then process each file appropriately. An example is find all html files with the string "www.athabascau.ca". You can then process the files with a sed script to change those occurrances of "www.athabascau.ca" with "intra.athabascau.ca".
No comments:
Post a Comment