Linux – tail all log files in a directory | exclude zipped files

excludelinuxlog-filestail

Im trying to find the right command to tail a bunch of log files whilst excluding the zipped files in a set directory. The log files are being zipped as they become oversized.

At the moment Im using:

tail -f /var/logs/myLog*

Which works fine, but it will also tail the .gz files which are a garbled mess. I need to tail only files without this extension.

Best Answer

If the filenames have anything else in common - e.g. length of name, number of periods in name, name ending... you can simply adjust your glob.

If not, there are some other ways:

tail -f `ls -l /var/logs/myLog* |grep -v .gz$`

or, using xargs:

ls /var/logs/myLog* | grep -v .gz$ | xargs tail -f
Related Topic