• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Mister PKI

SSL Certificates * SSL Tools * Certificate Decoder

  • Buy SSL Certificates
  • Blog
  • OpenSSL
  • Keytool
  • SSL Tools
  • Donate

Linux ls human readable file size

February 9, 2023 by Mister PKI Leave a Comment

This article will demonstrate how to use the linux ls command to show a human readable file size in GB, MB, and K. The same command and set of options is used for showing each classification of size, but we have documented each of them separately for clarity.

ls in gigabytes

GB is short for gigabytes. A GB is equal to 1024 megabytes (MB) is equal to 1024 kilobytes (K or KB). If a file size is in upwards of gigabytes, it will show up with GB after the number.

To show results of the ls command in GB, run the following command.

ls -lah

The -h is key, which stands for human readable.

The other options are defined as:

  • -a – List all entries in the directory including the hidden files and sub directories
  • -l – Format into a long list

ls in megabytes

The command to show file size in megabytes with ls is the same as for gigabytes.

ls -lah

ls in kilobytes

The command to show file size in kilobytes with ls is the same as for gigabytes and megabytes.

ls -lah

ls shortcut alias

If you have a set of preferred options when using the ls command you can create an alias to automatically use those options each time. In our case, we simply want to override the ls command with the ls -lah options. The quickest way to do so is to run the following alias command:

alias ls='ls -lah'

The alias command is a temporary and not persistent command. The alias will only be created for the open terminal session. If you want the command to persist you will need to edit the .bashrc file.

vi ~/.bashrc

Conveniently, there is already a section with ls aliases. You should find the following section, at least for WSL2 on Windows using Ubuntu.

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

Simply add the previous alias to the list in the .bashrc file.

alias ls='ls -lah'

The change is saved, but you must either source the file or close and reopen your terminal.

source ~/.bashrc

With that, you’re on your way to quicker ls commands.

Conclusion – linux ls human readable

This article has demonstrated how to run ls to show human readable file sizes in gigabytes, megabytes, and kilobytes. Note that if no suffix is appended to the file size, it is less than a kilobyte and is being shown in the standard bytes format. Let us know in the comments if you have any questions or would like to see more examples of the ls command. Read our article on the du command for showing directory and file sizes or any other article.

linux

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Popular Posts

PKCS12

openssl s_client

Keytool

Keytool list

ECDSA vs RSA

OpenSSL

PKCS7

Certificate Decoder

Training Courses

Top online courses in IT & Software

Cyber Security Training

Udemy - The Complete Internet Security Privacy Course icon

Buy SSL Certificates

The SSL Store

Comodo Store

Sectigo Store

RapidSSL

Recent Posts

  • Linux ls human readable file size
  • Show linux directory size
  • Sendmail vs Postfix – Mail Transfer Agent Comparison
  • DNS Powershell
  • How to Install Apache for Linux

Footer

  • Twitter
  • YouTube

Pages

  • About Mister PKI
  • Blog
  • Compare and Buy Affordable PKI Certificates
  • Contact Us
  • Full Disclosure
  • Privacy Policy
  • SSL Tools – Certificate Decoder and Certificate Checker

Copyright © 2023