size of files linux 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 the size of files in a directory linux

# Displays all the files and sizes in MB or GB
du -h --max-depth=1

Example 3: linux command for file size

#Get file size of each folder
du -bsh *

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