home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Complete Idiot's Guide to Linux
(Publisher: Macmillan Computer Publishing)
Author(s): Manuel Ricart
ISBN: 078971826x
Publication Date: 12/22/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Finding out How Much Disk Files Consume: du

The disk usage program, du, allows you to get a listing of how much space a directory eats up, given in 1K increments. By default, it will print an entry for each directory it finds, like this:

     [alberto@digital alberto]$ du
     14      ./.seyon
     3       ./lg/lg_layouts
     1       ./lg/.lgDESKTOP
     1       ./lg/lg3_hosts
     15      ./lg
     40      ./.kde/share/config
     1       ./.kde/share/apps/kfm/tmp
     1       ./.kde/share/apps/kfm/bookmarks
     6       ./.kde/share/apps/kfm
     4       ./.kde/share/apps/kdehelp
     2       ./.kde/share/apps/knotes/notes
     1       ./.kde/share/apps/knotes/xyalarms
     5       ./.kde/share/apps/knotes
     1       ./.kde/share/apps/kppp/Rules

To summarize output, specify the -s option, as in the following:

     [alberto@digital alberto]$ du -s
     23670   .

To specify specific directories or files to list, provide their names as arguments, like this:

     [root@digital /home]# du -s *
     23670   alberto
     32      cool
     32      digital
     35      flower
     583     ftp
     1582    httpd
     1       public
     1       samba
     1       test_project

In this example, all home directories are summarized.

Finding the Amount of Free Disk Space: df

To find the amount of disk space to devices available in your system, use the df (disk free) command, as shown in the following:

     [root@digital /home]# df
     Filesystem         1024-blocks  Used Available Capacity Mounted on
     /dev/hda1             686892  606189    45223     93%   /

The command produces a nice table specifying how much space is available. Numbers are expressed in kilobytes.

In UNIX/Linux, just because there’s free space doesn’t mean that you can create files. If the file system’s inode table fills up (unlikely, but possible if a disk holds a great deal of tiny files), your system would be unable to create additional files. To see how you are doing on inodes, provide the -i option to df:

    [root@digital /home]# df -i
    Filesystem           Inodes   IUsed   IFree  %IUsed Mounted on
    /dev/hda1             177480   34971  142509    20%  /

If you compare the regular df output, you’ll see that under normal circumstances, there are plenty of inodes left. On my disk, I have used 93% of my disk, yet only 20% of the inodes.

Log Files

Many of the programs that run in the background, Web server, email, FTP, and so on generate logs for errors or just as a record of someone accessing it. This type of information is recorded, for example, every time a user logs in or out of the system.

Monitoring Logins: last

Linux keeps very good track of users and their logins. This information is particularly useful when you are in a networked environment, and as a security precaution, you check to make sure that no “weird” traffic is going on in your machine.

By default, Linux is set up to keep track of logins and logouts. You can browse the login record using the last command.

To filter output to a specific user, provide the username as an argument to last:

  [alberto@digital log]$  last alberto
  alberto  ttyp0        192.168.0.3      Fri Oct  2 18:32   still logged
    in
  alberto  ttyp0        192.168.0.3      Fri Oct  2 18:29 - 18:32
  alberto  tty2                          Fri Oct  2 15:20 - 17:01   (01:40)
  alberto  ttyp1        192.168.0.3      Fri Oct  2 14:55 - down    (03:32)
  alberto  ftp          192.168.0.3      Fri Oct  2 13:41 - 13:42   (00:00)
  alberto  ftp          192.168.0.3      Fri Oct  2 13:12 - 13:28   (00:16)
  alberto  tty1                          Fri Oct  2 13:02 - down    (05:25)
  alberto  tty1                          Wed Sep 30 17:41 - down    (00:18)
  alberto  tty1                          Tue Sep 29 11:10 - down    (00:10)
  alberto  tty1                          Mon Sep 28 17:36 - down    (00:47)

The last command prints the username, the terminal used to access the system, where the user came from (IP address) if the login was remote, and the date and duration of the session.

If the log file /var/log/wtmp doesn’t exist in your system, the system will not keep track of login information. To enable (or disable) this feature, just create or delete this file.

Monitoring Bad Logins: lastb

The lastb command keeps track of bad (unsuccessful) logins. To enable bad login accounting, as root create the file /var/log/btmp. You can do this using the touch command (touch /var/log/btmp).

To review bad logins, use the lastb command. Unfortunately, Caldera OpenLinux doesn’t currently support lastb use.

If an account has an unusual number of bad logins, it is possible that the account is under attack by someone. Such accounts should be disabled and the user owning the account should be notified.

Disabling an Account

The easiest way to disable an account is to put an asterisk (*) before the encrypted password in the /etc/passwd file. (The password is the second field in /etc/passwd.) Fields are separated by colons (:), like this:

     me:*Ms.7kvaAYyHbU:500:100:Me:/home/me:/bin/sh

If you are using shadow passwords, the easiest way to disable an account is to use usermod and expire it with a date in the past:

     usermod -e MM/DD/YY login
     [root@digital alberto]# usermod -e 09/01/98 me

(Usermod is introduced in Chapter 18, “Users, Groups, and Passwords.”)


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.