测试是否存在多个文件 [英] Test if multiple files exist
本文介绍了测试是否存在多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用测试命令处理任意数量的文件(由regexp传入参数)
How can i use test command for arbitrary number of files, passed in argument by regexp
例如:
test -f /var/log/apache2/access.log.* && echo "exists one or more files"
但出现打印错误: bash:测试:参数过多
推荐答案
为避免参数过多错误",您需要xargs.不幸的是, test -f
不支持多个文件.以下一线应能正常工作:
To avoid "too many arguments error", you need xargs. Unfortunately, test -f
doesn't support multiple files. The following one-liner should work:
for i in /var/log/apache2/access.log.*; do test -f "$i" && echo "exists one or more files" && break; done
BTW,/var/log/apache2/access.log.*
被称为shell globbing,而不是regexp,请检查以下内容:
BTW, /var/log/apache2/access.log.*
is called shell-globbing, not regexp, please check this: Confusion with shell-globbing wildcards and Regex.
这篇关于测试是否存在多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文