显示所有目录和文件,也可读写和可执行文件

时间:2014-04-04 06:02:43

标签: unix

#!/bin/sh

LOCATION=$1

if [ "$#" -ne "1" ]
then
echo "Usage: test1 <directory_name>"

else
echo "Number of directories:` find -type d | wc -l `"
echo "Number of files: ` find -type f | wc -l`"
echo "Number of readable:` find -perm -g+r | wc -l`"
echo "Number of writable:` find -perm -g+w | wc -l`"
echo "Number of executable:` find -perm -g+x | wc -l`"
fi

这段代码有什么问题吗?当我输入./test1

时,我希望它显示所有目录,文件可读,可写和可执行

1 个答案:

答案 0 :(得分:0)

您需要在LOCATION命令中添加find。如果你没有给出任何值,那么它将开始以递归方式从当前目录中查找文件。

你的脚本应该是,

#!/bin/bash 
LOCATION=$1

if [ "$#" -ne "1" ]
then
   echo "Usage: test1 <directory_name>"    
else
   echo "Number of directories: $(find $LOCATION -type d | wc -l)"
   echo "Number of files: $(find $LOCATION -type f | wc -l)"
   echo "Number of readable:$(find $LOCATION -perm -g+r | wc -l)"
   echo "Number of writable: $(find $LOCATION -perm -g+w | wc -l)"
   echo "Number of executable: $(find $LOCATION -perm -g+x | wc -l)"
fi