Bash Get the size of a file

Posted on May 17, 2017 at 10:39 am

With stat you can get the size of a file:

stat --printf="%s" /path/to/file

In Bash you can store the file size in a variable:

FILESIZE=$(stat -c%s "/path/to/file")

And you can check if a file is of 0 bytes:

if [ "$(stat -c%s "/path/to/file")" -eq 0 ]; then
    echo "The file is of 0 bytes"
    exit 1

Receive updates via email

Other Posts

Updated Posts