How to retrieve if a file exists or file size is 0

Here are the codes of shell script to retrieve the existence of the file and file size is 0 or not.

File does NOT exist

if [ ! -e /path/to/file/hoge.txt ]; then
    # Process when the file doesn't exist
fi


File size is NOT 0

if [ ! -s /path/to/file/hoge.txt ]; then
    # Process when the file size is 0
fi
If you liked this article

Let's subscribe the updates of Scuti!
Share on Google Plus

About Tomohide Kakeya

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 Comments:

Post a Comment