grep
I've never been able to understand this command. It searches dir/files for a file pattern.
grep [-cilnv] pattern [filelist] how do you use the grep command with ls? Let's say I wanted to search through an entire directory of files for a pattern of text. how is this done? the following does not work: ls location | grep -l pattern |
Do you want to search the list of filenames that the ls command returns, or the contents of the files themselves?
To list the contents of your ~/downloads directory and look for occurances of the string "bleh" in the filenames you could do something like this: ls ~/downloads | grep "bleh" To go through the files in a directory and display what files contain the string "bleh", and in what file and on what line, you could type this: grep -Hn bleh * The -H switch displays the filename, the -n switch displays line number in the file(s) where "bleh" is found, "bleh" is the string to search for and * is the mask for the files to be searched (an asterisk meaning all files). To recursively look for files containing the string "bleh" in their name, try this: find . -name "*bleh*" Håkan |
thanks.
|
All times are GMT -5. The time now is 07:08 AM. |