
题主你好,
测试截图:
从测试截图可以看出, 我当前目录下只有1个文件,名叫lisi, 其它的都是文件夹(以"-"打头的是文件, 以"d"打头的是文件夹), 执行命令后, 可以看到, 结果是1.
-----
希望可以帮到题主, 欢迎追问.
在shell终端中输入下列命令:
# 在当前目录生成脚本文件 countfilecat >countfile <<SCRIPT
#!/bin/sh
find "\$@" -type f |
wc -l
SCRIPT
# 为脚本添加权限
chmod +x countfile
# 执行用例
./countfile ~
#!/bin/bashfor file in *
do
if [ $file = "AAA" ]then
# Check if it's a folder
detail=`ls -dl $file`
if [ ${detail:0:1} = "d" ]then
touch newfile
echo "New file created!"
break
fi
fi
done
或者:
-----------------------------------------------------
#!/bin/bash
ls -l|grep "^d.*"|while read line
do
filename=`echo "$line"|awk '{print $NF}'`
if [ $filename = "AAA" ]then
touch newfile
echo "New file created!"
break
fi
done
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)