Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
Linux ›
Command to Display Directory Sizes in Linux

Command to Display Directory Sizes in Linux

October 25, 2010 Linux Jesin A Leave a Comment

linux category thumbnail

Even though Linux has developed so much in terms of GUI which has become comparable to the latest Aero theme from Microsoft’s stables (especially in KDE environment) the command line becomes an inevitable tool for performing advanced administrative tasks like setting user quotas, compiling from the source to name it a few. But unlike the command line in windows, Linux command line works differently. A good example is showing the sizes of directories while listing the contents. The “ls” command in Linux shows a list of files and directories in the present directory but doesn’t show the sizes of directories and the file sizes are shown in bytes which makes it difficult to read and understand. So the correct command for this purpose is “du“

Display sizes of all files and directories

Just entering the du command will show the entire list of files and directories in the current directory with their sizes in KB, the last line shows the size of the entire directory without any units. Not so useful isn’t it ? Lets move on to something more useful.

Display sizes in human readable format

So earlier when the sizes of the directories were displayed it was difficult to interpret whether the displayed size was in KB or MB and several digits were displayed for files of huge sizes which would’ve left you confused. A parameter -h will display sizes in KB, MB or GB according to the file size which makes it human readable.

Look at the screenshot below for du -h in action

linux-du-command-h-parameter
The du -h command displays the file and directory sizes in units

Display the size in one line

In the previous examples you would’ve noted that the entire list of files and directories in the current location are displayed. What if you only need the size of the current directory you are in ? Use the -s parameter and a single line showing the size is displayed. This parameter can be combined with -h to display the size in human readable format.

Type du -sh to display the size in one line in human readable format

linux du command sh parameter
Use the -s parameter to display the size in one line

Display the size of the specified directory

Till now we have been seeing how to display the size of the present working directory, now we’ll see how to specify the particular directory for which the size should be displayed. The syntax is du [parameters] [path/to/directory]

The screenshot below shows the command du -sh /etc in action

linux du command sh parameter directory specified
The size of the specified directory is displayed in human readable format

You aren’t limited to only these options just type du –help to get a complete list of parameters for the du command.

Related posts:

linux category thumbnailHow to make undeletable files and directories in Linux linux category thumbnailChange Home Directory in Linux linux category thumbnailLinux ACL Tutorial linux category thumbnailSetup Linux DNS Server for Windows Active Directory linux category thumbnailMount an ISO file in Linux

Tags: linux, linux commands

Leave a Reply Cancel reply

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

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.