The df program displays the amount of free space

an article added by: Daniel K. at 11282007


In: Categories » Computers and technology » Linux Commands » The df program displays the amount of free space

The df program displays the amount of free space, partition by partition. The drives/partitions must be mounted in order to get this information. NFS information can be gathered this way, as well. Some parameters for df are listed here; additional (rarely used) options are listed in the df manual page.

To show the free space in a human-readable format for the file system on which /tmp is located, type this command:

    [michael@workbox michael]$ df -h /tmp

Synchronizing Disks: sync

Like most other modern operating systems, Linux maintains a disk cache to improve efficiency. The drawback, of course, is that not everything you want written to disk will have been written to disk at any given moment. To schedule the disk cache to be written out to disk, you use the sync command. If sync detects that writing the cache out to disk has already been scheduled, the kernel is instructed to immediately flush the cache. This command takes no command-line parameters. Type this command to ensure the disk cache has been flushed:

    [root@workbox /root]# sync ; sync

Tracking and Terminating Processes

Under Linux (and UNIX in general), each running program comprises at least one process. From the operating system’s standpoint, each process is independent of the others. Unless it specifically asks to share resources with other processes, a process is confined to the memory and CPU allocation assigned to it. Processes that overstep their memory allocation (which could potentially corrupt another running program and make the system unstable) are immediately killed. This method of handling processes has been a major contributor to the stability of UNIX systems: User applications cannot corrupt other user programs or the operating system. This section describes the tools used to list and manipulate processes. They are very important elements of a system administrator’s daily work.

Listing Processes: ps

The ps command lists all the processes in a system, their state, size, name, owner, CPU time, wall clock time, and much more. There are many command-line parameters available;

The most common set of parameters used with the ps command is –auxww. These parameters show all the processes (regardless of whether they have a controlling terminal), each process’s owners, and all the processes’ command-line parameters. Let’s examine the output of an invocation of ps –auxww.

    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 1 0.0 0.3 1096 476 ? S Jun10 0:04 init
    root 2 0.0 0.0 0 0 ? SW Jun10 0:00 [kflushd]
    root 3 0.0 0.0 0 0 ? SW Jun10 0:00 [kpiod]
    root 4 0.0 0.0 0 0 ? SW Jun10 0:00 [kswapd]
    root 5 0.0 0.0 0 0 ? SW< Jun10 0:00 [mdrecoveryd]
    root 102 0.0 0.2 1068 380 ? S Jun10 0:00 /usr/sbin/
    apmd -p 10 -w 5
    bin 253 0.0 0.2 1088 288 ? S Jun10 0:00 portmap
    root 300 0.0 0.4 1272 548 ? S Jun10 0:00 syslogd -m 0
    root 311 0.0 0.5 1376 668 ? S Jun10 0:00 klogd
    daemon 325 0.0 0.2 1112 284 ? S Jun10 0:00 /usr/sbin/atd
    root 339 0.0 0.4 1284 532 ? S Jun10 0:00 crond
    root 357 0.0 0.3 1232 508 ? S Jun10 0:00 inetd
    root 371 0.0 1.1 2528 1424 ? S Jun10 0:00 named
    root 385 0.0 0.4 1284 516 ? S Jun10 0:00 lpd
    root 399 0.0 0.8 2384 1116 ? S Jun10 0:00 httpd
    xfs 429 0.0 0.7 1988 908 ? S Jun10 0:00 xfs
    root 467 0.0 0.2 1060 384 tty2 S Jun10 0:00 /sbin/
    mingetty tty2
    root 468 0.0 0.2 1060 384 tty3 S Jun10 0:00 /sbin/
    mingetty tty3
    root 469 0.0 0.2 1060 384 tty4 S Jun10 0:00 /sbin/
    mingetty tty4
    root 470 0.0 0.2 1060 384 tty5 S Jun10 0:00 /sbin/
    mingetty tty5
    root 471 0.0 0.2 1060 384 tty6 S Jun10 0:00 /sbin/
    mingetty tty6
    root 473 0.0 0.0 1052 116 ? S Jun10 0:01 update
    (bdflush)
    root 853 0.0 0.7 1708 940 pts/1 S Jun10 0:00 BASH
    root 1199 0.0 0.7 1940 1012 pts/2 S Jun10 0:00 su
    root 1203 0.0 0.7 1700 920 pts/2 S Jun10 0:00 BASH
    root 1726 0.0 1.3 2824 1760 ? S Jun10 0:00 xterm
    root 1728 0.0 0.7 1716 940 pts/8 S Jun10 0:00 BASH
    root 1953 0.0 1.3 2832 1780 ? S Jun11 0:05 xterm
    root 1955 0.0 0.7 1724 972 pts/10 S Jun11 0:00 BASH
    nobody 6436 0.0 0.7 2572 988 ? S Jun13 0:00 httpd
    nobody 6437 0.0 0.7 2560 972 ? S Jun13 0:00 httpd
    nobody 6438 0.0 0.7 2560 976 ? S Jun13 0:00 httpd
    nobody 6439 0.0 0.7 2560 976 ? S Jun13 0:00 httpd
    nobody 6440 0.0 0.7 2560 976 ? S Jun13 0:00 httpd
    nobody 6441 0.0 0.7 2560 976 ? S Jun13 0:00 httpd
    root 16673 0.0 0.6 1936 840 pts/10 S Jun14 0:00 su -michael
    michael 16675 0.0 0.8 1960 1112 pts/10 S Jun14 0:00 -zsh
    root 18243 0.0 0.9 2144 1216 tty1 S Jun14 0:00 login --
    rwhite
    rwhite 18244 0.0 0.8 1940 1080 tty1 S Jun14 0:00 -tcsh

