How to get the file size in BYTES or the smallest possible unit in SOLARIS

advertisements

Is there any script or command to get the FOLDER size in BYTES or BITS so that every small change in the files in the folder is reflected by checking the Folder size in SOLARIS/


The directory size doesn't change when you add few bytes to files. Files are allocated in fragments / blocks.

Should you want the cumulative size of all files in a directory, you have to compute it yourself. See https://superuser.com/a/603302/19279

Note that this size doesn't represent what the files are using, which is usually larger but can also be smaller depending on various factors.

Edit:

Here is a simplified solution giving the size in bytes:

#!/bin/sh
find ${1:-.} -type f -exec ls -lnq {} \+ | awk '{sum+=$5} END{print sum}'