Display file or directory size


This post goes over how to a display the size of a file or directory in human-readable format.

ls

To display a human-readable file size in long format using ls:

ls -lh <file>

To display the size of files in a directory:

ls -lh <directory>

sort

To sort by size in descending order:

ls -lhS <directory>

To sort by size in ascending order:

ls -lhrS <directory>

du

To get the size of a directory, use the du command:

du -sh <directory>


Please support this site and join our Discord!