In Linux, using the command tailf
, how can I tail several log files that are inside a folder and in the subfolders?
6 Answers
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.
-
1To to tail folder+ sub folders
tail -f ../logs/**/*log* ../logs/*log*
– so_mvCommented Dec 5, 2013 at 22:22 -
9Is there a way to tail all files and all new files (doesn't exist yet)? Commented Oct 29, 2014 at 20:53
-
7
multitail -Q 5 '/path/to/logs/*'
- where 5 is number of seconds to check for new files. Install it usingapt-get install multitail
oryum
or whatever. Commented Sep 10, 2015 at 10:43 -
5
tailf **/*.log
Works with only one level of sub-folders Commented Nov 22, 2017 at 9:36 -
thank you @luchaninov,
multitail
was exactly what I was looking for. If I had 5 files, for instance, I wanted to see all 5 of them on the terminal at once and only the last few lines of each as the data changed. Commented Sep 22, 2019 at 15:45
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
If all log files doesn't have same extension. You can use following command.
tail -f **/*
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.
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
One can try using & for that purpose in between the logs statements like
tail -f /app/temp/logs/C1/a.log & tail -f /app/temp/logs/C2/b.log