The file system and file sizes
It's easy to learn how to deal with individual files and examine their size and content. You can use the same techniques to examine the contents of entire directories and the file system. Many new versions of UNIX can display this information in simple numbering formats, using letters to denote units.
df stands for Display Free disk space.
Using it is as simple as typing
df; you get information about the
amount of disk space in each file system on your machine, the amount
of space used, and the amount of space available. Most systems default
to display the values in 512KB blocks, which is hard to read.
-g to display information in gigabytes
-m to display information in megabytes.
Some systems have a
-h option, which stands for
human-readable. This makes
df use suffixes like G, M, and K, and it
displays each number in three or fewer digits. Type this command:
$ df -h
This is an example of output you might see on a simple server:
$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 7.9G 3.7G 3.9G 50% / none 3.9G 0 3.9G 0% /dev/shm /dev/sda3 24G 20G 1.9G 92% /export
If your system has
df, you can also use it with
ls. Type this command to see a detailed
listing with easy to read file sizes:
$ ls -lh
du is a third way to check file sizes, but it
has the added advantage of summing up directory sizes. It can also be
-h on some systems; otherwise, try using
-k, which gives results in 1024-byte
blocks. You can also use
-s and a filename or wildcard to specify
which directories and files you want to examine. Try this:
$ cd ~ $ du -sk * $ du -sh *
This is an example of output you might see in a home directory:
$ du -sk * 316468 OLD 637940 MyData1 571788 Code 12356364 Build 3224480 Hardened $ du -sh * 310M OLD 623M MyData1 559M Code 12G Build 3.1G Hardened
/dev directory holds special files called device files,
which, among other things, are used to access disk drives on your system.
To learn about the /dev directory, take another look
at the output of
df. This is different on every machine,
but it's important to note that
df shows results for each
file system on your computer. Unlike Windows-based computers, each mounted file system
is addressed from the system's root, which is denoted by a forward slash:
/. This is different from systems that separate disks
with drive letters, such as C, D, E, and so on.
In UNIX, it's common for SCSI (and SATA) disks to use device names, such as /dev/sda, /dev/sdb, /dev/sdc, and so on. A common device name for a CD-ROM drive is /dev/cdrom. These devices are mounted to directories so that they can be accessed without using the device name. Please consult the documentation for your flavor of UNIX to find out how devices on your system are labeled.
Any device can be mounted at any location
(any directory). For instance, it's common to mount a CD-ROM at
/mnt/cdrom. Some UNIX-like operating systems (such as
many versions of Linux and Mac OS) mount CD-ROMs automatically, but it's good
to learn how to use the
mount command either way.
Insert a CD-ROM, and type the following commands:
$ mount -t iso9660 /dev/cdrom /mnt/cdrom $ df $ ls /mnt/cdrom
Note: This will work only if /dev/cdrom and /mnt/cdrom exist on your system. If so, you see
in the output of the
df command that the CD-ROM is now
part of the file system. The
ls command should show
the contents of the CD-ROM drive you just mounted.
To unmount a device, most UNIX-like operating systems use
umount. The syntax is
followed by the mount point. If your previous
succeeded, type the following:
$ umount /mnt/cdrom $ df $ ls /mnt/cdrom
Note: You must not be in the mounted file system for the device to unmount
properly; otherwise, the system complains that the file system is busy. After
a proper execution of
command no longer shows the CD-ROM drive in the file system, and the
ls command shows that /mnt/cdrom
is now empty (because nothing is mounted there -- it's a normal directory).