Linux administration

Find System Files and Place Files in the Correct Location

Nguyen Hai Chau
Vietnam National University

Unix Filesystem Layout

  • Many common directory names are abbreviated versions of real words
  • Traditional structure which has developed over many years
    • Most system files have their proper place
    • Programs rely on them being in the correct place
    • Users familiar with Unix directory structure can find their way around any Unix or Linux system
  • But a user's home directory can be structured however they want

The Filesystem Hierarchy Standard

  • Started as an attempt to standardise Linux filesystem layouts
    • Called the FSSTND when the first version was published in 1994
  • Widely accepted by distributors
    • But few Linux systems are 100% compliant yet
  • Intended to avoid fragmentation of Linux distributions
  • Renamed to the File Hierarchy Standard, or FHS
  • Now intended to apply to all Unix-like operating systems

Shareable and Non-Shareable Data

  • Some files can be shared between multiple computers, using networked filesystems such as NFS
    • This can save space, although cheap hard drives mean that this is not so important now
    • More importantly, it can help to centralise administration for a network
  • Usually programs, email and home directories are all shareable
  • Log files and machine-specific configuration files are not shareable

Static and Dynamic Data

  • Some files hardly ever need to be changed, while others change all the time
  • It can help to store static files separately from those which regularly change:
    • The static files can be on a partition mounted read-only (such as a CD-ROM)
  • Programs and libraries are usually static (except when new software is installed)
  • Home directories and status files are usually more variable

Overview of the FHS

FHS: Installed Software

  • Programs are usually found in the bin and sbin directories
    • These are found in /, /usr and /usr/local
  • sbin is used for programs likely to be useful to system administrators rather than to general users (mail daemon, web server, etc.)

  • These directories are named after binaries

    • Most programs in them are binaries (compiled programs), although some are human-readable scripts
  • Libraries are stored in directories called lib, found in the same places as bin

    • These directories should be listed in /etc/ld.so.conf

FHS: Other Directories Under /usr

  • /usr/include contains header files used by C/C++ programs
  • /usr/X11R6 contains files used by the X Window system, including programs, libraries, configuration files and documentation

  • /usr/local is where software is installed when it is compiled from source code rather than installed as a package

  • /usr/share contains files which are not specific to the architecture of a machine, e.g., fonts and icons

    • Theoretically could be shared between different types of machine over a network
  • /usr/src often contains the source code for the Linux kernel

FHS: Directories Under /var

  • /var/run contains pid files (process-id files for currently-running daemon programs)
    • Also contains utmp, a record of user logins
  • /var/mail or /var/spool/mail is where each user's email is queued up until it is deleted or saved
  • /var/log contains logs produced by various programs, including syslog
  • /var/cache contains data generated by programs which is cached to save time
    • Cached data can be regenerated if deleted

FHS: Other Directories

  • /etc contains configuration files
  • /mnt is used to mount other filesystems temporarily
  • /boot contains files used by GRUB to boot the system
  • /dev contains device files, which provide access to hardware devices such as disk drives or serial ports
  • /tmp is used by many programs for temporary files
  • /opt can contain packages of software from third parties (i.e., not in the native package management format)

FHS: Other Directories

  • /proc provides access to information from the kernel, particularly about running processes
  • /home contains directories which belong to each user
    • Use echo ˜ to find out where your home directory is
  • /root is the home directory of the root user

Finding Programs with which

  • Searches for programs which can be run
  • Looks in the same directories as the shell
    • Determined by the $PATH environment variable
    • Use echo $PATH to see what directories are searched
  • For example, to find out where gnumeric is:
$ which gnumeric
  • This is useful if different versions of the same program are installed in different places

The type Built-in Command

  • type is like which, but is built into the shell
    • It tells you about shell aliases and functions
    • Not available in the C Shell
  • type -p is just like which
  • type -a shows all the commands of the name given
    • Useful for detecting duplicate programs, or aliases which are hiding real programs
  • See help type for full details

Checking for Shell Builtins with type

  • Some commands are built into the shell
    • Examples include cd, test, pwd and ulimit
  • The Bash shell has a builtin called type which reports on whether a command is a builtin
  • For example, to see whether the test command will run a shell builtin, or a real program:
$ type test
  • The example shows that test will run a shell builtin, even though there is a real program with the same name
  • type will also identify shell aliases and functions

Updating the locate Database

  • Use the updatedb program to refresh the database of files used by locate
  • Modern versions are configured by giving options to updatedb
    • -e provides a list of directories which will not be searched
    • -f gives the names of filesystem types to miss out
    • See the manpage for full details
  • updatedb is usually run by cron every night
    • Look in /etc/cron.daily for the script which runs it

updatedb.conf

  • Older versions of GNU updatedb used the configuration file /etc/updatedb.conf
    • For compatibility, some modern versions still read it
  • The configuration is done by setting environment variables
  • For example, to ignore certain filesystems:
$ PRUNEPATHS="/tmp /usr/tmp /var/tmp /mnt /var/spool"
$ export PRUNEPATHS
  • The $PRUNEFS variable lists the names for filesystems which should be ignored (e.g., nfs, iso9660, etc.)
  • These variables are equivalent to the -e and -f options

whatis

  • whatis finds manpages with the given name and lists them
    • Usually only useful when the name of a command is already known
  • For example, to find manpages about bash:
$ whatis bash
  • The database searched by whatis is updated with the makewhatis command
    • This should be run when new manpages are installed
    • Debian instead has /etc/cron.daily/man-db, which also expunges old cached man pages

Finding Manpages with apropos

  • The apropos command is similar to whatis
    • The difference is that any word in the title line of a manpage can match the word given
  • apropos word is identical to man -k word
  • For example, to find commands relating to directories:
$ apropos directories
$ man -k directories
  • apropos also uses the database built by makewhatis

Web Resources

Exercise

  • a. Find out whether the ls command runs a program directly, or is a shell alias or function.
  • b. Locate the binary of the traceroute program.
  • c. Use whatis to find out what the watch command does.
  • d. Use apropos to find programs for editing the partition table of disks.
  • e. See if the Linux installation you are using has an updatedb.conf, and look at the current configuration if it has.
  • f. Log on as root and update the locate database with the updatedb command.