读取文件名,统计文件数量

# cat ./s1.sh
#!/bin/bash


filelist=$(ls ~/)

echo "-----------begin------------"
for file in $filelist
do
echo $file
if [ -f ~/$file ]

then echo "this is a file"

else echo "this is a dir"

fi

done

echo "-----------end------------"


# ./s1.sh
-----------begin------------
anaconda-ks.cfg
this is a file
apache-maven-3.1.1-bin.tar.gz
this is a file
apache-maven-3.2.5-bin.tar.gz
this is a file
Desktop
this is a dir
Documents
this is a dir
Downloads
this is a dir
forktest.py
this is a file
forktest.py~
this is a file
glibc-2.17
this is a dir
glibc-2.17.tar.gz
this is a file
glibc-2.9.tar.bz2
this is a file
glibc-linuxthreads-2.5.tar.bz2
this is a file
hadoop-2.6.0-src.tar.gz
this is a file
hadoopsrc
this is a dir
ifcfg-eth0
this is a file
ifcfg-lo
this is a file
install.log
this is a file


# ll
total 600
-rwxr-xr-x. 1 root root 47 May 3 05:43 calculate.sh
-rwxr-xr-x. 1 root root 200 May 3 06:10 canshu.sh
-rwxr-xr-x. 1 root root 84 Aug 23 08:16 cs.sh
-rwxr-xr-x. 1 root root 162 May 3 05:47 hello.sh
-rwxr-xr-x. 1 root root 227 May 3 06:22 readtest.sh
-rwxr-xr-x. 1 root root 246 Aug 31 08:23 s1.sh
-rw-r--r--. 1 root root 575289 May 9 19:22 services
-rw-r--r--. 1 root root 25 Aug 31 08:09 stest.txt
-rw-r--r--. 1 root root 69 May 4 07:09 student.txt
-rw-r--r--. 1 root root 140 May 9 18:18 vitest.txt
# ls -l | grep ^- | wc -l
10
#
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值