繁体   English   中英

命令脚本将文件识别为目录

[英]Command script recognizes files as directories

以下代码应计算目录包含的元素数量,但正确执行的同时,还将当前目录中的每个元素都识别为一个目录

我不知道如何不显示不是目录的元素。 我该怎么办?

代码在这里: http : //pastebin.com/9R4eB4Xn

termlog.txt: https ://justpaste.it/tgsl

如您所见,.jpg或.zip等某些文件被识别为目录。

您的echo "Element is a directory"位于ifthen then将其移动:

for i in *
do
  if [ ! -f "$i" ] && [ -d "$i" ]
    then
      echo "Element is a directory"
      FILES=`ls -l "$i" | wc -l`  # List the content of "$i" directory
                                  # and count the number of lines
      FILES2=`expr $FILES - 1`    # Substract one because one line is
                                  # occupied with the number of blocks
      echo "$i: $FILES2"          # Shows the name of the directory and
                                  # the number of inputs that it has
  fi
done
for i in `find DIRECTORY -maxdepth 2 -type d`; do echo "$i: `ls -1 $i | wc -l`"; done

如果仅对当前目录感兴趣,则将DIRECTORY替换为。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM