64

In Linux, using the command tailf, how can I tail several log files that are inside a folder and in the subfolders?

the
  • 21,007
  • 11
  • 68
  • 101
nakib
  • 4,304
  • 2
  • 28
  • 39

5 Answers5

97

To log all the files inside a folder, you can go to the folder and write

tail -f *.log

To add the subfolders to the tailf command, use

tail -f **/*.log

Of course, the regular expression can be improved to match only specific file names.

Marc
  • 13,011
  • 11
  • 78
  • 98
nakib
  • 4,304
  • 2
  • 28
  • 39
32

This will recursively find all *.log files in current directory and its subfolders and tail them.

find . -type f \( -name "*.log" \) -exec tail -f "$file" {} +

Or shortly with xargs:

find . -name "*.log" | xargs tail -f

Noam Manos
  • 15,216
  • 3
  • 86
  • 85
cevaris
  • 5,671
  • 2
  • 49
  • 34
18

If all log files doesn't have same extension. You can use following command.

tail -f **/*
Farid Movsumov
  • 12,350
  • 8
  • 71
  • 97
2

To formalize the comment by luchaninov into an answer, multitail is useful if the set of filenames changes. In contrast, tail doesn't seem to be able to find new files that were created after it was started.

Installation:

sudo apt install multitail

Manual:

man multitail

Usage:

multitail -Q 4 '/path/to/logs/*.log'

The above command should check the quoted pattern every specified number of seconds for new files. The pattern must be quoted.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
1

This way find files recursively, print lines starting on line 5 in the each file and save on concat.txt

find . -type f \( -name "*.dat" \) -exec tail -n+5 -q "$file" {} + |tee concat.txt
Ivan Nack
  • 219
  • 2
  • 6