[英]Command script recognizes files as directories
The following code should count the number of elements that a directory contains, but as well as it does it correctly, it also recognizes every element inside the current directory as a directory . 以下代码应计算目录包含的元素数量,但正确执行的同时,还将当前目录中的每个元素都识别为一个目录 。
I don't know how not to show the elements that are not directories. 我不知道如何不显示不是目录的元素。 How could I do it?
我该怎么办?
Code is here: http://pastebin.com/9R4eB4Xn
代码在这里: http : //pastebin.com/9R4eB4Xn
termlog.txt: https://justpaste.it/tgsl
termlog.txt: https ://justpaste.it/tgsl
As you may see, some files like .jpg or .zip are recognized as directories. 如您所见,.jpg或.zip等某些文件被识别为目录。
Your echo "Element is a directory"
is between the if
and the then
. 您的
echo "Element is a directory"
位于if
和then
。 Move it after then
: 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.