get file size linux command code example
Example 1: linux file size
cd dir ; du -hsx * | sort -rh | head -20
# example output
# 300MB some_backup_file.log
# 1.8GB some_huge_file.war
Example 2: get file size in bash
# du is ok but is not accurate
# This is because it returns the disk usage for the target
# rather than the actual file size of the target.
# However, you can get more accurate results using the `--apparent-size` arg
du --apparent-size -h path/to/<file|folder>
# -h is tell it to print in a human readable format