技术小黑屋

BashBites:Check Files

Check a file exists

1
2
3
4
5
6
7
#!/bin/bash
if [[ -e /tmp/adb.log  ]]
then
    echo "Exists"
else
    echo "Not Exists"
fi

Check Empty String

1
2
3
4
5
6
if [[ -z "$emptyString"  ]]
then
    echo "Empty"
else
    echo "Not Empty"
fi

Here is a reference material from Stackoverflowhttp://stackoverflow.com/questions/3767267/check-if-file-exists

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-d FILE
    FILE exists and is a directory
-e FILE
    FILE exists
-f FILE
    FILE exists and is a regular file
-h FILE
    FILE exists and is a symbolic link (same as -L)
-r FILE
    FILE exists and is readable
-s FILE
    FILE exists and has a size greater than zero
-w FILE
    FILE exists and is writable
-x FILE
    FILE exists and is executable
-z STRING
    the length of STRING is zero

For more detailed information, please visit http://linux.about.com/library/cmd/blcmdl1_test.htm

Others





快来解锁最新版 Typora,新用户券后仅需 84 元!
如何便宜的购买 office 365 ?
新版赤友 NTFS 助手来袭,正版超低价