如何对任意数量的文件使用 test
命令,使用带通配符的参数传入?
例如:
test -f /var/log/apache2/access.log.* && echo "exists one or more files"
目前,它打印
error: bash: test: too many arguments
最佳答案
这个解决方案在我看来更直观:
if [ `ls -1 /var/log/apache2/access.log.* 2>/dev/null | wc -l ` -gt 0 ];
then
echo "ok"
else
echo "ko"
fi
关于bash - 如何使用 Bash 脚本测试是否存在多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14765569/