[File under: too-technical, unix-tricks]
I spent some time researching how to tail all the log files in and under my log directory. I'm blogging about it here in hopes that it will be useful to someone, and in hopes that I'll not forget it when I need it next!
Several of the log files contain non-printable characters, so I had to find a way to discriminate between binary and text files. I played around with using the
file command, but I couldn't find a way to use its analysis within a single command-line.
This is what I finally wound up with:
find . -type f -not -name \*\.deflate_log\* -exec grep -Il . {} \; | xargs tail -F
Trying to translate into English, this is what I think it does:
find . gives a list of all files in this subdirectory and its subdirectories.
-type f specifies only plain files, as opposed to subdirectories and links. (I think.)
-not -name \*\.deflate_log\* removes files with
.deflate_log anywhere in their filenames: I believe the deflate mechanism is working, so I don't want to tail those logfiles.
-exec grep -Il . {} \; tells the find program to pass the filename to
grep The
-I tells grep to ignore binary files, and the
l tells it to return only the name of files that match,
i.e. all text files.
Finally, the remaining filenames are passed to
xargs, which then spawns a
tail -F command to do the actual work.
Can you see a cleaner way to get the job done? Please tell me!