How to tail all the log files inside a folder and subfolders?

UnixLoggingCommand LineTail

Unix Problem Overview


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

Unix Solutions


Solution 1 - Unix

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.

Solution 2 - Unix

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

Solution 3 - Unix

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

tail -f **/*

Solution 4 - Unix

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

Solution 5 - Unix

To formalize the comment by luchaninov into an answer, multitail is useful if the set of files change. 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnakibView Question on Stackoverflow
Solution 1 - UnixnakibView Answer on Stackoverflow
Solution 2 - UnixcevarisView Answer on Stackoverflow
Solution 3 - UnixFarid MovsumovView Answer on Stackoverflow
Solution 4 - UnixIvan NackView Answer on Stackoverflow
Solution 5 - UnixAsclepiusView Answer on Stackoverflow