Using cat and grep to print out the names of files that contain the "password:" string within the current directory:
cat * 2>&- | grep -ls 'password:' *
With full file path:
cat * 2>&- | grep -ls 'password:' ${PWD}/*
2>&- is used to suppress error messages about being unable to read certain files/directories.
Using only grep to do the same thing:
grep -ls 'password:' *
With full file path:
grep -ls 'password:' ${PWD}/*
Using grep to pattern match for the "password:" string, printing the filename, then using cat to display the entire file(s) contents:
for match in $(grep -ls 'password:' *) ; do
echo "${match}"
cat "${match}"
done
With full file path:
for match in $(grep -ls 'password:' *) ; do
echo -e "\e[7m\n$(readlink -f "${match}")\e[0m"
cat "${match}"
done