linux相关面试题(shell编程)

来源:互联网 发布:淘宝定制可以退款吗 编辑:程序博客网 时间:2024/06/06 09:25

最近在学习shell编程,网上看到一些linux的面试题,就拿来做一做。求更好的实现方式 。

(1)统计/var/log/下文件个数

#!/bin/sh
count=0
path='/var/log'
echo "the directory you want to statistic is $path"
allFile=`ls $path`
for file in $allFile
do
        if [ -e "$path/$file" ]
        then
                count=`expr $count + 1`
        fi
done
echo "There are $count files in $path"

运行结果:




0 0