TopL TopM TopR
MiddleL

How Big Is that File?

There are a few ways of checking the size of a file. Knowing them can be especially helpful if you’re planning to move files to a new file system or are working out how much disk space you need for a copy or a backup.

The ls –l command shows you the size of a file in bytes:

ls -l dvdimage.iso
-rw-r-----    1 root     system   3607250944 Jul 19 14:16 dvdimage.iso

To display the file size in kilobytes (KB), use the –s flag:

ls –s dvdimage.iso
3522716 dvdimage.iso

Disk Usage (du) by File

If you want that in Gigabytes (GB), you can do the calculation yourself, but there’s another, simpler way: use the du command. You can pass the file name as a parameter to du, and use the -g flag to report the size in GB:

du –g dvdimage.iso
3.36 dvdimage.iso

You can also display the size in MB using the –m flag:

du –m dvdimage.iso
3440.15 dvdimage.iso

To display in kilobytes, use du –k filename, which is equivalent to doing ls –s filename.

Where Does the File Really Reside?

You may find that a file is growing but the file system it belongs to isn't changing at all. That can happen if one of the file's parent directories is actually a symbolic link to a different file system.

For example, suppose you have two file systems: /usr/sap and /sapmnt. The file here:

/usr/sap/BWT/SYS/global/SLOGJO

looks to belong to the file system /usr/sap. But in fact, the file's parent directory /usr/sap/BWT/SYS/global is symbolically linked to /sapmnt/BWT/global. And that directory is in a different file system: /sapmnt.

ls -l /usr/sap/BWT/SYS/global
lrwxrwxrwx 1 root system 18 Mar 30 15:23 /usr/sap/BWT/SYS/global -> /sapmnt/BWT/global

Who would have guessed that?

You can see what file system a file really belongs to by running df with the file name itself:

df /usr/sap/BWT/SYS/global/SLOGJO
Filesystem 512-blocks Free %Used Iused %Iused Mounted on
/dev/sapmnt 10485760 6785000 36% 6312 1% /sapmnt/BWT

When you want to address the space issue caused by a large file, you need to be sure you are looking at the right file system. df filename can help you here.

This tip about df can be helpful if you have many nested file systems or NFS mounts. If you're used to running df and then scanning down a list of mount points with a jagged edge display, using df filename can save you some eye strain. And, as with du, you can display the file system sizes in GB (df -g), KB (df -k) or MB (df -m).

Resources

Anthony English is an AIX / Power Systems engineer working in Sydney. Follow him on Twitter @AIXDownUnder.

Comments

Was it good for you, too?Join the discussion » ,but you need to login first before you make comments.

     

    Other Recent Comments

    1. Re: Easy Ways to Trace VSCSI Configuration with AIX

      No Anthony, it's not so obvious. As you see, I've removed first paths and after that I changed vscsi...

      --Andrey Klyachkin

    2. Re: Easy Ways to Trace VSCSI Configuration with AIX

      Thanks, Andrey. Your test shows that if one path is down, then its corresponding VSCSI adapter isn't...

      --Anthony English

    3. Re: Easy Ways to Trace VSCSI Configuration with AIX

      Test with rmpath/cvai:# lspath -l hdisk1 -F parentvscsi0vscsi1# lspath -l hdisk0 -F parentvscsi0vscs...

      --Andrey Klyachkin

    4. Re: IBM Reveals PowerLinux Details and Pricing

      Thanks for the tip, Bill -- much appreciated! (I must say, though, we'll have to wrangle a few Power...

      --Chris Maxcer

    5. Re: IBM Reveals PowerLinux Details and Pricing

      http://www.ibm.com/developerworks/group/tpl

      --Bill Buros

    Google Links

    Sponsored Links

    Featured Links

    MiddleR
    BottomL BottomM BottomR

    © Penton Media, Inc.