File Size and Free Space


Often, it's necessary to understand how large files are and to know how much space they're taking up on the hard disk. In addition, it's often handy to know how much free space is left on a disk.

Viewing File Sizes

Using the ls -l command option will tell you how large each file is in terms of bytes. Adding the -h option converts these file sizes to kilobytes, megabytes, and even gigabytes, depending on how large they are.

In order to get an idea of which are the largest files and which are the smallest, you can add the -S command option. This will order the files in the list in terms of the largest and smallest files.

The following will return a list of all the files in the current directory, in order of size (largest first), detailing the sizes in kilobytes, megabytes, or gigabytes:

ls -Slh 

There's another more powerful way of presenting this information: using the du command, which stands for disk usage. When used on its own without command switches, du simply presents the size of directories alongside their names (starting in the current directory). It will show any hidden directories (directories whose names start with a period), and will also present a total at the end of the list. This will probably be quite a long list. Once again, you can add the -h command option to force the du command to produce human-readable measurements of kilobytes and megabytes.

If you specify a file or directory when using the du command, along with the –s command option, you can find out its total file size:

du -sh mydirectoryname

This will show the size taken up on the disk by mydirectoryname, adding to the total any files or subdirectories it contains.

However, du is limited by the same file permission problems as the find tool, as shown in Figure 15-6. If you run du as an ordinary user, it won't be able to calculate the total for any directories you don't have permission to access. Therefore, you might consider running the command as root.

image from book
Figure 15-6. The du command shows the size of a file, and the df command can be used to gauge the amount of free space on the disk.

Finding Out the Amount of Free Space

What if you want to find out how much free space there is left on the disk? In this case, you can use the df command. This command is also demonstrated in Figure 15-6.

The df command works on a partition-by-partition basis. Typing it at the command prompt will show you how much space is free on the entire disk. Once again, you can add the –h option to the df command to have the file sizes returned in megabytes and gigabytes (and even terabytes if your hard disk is big enough!).

Note 

There's as much space free in any directory as there is space on the disk, which is why df displays data about the entire partition. If you're using a system managed by a system administrator within a business environment, you might find that quotas have been used to limit how much disk space you can take up. However, if you're using a desktop PC and are the only user, this won't be activated.




Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net