User:
gbs
Date: 5/5/2016 9:33 am
Views: 14299
Rating: 1
- This the most powerful and useful command in all of Unix (IMHO) is the find command. It will explore all subdirectories at a specified root location and perform a command on all files.
- Here is a command to find the word "California" inside any text file (and some binary files) underneath the current directory.
- Find all files under my current working directory (cwd) with the word California in the file.
$ find . -type f -exec grep California {} \; -print
The command "prints" to the screen (sysout), not a printer.
The "-type f" means to only look at files. Otherwise you will get an error reported for all directories (-type d) traversed.
The "{} \; -print" is voodoo. Just go with it.
How many lines were there in the results?
$ find . -type f -exec grep California {} \; -print | wc -l
Line numbers please
$ find . -type f -exec grep -n California {} \; -print | wc -l
I want both upper case and lower (California and california)
$ find . -type f -exec grep -i California {} \; -print | wc -l
Just my log file over in first logs
$ find /etc/logs/Server.log -exec grep Error {} \; -print
Too much output! Show me only lines in the file with both "California" and "surfboard". I want the output to go to a file. Note you will lose filenames (unless they have "surfboard" in their name.)
$find . -type f -exec grep California {} \; -print | grep surfboard > SurfsUp.txt
The find command can be used to run most any unix command. I have only shown "greg". You could delete files with "rm" and much more. Search for "cygwin find" to see more.
Sorry no examples.