如何将旋转的日志重新连接在一起以制作原始文件?
huali-access.log huali-access.log.15 huali-access.log.21 huali-access.log.28 huali-access.log.34 huali-access.log.40 huali-access.log.47 huali-access.log.6
huali-access.log.1 huali-access.log.16 huali-access.log.22 huali-access.log.29 huali-access.log.35 huali-access.log.41 huali-access.log.48 huali-access.log.7
huali-access.log.10 huali-access.log.17 huali-access.log.23 huali-access.log.3 huali-access.log.36 huali-access.log.42 huali-access.log.49 huali-access.log.8
huali-access.log.11 huali-access.log.18 huali-access.log.24 huali-access.log.30 huali-access.log.37 huali-access.log.43 huali-access.log.5 huali-access.log.9
huali-access.log.12 huali-access.log.19 huali-access.log.25 huali-access.log.31 huali-access.log.38 huali-access.log.44 huali-access.log.50
huali-access.log.13 huali-access.log.2 huali-access.log.26 huali-access.log.32 huali-access.log.39 huali-access.log.45 huali-access.log.51
huali-access.log.14 huali-access.log.20 huali-access.log.27 huali-access.log.33 huali-access.log.4 huali-access.log.46 huali-access.log.52
答案1
像这样:
cat huali-access.log* > merged-huali-access.log
或者确保其按时间顺序排列:
echo -n "" > merged-huali-access.log # creating new file and making sure its empty
for i in {1..52}
do
cat huali-access.log.${i} >> merged-huali-access.log
done
cat huali-access.log >> merged-huali-access.log
答案2
如果文件设置了正确的修改时间(例如,你没有在没有注意保留修改时间的情况下复制它们),则可以使用
cat $(ls -t huali-access.log*) > output.log
ls 中的选项-t
将按修改时间对其进行排序。
答案3
来自@mauro.stettler,修复了文件顺序问题,并使其变得通用:
for LOG in *.log; do
( for i in {100..1}; do
F=${LOG}.${i};
[ -e $F ] && cat $F;
done ; cat ${LOG} ) > aggregated_${LOG};
done
或者您可以在访问日志上使用,它不像其他的那么通用,无法应用于任何日志,并且不能在不同的月份中使用:
cat accesslog.log* | sort -nk 4 > aggregated_accesslog.log
答案4
ls -1t *.access.log* | xargs zcat > access.all.log