The very first line of the output provides column headers for the listing, as follows:

- Column 1: USER Who owns what process.

- Column 2: PID Process identification number.

- Column 3: %CPU Percentage of the CPU taken up by a process. Note: For a system with multiple processors, this column will add up to more than 100 percent.

- Column 4: %MEM Percentage of memory taken up by a process.

- Column 5: VSZ The amount of virtual memory a process is taking.

- Column 6: RSS The amount of actual (resident) memory a process is taking.

- Column 7: TTY The controlling terminal for a process. A question mark in this column means the process is no longer connected to a controlling terminal.

- Column 8: STAT The state of the process:

- S Process is sleeping. All processes that are ready to run (that is, being multitasked, and the CPU is currently focused elsewhere) will be asleep.

- R Process is actually on the CPU.

- D Uninterruptible sleep (usually I/O related).

- T Process is being traced by a debugger or has been stopped.

- Z Process has gone zombie. This means either (1) the parent process has not acknowledged the death of its child using the wait system call; or (2) the parent was improperly killed, and until the parent is completely killed, the init process (see Linux tutorial 8) cannot reap the child itself. A zombied process usually indicates poorly written software. In addition, the STAT entry for each process can take one of the following modifiers: W = No resident pages in memory (it has been completely swapped out); < = High-priority process; N = Low-priority task; L = Pages in memory are locked there (usually signifying the need for real-time functionality).

- Column 9: START Date the process was started.

- Column 10: TIME Amount of time the process has spent on the CPU.

- Column 11: COMMAND Name of the process and its command-line parameters.

legal notice

Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.

Useful tools and features

Link to this article from your page    Send this article to you or to a friend
If you like this article (tutorial), please link to it from your web page using the information above.

related articles

1. X offers the ability to display content on other hosts
Remote X Displays In Linux tutorial 1, I said that X offers the ability to display content on other hosts’ screens. This makes it possible to log in to a server that has a special program on it and have the display redirected to the screen in front of you. Allowing this to happen is a two-step process. The first step is telling your machine that it should allow connections from another host for X displays. This is done with the xhost command: [michael@workbox michael]$ xhost +ungerer...

2. Editing text filesin Linux Red Hat
Editing Text Files Editors are by the far the bulkiest of common tools, but they are also the most useful. Without them, making any kind of change to a text file would be a tremendous undertaking. Regardless of your Linux distribution, you will have gotten a few editors. You should take a few moments to get comfortable with them before you’re busy fighting another problem. NOTE Although all of the editors listed here come with Red Hat 8, not all of them are installed by default. ...

3. Reviewing Linux File System Standards
Reviewing Linux File System Standards One argument you hear regularly against Linux is that there are too many different distributions, and that multiple distributions lead to fragmentation. This fragmentation will eventuate in different, incompatible Linux versions. This is, without a doubt, complete nonsense that plays on “FUD” (Fear, Uncertainty, and Doubt). These types of arguments usually stem from a misunderstanding of the kernel and distributions. However, the Linux community has realized that it h...

4. Linux is built upon the foundation of file systems
File Systems Linux is built upon the foundation of file systems. They are the mechanisms by which the disk gets organized, providing all of the abstraction layers above sectors and cylinders. In this module, you’ll learn about the composition and management of these abstraction layers supported by the default Linux file system, ext2, and its more robust counterpart, ext3. This module covers the many aspects of managing disks. This includes creating partitions, establishing file systems, automating the process ...

5. Mounting and Unmounting Local Disks
Linux’s strong points include its flexibility and the way it lends itself to seamless management of file locations. Partitions are mounted so that they appear as just another subdirectory. Even a substantial number of file systems look, to the user, like one large directory tree. This characteristic is especially helpful to the administrator, who can relocate partitions to various servers but can have the partitions still mounted to the same location in the directory tree; users of the file system need not know abou...

6. The fsck tool short for File System ChecK
Using fsck The fsck tool, short for File System ChecK, is used to diagnose and repair file systems that may have become damaged in the course of daily operations. Such repairs are usually necessary after a system crash in which the system did not get a chance to fully flush all of its internal buffers to disk. (Although this tool’s name bears a striking resemblance to one of the expressions often uttered after a system crash, that this tool is part of the recovery process is strictly coincidence.) Us...

7. The process of adding a disk under Linux on the Intel
Adding and Partitioning a Disk The process of adding a disk under Linux on the Intel (x86) platform is relatively easy. Assuming you are adding a disk that is of similar type to your existing disks (e.g., adding an IDE disk to a system that already has IDE drives or adding a SCSI disk to a system that already has SCSI drives), the system should automatically detect the new disk at boot time, and all that is left is partitioning it and creating a file system on it. If you are adding a new type of disk (...