![](/img/trans.png)
[英]Bash script to run diff command on files in two directories and provide custom side by side output?
[英]Command script recognizes files as directories
以下代碼應計算目錄包含的元素數量,但正確執行的同時,還將當前目錄中的每個元素都識別為一個目錄 。
我不知道如何不顯示不是目錄的元素。 我該怎么辦?
代碼在這里: http : //pastebin.com/9R4eB4Xn
termlog.txt: https ://justpaste.it/tgsl
如您所見,.jpg或.zip等某些文件被識別為目錄。
您的echo "Element is a directory"
位於if
和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.