log_count.sh
#!/bin/bash
clear
cd /var/log
sum=0
for i in $(ls -r *)
do
if [ -f $i ];then
let sum++
echo "FileName:" $i
fi
done
echo "The count of files:" $sum
验证:
[root@logstash ~]# sh log_count.sh
FileName: ztj.log
FileName: yum.log-20240117
FileName: yum.log
FileName: wtmp
FileName: vmware-vmtoolsd-root.log
FileName: vmware-vmsvc-root.log
FileName: vmware-vgauthsvc.log.0
FileName: vmware-network.log
FileName: vmware-network.9.log
FileName: vmware-network.8.log
FileName: vmware-network.7.log
FileName: vmware-network.6.log
FileName: vmware-network.5.log
FileName: vmware-network.4.log
FileName: vmware-network.3.log
FileName: vmware-network.2.log
FileName: vmware-network.1.log
FileName: tallylog
FileName: spooler-20240524
FileName: spooler-20240516
FileName: spooler-20240509
FileName: spooler-20240428
FileName: spooler
FileName: secure-20240524
FileName: secure-20240516
FileName: secure-20240509
FileName: secure-20240428
FileName: secure
FileName: messages-20240524
FileName: messages-20240516
FileName: messages-20240509
FileName: messages-20240428
FileName: messages
FileName: maillog-20240524
FileName: maillog-20240516
FileName: maillog-20240509
FileName: maillog-20240428
FileName: maillog
FileName: lastlog
FileName: grubby_prune_debug
FileName: firewalld
FileName: dmesg.old
FileName: dmesg
FileName: cron-20240524
FileName: cron-20240516
FileName: cron-20240509
FileName: cron-20240428
FileName: cron
FileName: btmp-20240509
FileName: btmp
FileName: boot.log-20240528
FileName: boot.log-20240527
FileName: boot.log-20240525
FileName: boot.log-20240524
FileName: boot.log-20240522
FileName: boot.log-20240521
FileName: boot.log-20240520
FileName: boot.log
The count of files: 58
[root@logstash ~]#