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

守給你的承諾、 提交于 2019-12-03 04:06:52

问题


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


回答1:


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

tailf *.log

To add the subfolders to the tailf command, use

tailf **/*.log

Instead of tailf you can also use tail -f. Of course, the regular expression can be improved to match only specific file names.




回答2:


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




回答3:


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

tail -f **/*



回答4:


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


来源:https://stackoverflow.com/questions/18321336/how-to-tail-all-the-log-files-inside-a-folder-and-subfolders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!