如何递归得到一个目录下所有日志文件
大家好,如下脚本只能的到当前Applog当前目录下的文档,但是不能够得到其下面子目录中的文件,此脚本如何编写,谢谢;
for f in /opt/Applog/*
do
echo $f
>$f
done
------解决方案--------------------使用递归
function SearchLog
{
Dir=$1
for f in $1/*
do
if [[ -d $f ]]
then
SearchLog $f
else
echo $f
>$f
fi
done
}
SearchLog /var/log
结果:
var/log/cron.2
/var/log/cron.3
/var/log/cron.4
/var/log/cups/access_log
/var/log/cups/access_log.1
/var/log/cups/access_log.2
/var/log/cups/access_log.3
/var/log/cups/access_log.4
/var/log/cups/error_log
/var/log/cups/error_log.1
/var/log/cups/error_log.2
/var/log/cups/error_log.3
/var/log/cups/error_log.4
/var/log/dmesg
/var/log/faillog
/var/log/ha-debug
/var/log/ha-debug.1
/var/log/ha-debug.2
/var/log/ha-debug.3
/var/log/ha-debug.4
/var/log/ha-log
/var/log/ha-log.1
/var/log/ha-log.2
/var/log/ha-log.3
/var/log/ha-log.4
/var/log/init.log
/var/log/kern
/var/log/lastlog
/var/log/mail/statistics
/var/log/maillog
/var/log/maillog.1
/var/log/maillog.2
/var/log/maillog.3
/var/log/maillog.4
/var/log/messages
/var/log/messages.1
/var/log/messages.2
/var/log/messages.3
/var/log/messages.4
------解决方案--------------------find /opt/Applog/
------解决方案--------------------推荐find命令,直接出来