@ysongzybl
2015-05-06T20:05:59.000000Z
字数 651
阅读 6567
bash
if ls /path/to/your/files* 1> /dev/null 2>&1; then
echo "files do exist"
else
echo "files do not exist"
fi
Or better one:
for f in /path/to/your/files*; do
## Check if the glob gets expanded to existing files.
## If not, f here will be exactly the pattern above
## and the exists test will evaluate to false.
[ -e "$f" ] && echo "files do exist" || echo "files do not exist"
## This is all we needed to know, so we can break after the first iteration
break
done
For example, I want to remove all files with name prefix "aabb" at current foler, then I write script as:
for f in ./aabb*; do
if [ -e "$f" ];
then
rm $f
fi
done
http://stackoverflow.com/questions/6363441/check-if-a-file-exists-with-wildcard-in-shell-script