2

I want to live tail from three different folders with certain files included & excluded.
Folder 1:

  • Path: /var/www/app/var/log/
  • Exclude only: file1.log & file2.log

Folder 2:

  • Path: /var/log/web/log/
  • Include only: error.log

Folder 3:

  • Path: /var/log/service/log/
  • Include only: app1.error.log & app2.error.log

How would I tail from three different folders with inclusion and exclusion of some files in one tail command?

tail -f ???

Tried so far

tail -f /var/www/app/var/log/!(file1,file2).log /var/log/web/log/error.log /var/log/service/log/{app1,app2}.log 

But this doesn't work. I feel need to use find + tail

2
  • What have you tried? Mar 17, 2021 at 7:36
  • @NasirRiley Updated my hit n trials
    – MagePsycho
    Mar 17, 2021 at 8:02

2 Answers 2

1

Use my answer to your not-that-different question on SU to create three find commands that will find the files you're after. Then:

{ find … -print0 ; find … -print0 ; find … -print0 ; } | xargs -r -0 tail -F

Notes:

  • -F because of this: How to do a tail -f of log rotated files?
  • find commands run just once. If a new file appears whose name would have been matched but didn't exist at the time, then tail will ignore it. In other words: when tail starts all of its arguments are fixed, the file-to-be is not among them.
  • If the results form finds exceed the limit then xarg will run more than one tail (by default not in parallel though). Certainly you don't want this. Hopefully your finds will find a reasonable number of files and the limit will not be exceeded.
  • find -print0 and xargs -r -0 are not portable. You tagged ; in Ubuntu they will work.
1
  • That worked like a charm. Not sure how effective is the pipeline with exec command instead of xargs
    – MagePsycho
    Mar 18, 2021 at 13:18
0

Tail all of the files you want... output each tail to a file... tail the new file.

tail -f /var/log/large.log > ~/full.log && tail -f /var/log/medium.log > ~/full.log && tail -f ~/full.log

you can run it as one command but it looks a lil funky at first... but you could run it in another tty if you wanted and just tail the full log where you want it to look good.

2
  • you cant run it with the && sorry, you have to run it with a singular & or a nohup. Mar 18, 2021 at 10:42
  • the && will wait until the first tail is done... Mar 18, 2021 at 10:43

You must log in to answer this question.

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