shell 脚本统计当前目录下普通文件个数

来源:互联网 发布:淘宝开店要钱吗 编辑:程序博客网 时间:2024/05/21 15:03

hell 脚本统计当前目录下普通文件个数

#!/bin/bash  #The shell function used to count how many files in the current dirctory  count=0  for files in *  do  if [ -f "$files" ]  then  count=`expr $count + 1`  fi  done  echo "There are $count files in `pwd`" 

[root@localhost sourcetemp]# ./filecount
There are 75 files in /mnt/hgfs/share/sourcetemp

注意问题:

1.for循环后跟do 配合done结束,结束for循环,需注意done的位置。

2.=赋值左右没有空格。

3.· ·是tab键上的符号,而不是' '。

4.文件状态:
********************************************
- d 目录
- s 文件长度大于0、非空
- f 正规文件
- w 可写
- L 符号连接
- u 文件有s u i d位设置
- r 可读
- x 可执行
*********************************************************

0 0
原创粉丝点击