Terms of Use For FixedByVonnie

By proceeding to access fixedByVonnie.com, you expressly acknowledge, and agree to, all of the following:

fixedByVonnie.com is a personal website and blog owned by Security Plus Pro LLC, which is being presented for informational purposes only. The views on this website are solely those of the website owner (and not those of any employer or of any professional associations affiliated with the website owner).  Any views expressed in this website and any information presented on this website, or in any of its blog entries, should not be relied on for any purpose whatsoever other than as the personal opinions of the website owner.  The website owner expressly disclaims any and all liability for any information presented on this site.  The owner of this website and its blog posts shall not be held liable, and shall be held harmless, for any errors or omissions in any information or representations contained in this website, or in any of its blog entries.  The website owner also expressly disclaims any liability for the current or future availability of any such information. The website owner makes no representations as to the accuracy or completeness of any information on this website or which may be found by following any link on this website. The website owner shall not be held liable for any losses, injuries, damages, claims, or causes of action, from the display or use of any information on this website or in any of its blog entries. If you use the information on this website, or on any of its blog entries, you do so solely at your own risk.

How can I view the size of a file or folder in Linux using SSH? - fixedByVonnie

How can I view the size of a file or folder in Linux using SSH?

Let’s say you’ve got a shiny new VPS from DigitalOcean and just installed CentOS 6.5 and you’re ready to rumble.

You’re eyes are wide, you’ve got adrenaline coursing through your veins but now you’re staring at a black screen with a blinking cursor and wondering about the file and directory sizes on your server.

Is there a quick and easy way to grab this information from the command line?

Yup! Here’s how:

I just installed WordPress on my DigitalOcean webserver but since I only have 20GB’s of space I need to make sure I watch my storage limits.

If I simply type ls from the command prompt it just lists all my files but doesn’t show anything about file sizes.

CentOS 6.5 ls command

Of course I could add the -l (that’s a dash lowercase L) qualifier to get the full file readout but there are two problems with this approach:

  • File sizes are displayed in bytes which are harder to read than KB or MB
  • It isn’t convenient to list all file sizes when you just have one specific file in mind

This is what the same command looks like with the -l qualifier: ls -l.

I’ve highlighted the file sizes column in calming cerulean blue.

CentOS 6.5 File sizes with ls -l

As you can see, the ls -l command is better but still not ideal.

Here’s a better way:

Viewing the file size of a single file

Let’s say I just want see the file size of one file: wp-signup.php.  I can type this:

du -h wp-signup.php

du -h command

If you have more than one file just smash it on the end of the list.

du -h wp-signup.php wp-login.php

Using du -h to view filesizes of multiple files

So what’s all this du business about?

The du command (Disk Usage) estimates file space usage for files and directories.  I added the -h option to display the file size in a human readable format.  In other words, -h forces du to prints pretty sizes like 1K instead of 1024.

Now, if you compare the du output of 28K for wp-signup.php to the ls -l result of 25665 you’ll see it’s just an approximation.  But this will suffice for most purposes.

Viewing directory sizes

If you want to view the file size of a complete directory including all the files and subdirectories inside, just use the -sh options.

For example, now I want to view the size of my www folder so I type the following:

du -sh www

du -sh to view folder size

There you go! You can see my folder is only 21MBs so I’m good.

About

Connect with Vonnie on Twitter

Posted in Linux Tagged with:
  • Cron Matic

    thank you for your time.

  • George Chalhoub

    Amazing article, finally! Thank you. Will bookmark this page.

  • Pingback: download identity 2003()

  • Ngoãn Trần

    $ ls -lh
    Getting the list of files and folder with sizes in human readable format.
    Hope it helpful.