tiger99
January 23, 2008, 12:04am
1
Hi
I was wondering why command 2 doesn't work like command 1 below.
find . -exec grep "test" '{}' \; -print
ls -R | grep "test"
I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2?
Thanks in advance for your help
tiger99:
Hi
I was wondering why command 2 doesn't work like command 1 below.
find . -exec grep "test" '{}' \; -print
ls -R | grep "test"
I am trying to search "test" from all the files in the current and sub directories. What's wrong with my command 2?
Thanks in advance for your help
command 2 searches for filenames that have the string "test" as part of their name while command 1 searches for the string "test" inside each of the files.
ls -R | xargs grep "test" #this makes command 2 like command 1
Hi shamrock
Thanks for your help
However the code you suggested
ls -R | xargs grep "test"
gives me a huge list with ending "No such file or directory".
i.e.
grep: expr.sh: No such file or direcotory
Is it possible to only display the directory and file name when the text that I am searching is found?
Thanks
try this :
find . | xargs grep -l "test"
Hi,
For the "No such file or directory", it is becuase there are error messages print to the stand output, you can ignore them by adding
2>/dev/null
at the end of the command,which will stop printing all the error message to stand output which is our screen.