get the size of a file in shell script code example

Example 1: 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

Example 2: find the size of file in linux

ls -l filename   #Displays Size of the specified file
ls -l *          #Displays Size of All the files in the current directory
ls -al *         #Displays Size of All the files including hidden files in the current directory
ls -al dir/      #Displays Size of All the files including hidden files in the 'dir' directory