I've been typing commands like the (the long way) for my whole life.

tail -f /var/log/syslog /var/log/mail.log /var/log/mail.err

This is probably a really basic question, but I had a hard time finding the answer.

Is there a regex way to match multiple files in the folder without retyping the location each time?

This saves me a few keystrokes, but not many

export LOGDIR=/var/log
tail -f $LOGDIR/syslog $LOGDIR/mail.log $LOGDIR/mail.err 

And sometimes I want multiple locations... I want to figure out something like this:

tail -f /var/log/(mail*|syslog|nginx/*)

(but actually have it work)

  • Note those are not regular expressions, but shell patterns.
    – Quasímodo
    Nov 21, 2020 at 17:49

3 Answers 3


Use brace-expansion.

tail -f /var/log/{mail*,syslog,nginx/*}


$ tree
├── mail.err
├── mail.log
├── nginx
│   ├── a
│   ├── b
│   └── c
├── notthis
└── syslog
$ echo {mail*,syslog,nginx/*}
mail.err mail.log syslog nginx/a nginx/b nginx/c
  • of course this is better answer than mine Nov 21, 2020 at 18:20

In bash:

shopt -s extglob ## enable extend-glob if not enabled; default is "on"
tail -f /var/log/+(syslog|mail.+(log|err))

or apparently:

tail -f /var/log/+(syslog|mail*)

Please note that these are filename globing and applicable only for the files, so you should not expect to have expansion on the path like in nginx/* you said; instead you can prefer to use brace-expansion based solution and answer given by Quasímodo or just explicitly separate that as another parameter to the command:

tail -f /var/log/+(syslog|mail*) /var/log/nginx/*
  • I couldn't make this work with subdirectories, I tried echo +(syslog|mail.+(log|err)|nginx/*). Did I miss something or is it not possible?
    – Quasímodo
    Nov 21, 2020 at 17:51
  • @Quasímodo not possible, that's for filename globing not the path Nov 21, 2020 at 17:53

Doing tail -f file1 file2 will follow file1 until "done" (never) before it gets to file2. However, multitail handles multiple files simultaneously. sudo apt install multitail;man multitail.

  • I've always used Ubuntu and I get updates from each file as it comes in. For real-time monitoring, this isn't an issue. Oct 14, 2021 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.