Shell脚本 输出当前目录下某文件夹中的非空文件

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 19:34   2554   0
#!/bin/bash</code>
$dirName
counter=0
prefix=`pwd`
for file in `ls $prefix/$1`;
        do
                counter=`expr $counter + 1`
                if [ -s $prefix/$file ]; then
                        echo $file "is not empty"
                fi
        done
echo "There are $counter files in "$prefix/$1" we need to process"

执行

./countfile.sh 文件夹名

该脚本可以得到当前目录下某个文件夹内的非空文件的文件名以及文件总数,这里不包含隐藏文件,若要得到隐藏文件可以修改ls命令
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP