我正在尝试创建一个脚本,它遍历存档位置并计算有多少文件。
这就是我所要做的。
#!/bin/bash
archive_location="location/archive/"
count=0
for files in $archive_location/* $archive_location/.*
do
count=$($count+1)
done
echo "File count: " $count
当我运行文件时,我得到 line 8: 0+1: command not found
& line 8: +1: command not found
请帮帮我。这是我第一次创建 bash 脚本。
最佳答案
你可以通过wc
运行find
find /path/to/search -type f | wc -l
编辑:
由于您需要编写一个循环,因此您需要将计数器更正为以下之一:
count=$((count+1))
或
let count=$count+1
或者为了性能声明 count
为一个整数,然后你可以简单地使用 +=
运算符:
declare -i count
count+=1
关于linux - 统计文件的脚本 (Bash),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46210312/