When you want to investigate a list of files and their respective sizes, it can be unwieldy to print the size in the default byte format while using the ‘ls’ command in Linux. Today, I’ll show you how to present the data in a more human-readable manner using ‘ls -lah’.
Listing Files and Their Data Format (KB, MB, GB) using ‘ls -lah’
We can use the ‘ls -lah’ command to print a list of files and their prefixed data format (KB, MB, GB)
The ‘ls -lah’ command displays the file size in the fifth column, similar to the traditional ‘ls -all’ command, e.g.
-rw-r--r-- 1 root root 165 2011-04-29 21:36 shells drwxr-xr-x 2 root root 4.0K 2011-04-29 21:36 skel drwxr-xr-x 2 root root 4.0K 2012-10-23 01:14 ssh drwxr-xr-x 4 root root 4.0K 2012-10-18 07:29 ssl -r--r----- 1 root root 574 2011-04-15 12:02 sudoers drwxr-xr-x 2 root root 4.0K 2012-10-18 07:29 sudoers.d -rw-r--r-- 1 root root 2.1K 2010-12-21 04:56 sysctl.conf drwxr-xr-x 2 root root 4.0K 2011-04-29 21:39 sysctl.d drwxr-xr-x 2 root root 4.0K 2011-04-29 21:39 terminfo -rw-r--r-- 1 root root 17 2012-10-18 07:27 timezone -rw-r--r-- 1 root root 1.3K 2011-03-01 00:45 ucf.conf drwxr-xr-x 3 root root 4.0K 2011-04-29 21:39 udev drwxr-xr-x 3 root root 4.0K 2012-10-18 08:12 ufw drwxr-xr-x 2 root root 4.0K 2011-04-29 21:36 update-motd.d
For more information regarding the flag use (l,a,h) please refer to the quick ‘ls’ reference table at the bottom of this post.
Traditional Listing of Files using ‘ls -all’
Comparatively, we’ll print a list of files using the traditional ‘ls -all’ command:
-rw-r--r-- 1 root root 165 2011-04-29 21:36 shells drwxr-xr-x 2 root root 4096 2011-04-29 21:36 skel drwxr-xr-x 2 root root 4096 2012-10-23 01:14 ssh drwxr-xr-x 4 root root 4096 2012-10-18 07:29 ssl -r--r----- 1 root root 574 2011-04-15 12:02 sudoers drwxr-xr-x 2 root root 4096 2012-10-18 07:29 sudoers.d -rw-r--r-- 1 root root 2083 2010-12-21 04:56 sysctl.conf drwxr-xr-x 2 root root 4096 2011-04-29 21:39 sysctl.d drwxr-xr-x 2 root root 4096 2011-04-29 21:39 terminfo -rw-r--r-- 1 root root 17 2012-10-18 07:27 timezone -rw-r--r-- 1 root root 1260 2011-03-01 00:45 ucf.conf drwxr-xr-x 3 root root 4096 2011-04-29 21:39 udev drwxr-xr-x 3 root root 4096 2012-10-18 08:12 ufw drwxr-xr-x 2 root root 4096 2011-04-29 21:36 update-motd.d
Linux ‘ls’ Flags Quick Reference Table
| Flag | Description | Example |
|---|---|---|
| -l | Displays file types, owner, group, size, date and filename. | ls -l |
| -a | Displays all files, including hidden files (suffixed with “.”). | ls -a |
| -h | Displays files with human readable format, e.g. 1k, 100MB, 1G. | ls -h |
