3

As part of my daily dev tasks (on a Mac running OS 10.12.3) I run tail -f * in my log folder from Terminal. The folder contains about 15 different files. How can I alter this command to monitor changes to all files but one from *? Suppose the only file I'd like to exclude from * is called Repetitive.log.

Apologies for the very basic question, I looked around for it and didn't see a duplicate. Reposted from https://stackoverflow.com/questions/42815599/exclude-files-from-the-catchall-symbol

6
  • +1; good question. While your question is on-topic for Super User, there may be a better chance you'll get an answer if you post it on Unix & Linux. If you so wish, you may post your question there and then delete it here. Please don't cross-post, though—having the same question on multiple sites at the same time is generally frowned upon. Mar 21, 2017 at 21:04
  • Or you may flag your own question as "in need of moderator intervention" and request migration to Unix & Linux Stack Exchange. I think the mods can do this for you, but am not sure. Mar 21, 2017 at 21:08
  • I've added some tags. This might increase your chances of getting upvotes and an answer. Mar 21, 2017 at 21:11
  • What shell are you using? help | head -n 5 will probably tell you. Mar 21, 2017 at 21:17
  • Very similar question at stackoverflow.com/questions/19429541/…
    – setempler
    Mar 21, 2017 at 22:37

2 Answers 2

2

If you are using bash as your shell, set the environment variable GLOBIGNORE to a colon-separated list of patterns which you want to not match when the shell is globbing, e.g.

$ export GLOBIGNORE=Repetitive.log
$ export GLOBIGNORE=somefile:anotherfile:abc*

From man bash:

   GLOBIGNORE
          A colon-separated list of  patterns  defining  the  set  of
          filenames  to be ignored by pathname expansion.  If a file-
          name matched by a pathname expansion pattern  also  matches
          one  of  the patterns in GLOBIGNORE, it is removed from the
          list of matches.
2

xargs is your friend! If not, find can also help.

Here are four approaches, using xargs, find ... -exec or extended pattern matching:

Use xargs via ls and grep

ls | grep -v Repetitive.log | xargs tail -f

Use xargs via find

find . -maxdepth 1 ! -name Repetitive.log | xargs tail -f

Use find with -exec argument

find . -maxdepth 1 ! -name Repetitive.log -exec tail -f {} \;

Use extended pattern matching in bash

Great answer, taken from https://stackoverflow.com/a/19429723/1862762.

shopt -s extglob
tail -f /directory/of/logfiles/!(Repetitive.log)

Note

For this task, I would prefer the xargs way, as it provides output from tail tagged with the respective file names. Using ls and grep seems more intuitive and easy to remember.

1
  • If you need to use sudo to access the files, you can wrap the command with sudo bash -c "<command>"
    – GammaGames
    Feb 24, 2022 at 17:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .