Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

How to Display File Size in KB, MB or GB in Linux Terminal

October 18, 2023
in Blog, Linux
0
ADVERTISEMENT

Table of Contents

Display File Size in KB, MB or GB in Linux Terminal

You probably already know that you can use ls command with long listing option -l to show file size in Linux.

ls -l /opt/sys/

But unfortunately, the long listing shows the file size in blocks and that’s not of much use to us humans.

root@vps:~# ls -l /opt/sys/
total 5655032
-rw-r--r-- 1 root root    3999808 Aug  4 13:37 AnyDesk.exe
-rw-r----- 1 root root      35622 Aug  4 13:37 auth.log
-rw-r--r-- 1 root root   96000792 Aug  4 13:37 balenaEtcher-1.10.2-x64.AppImage
-rw-r--r-- 1 root root       9477 Aug  4 13:37 cert1.zip
-rw-r--r-- 1 root root     100936 Aug  4 13:37 dmesg
-rw-r--r-- 1 root root  165841568 Aug  4 13:37 ExpanDrive_Setup_2022.7.1.exe
-rw-r--r-- 1 root root          2 Aug  4 13:48 install.sh
drwxr-xr-x 2 root root       4096 Aug  4 13:45 new_dir
-rw-r--r-- 1 root root 1697906688 Aug  4 13:37 ubuntu-16.04.7-desktop-amd64.iso
-rw-r--r-- 1 root root 3826831360 Aug  4 13:41 ubuntu-22.04.1-desktop-amd64.iso

The good thing is that you can combine the option -l with -h to show the file size in a human-readable format.

ls -lh /opt/sys

As you can see, it is better to display file size in a human-readable format. File sizes are now displayed in K (for KB), M for (MB). If the file size is in Bytes, it is not displayed with any suffix. In this example, install.sh is 2 Bytes in size.

root@vps:~# ls -lh /opt/sys/
total 5.4G
-rw-r--r-- 1 root root 3.9M Aug  4 13:37 AnyDesk.exe
-rw-r----- 1 root root  35K Aug  4 13:37 auth.log
-rw-r--r-- 1 root root  92M Aug  4 13:37 balenaEtcher-1.10.2-x64.AppImage
-rw-r--r-- 1 root root 9.3K Aug  4 13:37 cert1.zip
-rw-r--r-- 1 root root  99K Aug  4 13:37 dmesg
-rw-r--r-- 1 root root 159M Aug  4 13:37 ExpanDrive_Setup_2022.7.1.exe
-rw-r--r-- 1 root root    2 Aug  4 13:48 install.sh
drwxr-xr-x 2 root root 4.0K Aug  4 13:45 new_dir
-rw-r--r-- 1 root root 1.6G Aug  4 13:37 ubuntu-16.04.7-desktop-amd64.iso
-rw-r--r-- 1 root root 3.6G Aug  4 13:41 ubuntu-22.04.1-desktop-amd64.iso

Did you notice the size of new_dir directory? It is 4 KB. If you use ls -lh command on directories, it always shows the size of directory as 4.0 K.

-rw-r--r-- 1 root root 159M Aug  4 13:37 ExpanDrive_Setup_2022.7.1.exe
-rw-r--r-- 1 root root    2 Aug  4 13:48 install.sh
drwxr-xr-x 2 root root 4.0K Aug  4 13:45 new_dir
-rw-r--r-- 1 root root 1.6G Aug  4 13:37 ubuntu-16.04.7-desktop-amd64.iso

You’ll have to use du command to get the real size of a directory in Linux.

du -h /opt/sys/new_dir/

This is the output for the new_dir directory.

root@vps:~# du -h /opt/sys/new_dir/
2.6M    /opt/sys/new_dir/ACCDownload_20230804152427/Audio
2.6M    /opt/sys/new_dir/ACCDownload_20230804152427
804K    /opt/sys/new_dir/ACCDownload_20230804143438/Audio
812K    /opt/sys/new_dir/ACCDownload_20230804143438
84M     /opt/sys/new_dir/

If you find the output of the du command too verbose and would like to see just the total size of the directory in a human readable format, you can use the sum option -s.

du -sh /opt/sys/new_dir/
84M     /opt/sys/new_dir/

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Deploy Software Using Group Policy GPO (MSI)

Next Post

How to Check Windows 10 LTSC Version and Edition

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

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

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory