I searched everywhere but didn't find out how to return a file content that matches given words or a regex.
cat /tmp/*.txt | grep "strings"
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Did you just mean to
grep the file(s) instead of (uselessly)
cating it/them to
grep strings /tmp/*.txt
cat does is that it combines all
*.txt files into one big "file". If you
cat multiple files,
grep therefore will only see one input without a real name—it's all your files combined, fed through the pipe. This won't get you the file names, since you basically made everything one big file.
If you only want
grep to return the files that match, use the
grep -l strings /tmp/*.txt