How do I go through entire file system to locate a keyword - that is traverse all directories. My nested for loop is not going through complete file system. What is wrong with my logic, please?
for d in `find . ! -name . -prune -type d|xargs -n 1 basename`
do
if [ -d "$d" ]
then
for d in ./*/ ; do (cd "$d" && echo directory "$d" && find . -exec grep -n -i "KeyWord" {} /dev/null \;); done
else
echo "Processing file $d"
fi
done
From your code I understand that you want to execute "grep keyword" on all files from under the current directory. You don't need a script for it, might be done with:
find . -type f -exec grep -n -i "keyword" {} /dev/null \;
. … – czvtools