Important files and directories

Linux hides useful information about your computer all over your system. These resources are one of the reasons Linux is so useful, but learning about these resources can be tough. This section documents some useful files and directories that can make your administration life easier.

/etc

System-wide configuration files are kept in /etc. If you need to configure some service or program that affects all users, you want to look here. Generally, the configuration files for a package will bear that package's name.

Configuration files in Linux are usually plain text files, which you can edit with an editor. Before editing any configuration file, you should make a backup so that you can restore settings if you mess up.

In addition to system-wide configuration, individual users can control the behaviour of applications using dotfiles in their home directories. A dotfile is a file or directory that begins with a period (and so is hidden when typing ls but revealed when typing ls -a). Unless you want to change an application's configuration for every user on the system, you often want to change the appropriate dotfiles in your home directory instead.

Runlevels and /etc/init.d

Functionality such as printing, mail delivery, and the firewall are called services. Services on your system are controlled by daemons -- special programs started on bootup. These programs wait for some event to happen (for example, somebody trying to print to your printer) and then take action.

Daemons are started and stopped by scripts in the directory /etc/init.d/ . These scripts are called in a standard way; they take the options start, stop, restart, and reload. For example, to stop the firewall script, you could type

      
      /etc/init.d/firewall stop 
      
      

Runlevels

A runlevel determines the set of services/daemons that are allowed to run at any given point. When Linux enters a runlevel it will start and stop services so that the set of running services matches the services that are allowed to run at that time. Runlevels are important primarily when booting and shutting down the system.

There are eight runlevels that exist on your system, although in practice only five of them are distinct:

  • Runlevel 0 is used to shut down the system. As no services should be running when the system halts, the purpose of this runlevel is to stop all the daemons.
  • Runlevel 1 is used for single-user mode. This mode is used for maintenance: only the root user is allowed to log in, and most services are not started. Administrators typically use this mode when something serious has gone wrong (such as a hard drive's data becoming corrupt) and they need to make sure nobody else is using the system to fix things.
  • Runlevels 2-5 are used for multiple-user mode. By default these runlevels are identical. When your system starts, it will go into runlevel 2. Runlevels 3-5 will probably not be of much use to you unless for some reason you need to run different sets of services at different times.
  • Runlevel 6 is used when rebooting the system. It is fairly similar to runlevel 0 in that most services are stopped.
  • There is also a runlevel called runlevel S. Its purpose is to help make the transition to runlevel 1.

The init command is used to enter these runlevels. For example, if you wanted to enter single-user mode, you would type (as root)

        
        init 1 
        
        

You will usually not use this command directly.

Your system identifies the services to start and stop at each runlevel using symbolic links. Each runlevel gets its own directory: runlevel 0 uses /etc/rc0.d, runlevel 1 uses /etc/rc1.d, and so on.

Inside each of these directories is a set of symbolic links. The symbolic links point to the scripts in /etc/init.d. Each link is named in the following way:

  • The first character is `S' if the service should be started on that runlevel, and `K' if the service should be stopped ("killed") on that runlevel.
  • The next two characters are digits which specify the order that the scripts will be executed. Scripts with earlier numbers are executed first.
  • The rest of the name is the name of the script in /etc/init.d/

If for some reason you need to modify the services that run at some runlevel, you have two options: you can modify the symlinks directly, or you can use the update-rc.d command. For example, to disable the firewall from all runlevels, you would type

        
        update-rc.d -f firewall remove
        
        

This would remove all the symbolic links in the rc.d directories, but it will not touch the original script in /etc/init.d . Note that this command alters the services you run permananently; if you just wanted to temporarily stop the firewall, you would type

        
        /etc/init.d/firewall stop 
        
        

and the firewall would be disabled until you rebooted or turned it on again.

Networking control files

Files to configure your Internet connectivity are scattered throughout /etc. Each file controls a different aspect of networking:

  • If you have a network card in your machine, the file /etc/network/interfaces determines how the network card is configured. The network card is named eth0. A line in the interfaces file reading

            
            auto eth0
            
            

    determines whether you connect on to the Internet upon booting up. If the line is present and not commented out, then your network card attempts to connect to the Internet (or whichever network you are on) upon booting. If you are not always connected to the Internet, you may want to comment this line out:

            
            #auto eth0 
            
            

    Then you would type the following command (as root) to start networking manually:

            
            ifup eth0
            
            

  • The file /etc/resolv.conf configures name servers -- computers that turn numerical Internet addresses (such as 142.168.1.1) to domain names (such as "debian.org"). Often this file is configured for you automatically.

/var/log

Many daemons and applications write information to logfiles, recording status messages and errors. When things go wrong, it is often worth looking at the log files for errors and other unusual events.

Programs are supposed to keep their logfiles in the /var/log directory. Some files and directories of note include:

  • The XFree86.0.log file records information about graphical mode startup. If you find that graphical mode does not start, this file may tell you the error. The file is regenerated every time the computer attempts to start graphical mode.
  • The syslog is a general log. Many different programs record information to this file, so it is a good place to look if you cannot find a more specific file.
  • The aptitude file logs operations you have performed using aptitude. Use this when you are wondering why you installed a particular package.
  • The debug, messages, kern.log, and messages files store messages from the kernel.

Often you will not want to look through these files manually. Rather, you will want to search through the files for expressions using grep.