Quantcast
Channel: Day to day stuff
Viewing all articles
Browse latest Browse all 83

Getting size of a file in shell script

$
0
0
This is really too silly. There seems to be no consistent way to get the size of a file (in bytes) on multiple platforms. Here is a solution that works in bash on Linux (tested under Debian and Ubuntu) and BSD (tested under OSX): # Echo's size of a file (first argument). # Tested under Linux (Debian) and BSD (OSX). function filesize() { echo $(stat --format=%s "$1" 2>/dev/null || stat -f '%z

Viewing all articles
Browse latest Browse all 83

Trending Articles