Posted on 2006-04-12 00:13
安静的鼠窝 阅读(786)
评论(0) 编辑 收藏 所属分类:
Linux
linux shell 测试文件状态的命令选项:
条件 |
返回值 |
状态 |
test -e filename |
True |
文件存在 |
test -f filename |
True |
文件存在并且是一般文件 |
test -d filename |
True |
文件存在并且是目录文件 |
test -r filename |
True |
文件存在并且可读 |
test -w filename |
True |
文件存在并且可写 |
test -x filename |
True |
文件存在并且可执行 |
test -s filename |
True |
文件存在并且不为空 |
test -b filename |
True |
文件存在并且是特殊块 |
test -L filename |
True |
文件存在并且是符号链接 |
test -O filename |
True |
文件存在并且属于当前用户 |
test -G filename |
True |
文件存在并且属于当前用户组 |
test file1 -nt file2 |
True |
文件file1比文件file2新 |
test file1 -ot file2 |
True |
文件file1比文件file2旧 |
用法:
echo -n "Enter the file name: "
read fname
if [ -s $fname ]
then echo "$fname is exists and not empty!"
else
then echo "$fname is not exists and empty!"
fi