linux shell实现统计/var/log目录文件

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 ~]# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值