Shell script: get file size








stat -c %s /path/to/file
or
#!/bin/bash

path=/path/to/file
size=$(stat -c %s ${path})
if [[ $size -eq 0 ]]; then
    echo "${path} is a zero-size file."
fi
Note: If path directs to a directory, it will not fail nor return 0. It returns the block size associated with the directory. See this for more details.


No comments:

Post a Comment