您的位置:首页 > 其它

计算/etc/目录所有*.conf配置文件所占总空间大小

2013-06-07 22:37 316 查看
脚本1:

计算/etc/目录中所有*.conf配置文件所占用的总空间大小
1.用vi创建一个名为confsize.sh脚本,截图如下:



内容如下:#!/bin/bashsizenums=$(ls -l $(find /etc/ -type f -a -name *.conf) | awk '{print $5}')total=0for i in $sizenumsdototal=$(expr $total + $i)doneecho "total size of conf files: $total bytes."

其中:
ls -l $(find /etc/ -type f -a -name *.conf) 用于统计。conf文件的信息



ls -l $(find /etc/ -type f -a -name *.conf) | awk '{print $5}' 列出每个文件所对应的大小




2.赋予confsize.sh的x权限,并执行脚本验证效果。




脚本2:

检查以bash为登录shell在/opt目录中的文件数量并列出具体的数值及对应的用户账户
1、用vi创建一个名为shell.sh脚本,截图如下:



内容如下:
#!/bin/bash
DIR="/opt/"
users=$(grep "bash$" /etc/passwd | awk -F: '{print $1}')
for username in $users
do
num=$(find $DIR -user $username | wc -l)
echo "$username have $num files."
done
2、在/opt目录下临时先创建一些测试文件,以备方便验证效果:



3、给脚本shell.sh增加x权限



4、执行脚本,查看执行后的信息




本文出自 “听闻” 博客,请务必保留此出处http://wenzhongxiang.blog.51cto.com/6370734/1218520
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