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.