script checking file exists
This question already has an answer here:
No need to use find
in case your file is in current path itself, following may help you.
#!/bin/bash
filename=$1
if [[ -f "$filename" ]]; then
echo "file exists"
else
echo "file does not exists"
fi
Then run script as script.ksh file_name
Also in case you need to verify if file exists and is having some size then change -f
to -s
in above code.
You could also do man test
for checking all these kind of conditions too in your box.
上一篇: shell脚本删除文件,如果它已经存在
下一篇: 脚本检查文件存在