|
|
Important Files
and Directories
Linux Tips by Burleson Consulting |
Armed with knowledge about how to navigate the Linux
directory tree and manipulate files, we'll now look at some of the more
important files within Linux. This chapter will also provide information on how
to identify some of the standard directories created within the Linux directory
architecture and where important files are stored within the structure.
Home Directory
Each Linux user is assigned a home directory where they
can keep files and build upon the structure by creating their own directories.
The user home directories are identified by the Linux login user name and can
usually be found under a parent directory called /home. If the users on the
server are sally, bill, joan, and fred, the home directory structure would be
like the one demonstrated below.
/home
???
?
? /bill
?
? /fred
?
? /joan
?
? /sally
We mentioned earlier that every Linux system has a root
user but we do not see a home directory for root here. Since root is a special
user, root?s home directory can be found by itself at /root.
Hidden ?Dot? Files
There are some files within the home directory that are
ordinarily hidden. Hidden files have names that begin with a period; hence,
they have been given the nickname of dot files. Hidden files are not displayed
by the ls command unless the ?a option is used in the format of ls ?a.
Table 5.1 below lists some of the more common dot files
that users should know about. This is by no means a totally comprehensive
list. Additional dot files can be found in the user?s home directory; however,
some searches may not find some of the files listed here. The files found are
dependent upon the applications installed on the server, the utilities that are
in use and the command shell that is being used. Since the default shell for
Linux is the bash shell, the home directory contains the bash related scripts
indicated below.
File Description
.bash_history
For users of the bash shell, a file containing up to 500
of the most recent commands available for recall using the up and down arrow
keys.
.bash_logout
Script that is run by the bash shell when the user logs
out of the system
.bash_profile
Initialization script that is run by the bash shell upon
login in order to setup variables and aliases. When bash is started as the
default login shell, it looks for the .bash_profile file in the user?s home
directory; if not found, it looks for .bash_login. If there is no .bash_login
file, it then looks for a .profile file.
.bashrc
Initialization script executed whenever the bash shell
is started in some way other than a login shell. It is better to put system-wide
functions and aliases in /etc/bashrc, which will be presented later in the book.
.gtkrc
GTK initialization file. GTK+ is a multi-platform
toolkit for creating graphical user interfaces, used by a large number of
applications. It is the toolkit used by the GNU project's GNOME desktop.
.login
The initialization script that is run whenever a user
login occurs.
.logout
The script that is automatically run whenever a user
logout occurs.
.profile
Put default system-wide environment variables in
/etc/profile.
.viminfo
Initialization file for the Vim text editor that is
compatible with vi.
.wm_style
Specifys the default window manager if one is not
specified in startx
.Xdefaults & .Xresources
Initialization files for Xterm resources for the user.
Application program behavior can be changed by modifying these files.
.xinitrc
The initialization file used when running startx, which
can be used to activate applications and run a particular window manager.
.xsession
This file is executed when a user logs in to an
X-terminal and is used to automatically load the window manager and
applications.
Table 5.1: Common dot files for the bash shell
When these files do not exist in the user?s home
directory, programs that use the files will often use a global default
configuration file installed in one of the subdirectories in which the package
is installed.
The list below indicates the dot files installed in
tclark?s home directory.
-rw------- 1 tclark tclark 3773 Jan 13 21:39
.bash_history
-rw-r--r-- 1 tclark tclark 24 Aug 18 11:23
.bash_logout
-rw-r--r-- 1 tclark tclark 191 Aug 18 11:23
.bash_profile
-rw-r--r-- 1 tclark tclark 124 Aug 18 11:23
.bashrc
-rw-r--r-- 1 tclark tclark 237 May 22 2003
.emacs
-rw-r--r-- 1 tclark tclark 120 Aug 24 06:44
.gtkrc
-rw------- 1 tclark tclark 692 Jan 13 21:35
.viminfo
-rw-r--r-- 1 tclark tclark 220 Nov 27 2002
.zshrc
The following is the content of the .bash_logout file in
tclark?s home directory, which is executed whenever logging out of the system.
It does nothing more than clear the screen upon logout.
# ~/.bash_logout
clear
The following is the content of the .bashrc file from
tclark?s home directory. Shell scripts will be presented in a later chapter,
but for now suffice it to say that the script looks for a file in the /etc
directory called bashrc and execute it if the file exists.
# .bashrc
# User specific
aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
These files primarily affect individual users on the
Linux system. Next we'll look at the files which affect the entire system.
Important System Files
Everything in the Linux environment exists in files. It
makes sense for users to become familiar with some of the more important Linux
system files. Some of these are configuration files, others are devices which
Linux makes available through files and some are executable programs.
Table 5.2 below is by no means intended to be an
exhaustive list of Linux system files; however, it is a good representation to
give some insight into the inner workings of Linux.
File |
Description |
/boot/vmlinuz |
The Linux kernel file. File naming
conventions may include release information |
/dev/fd0 |
Device file for the first floppy disk
drive on the system |
/dev/fd0H1440 |
Device driver for the first floppy
drive in high density mode, commonly invoked when formatting a floppy
diskette for that density |
/dev/hda |
Device file for the first IDE hard
drive on the system |
/dev/hdc |
Commonly, the IDE CDROM drive device
file which often is a symbolic link called to /dev/cdrom, the real CDROM
driver file. |
/dev/null |
A dummy device which contains
nothing. It is sometimes useful to send output to this device to make it go
away forever. |
/etc/aliases |
Contains aliases used by sendmail and
other mail transport agents. Whenever this file is changed, the newaliases
utility must be run to notify sendmail of the changes |
/etc/bashrc |
Contains global defaults and aliases
used by the bash shell |
/etc/crontab |
A parent shell script to run commands
periodically. It invokes hourly, daily, weekly, and monthly scripts. |
/etc/exports |
Contains a list of filesystems which
may be made available to other systems on the network via NFS. |
/etc/fstab |
The file system table contains the
description of what disk devices are available at what mount points. |
/etc/group |
Holds information regarding security
group definitions. |
/etc/grub.conf |
The grub boot loader configuration
file |
/etc/hosts |
Contains host names and their
corresponding IP addresses used for name resolution whenever a DNS server is
unavailable |
/etc/hosts.allow |
Contains a list of hosts allowed to
access services on this computer. |
/etc/hosts.deny |
Contains a list of hosts forbidden to
access services on this computer. |
/etc/inittab |
Describes how the INIT process should
set up the system in various runlevels |
/etc/issue |
Contains the pre-login message, often
overwritten by the /etc/rc.d/rc.local script in Red Hat and some other
rpm-based Linux distributions |
/etc/lilo.conf |
The lilo boot loader configuration
file |
/etc/modules.conf |
Holds options for configurable system
modules |
/etc/motd |
This is the ?message of the day? file
which is printed upon login. It can be overwritten by /etc/rc.d/rc.local Red
Hat on startup. |
/etc/mtab |
Status information for currently
mounted devices and partitions |
/etc/passwd |
Contains information regarding
registered system users. Passwords are typically kept in a shadow file for
better security. |
/etc/printcap |
Holds printer setup information |
/etc/profile |
Contains global defaults for the bash
shell |
/etc/resolv.conf |
A list of domain name servers (DNS)
used by the local machine |
/etc/securetty |
This file contains a list of
terminals where root can login |
/etc/termcap |
An extensive ASCII text file defining
the properties of consoles, terminals, and printers |
/proc/cpuinfo |
Contains CPU related information |
/proc/filesystems |
Holds information regarding
filesystems that are currently in use |
/proc/interrupts |
Stores the interrupts that are
currently being used |
/proc/ioports |
A list of the I/O addresses used by
devices connected to the server |
/proc/meminfo |
Contains memory usage information for
both physical memory and swap |
/proc/modules |
Lists currently loaded kernel modules |
/proc/mounts |
Displays currently mounted file
systems |
/proc/stat |
Contains various statistics about the
system, such as the number of page faults since the system was last booted |
/proc/swaps |
Holds swap file utilization
information |
/proc/version |
Contains Linux version information |
/var/log/lastlog |
Stores information about the last
boot process |
/var/log/messages |
Contains messages produced by the
syslog daemon during the boot process |
/var/log/wtmp |
A binary data file holding login time
and duration for each user currently on the system |
Table 5.2: Representative list of Linux files
Now let's look at the contents of some files from
tclark?s server. Since these files contain variable information, do not expect
the files on every server to look exactly like these.
The following is part of the file /etc/passwd. The
second field has an x as a placeholder for the password. This indicates that
the passwords for each user are being kept in a shadow file.
/etc/passwd:
# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
ftp:x:14:50:FTP
User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
rpm:x:37:37::/var/lib/rpm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
oracle:x:500:501:Oracle Software
Owner:/home/oracle:/bin/bash
tclark:x:503:504:Terry Clark:/home/tclark:/bin/bash
The fields in this file are separated by colons. In
order the fields are username, password (or placeholder), user ID number,
primary group ID number, user's full name, user's home directory and user's
default shell.
The file system table, /etc/fstab, defines parameters
for mounting partitions and devices as filesystems. The fields displayed below
indicated the device or filesystem to be mounted, the mount point, the type of
filesystem, the mount options, dump option, and file check order at boot time.
/etc/fstab:
# cat /etc/fstab
/dev/md0 / ext3
defaults 1 1
LABEL=/boot /boot ext3
defaults 1 2
LABEL=/bootback /bootback ext3
defaults 1 2
none /dev/pts devpts
gid=5,mode=620 0 0
none /proc proc
defaults 0 0
none /dev/shm tmpfs
defaults 0 0
/dev/hdd1 swap swap
defaults 0 0
/dev/hdc1 swap swap
defaults 0 0
/dev/hdb3 swap swap
defaults 0 0
/dev/cdrom /mnt/cdrom
udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto
noauto,owner,kudzu 0 0
The /proc/meminfo file contains real and virtual memory
usage statistics.
/proc/meminfo:
# cat /proc/meminfo
total: used: free: shared: buffers:
cached:
Mem: 2107744256 2088869888 18874368 0 180436992
1587232768
Swap: 1508102144 13074432 1495027712
MemTotal: 2058344 kB
MemFree: 18432 kB
MemShared: 0 kB
Buffers: 176208 kB
Cached: 1544780 kB
SwapCached: 5252 kB
Active: 1391876 kB
ActiveAnon: 790712 kB
ActiveCache: 601164 kB
Inact_dirty: 437124 kB
Inact_laundry: 90216 kB
Inact_clean: 41596 kB
Inact_target: 392160 kB
HighTotal: 1179328 kB
HighFree: 5588 kB
LowTotal: 879016 kB
LowFree: 12844 kB
SwapTotal: 1472756 kB
SwapFree: 1459988 kB
Committed_AS: 1565668 kB
HugePages_Total: 0
HugePages_Free: 0
Hugepagesize: 4096 kB
Next we'll look at some of the significant directories
on the Linux system. Some of these will be familiar as the location of the
files we've just looked at.
Important Directories
Although organizations have made strides toward
consistency via standards such as the Linux Filesystem Hierarchy Standard (FHS),
different Linux distributions still have somewhat different directory
structures. The following rendering exemplifies a typical Red Hat effort toward
standardization of where files are stored according to type and use.
Directory |
Description |
/bin |
All binaries needed for the boot
process and to run the system in single-user mode, including essential
commands such as cd, ls, etc. |
/boot |
Holds files used during the boot
process along with the Linux kernel itself |
/dev |
Contains device files for all
hardware devices on the system |
/etc |
Files used by application subsystems
such as mail, the Oracle database, etc. |
/etc/init.d |
Contains various service startup
scripts |
/etc/profile.d |
Holds application setup scripts run
by /etc/profile upon login |
/etc/rc.d |
Contains subdirectories which contain
run level specific scripts |
/etc/rc.d/init.d |
run level initialization scripts |
/etc/rc.d/rc?.d |
Where ??? is a number corresponding
to the default run level. Contains symbolic links to scripts which are in
/etc/rc.d/init.d. for services to be started and stopped at the indicated
run level. |
/etc/skel |
Holds example dot files used to
populate a new user's home directory. |
/etc/X11 |
Contains subdirectories and
configuration files for the X Window system |
/home |
User home directories |
/lib |
Some shared library directories,
files, and links |
/mnt |
The typical mount point for the
user-mountable devices such as floppy drives and CDROM |
/proc |
Virtual file system that provides
system statistics. It doesn't contain real files but provides an interface
to runtime system information. |
/root |
Home directory for the root user |
/sbin |
Commands used by the super user for
system administrative functions |
/tmp |
A standard repository for temporary
files created by applications and users. |
/usr |
Directory contains subdirectories
with source code, programs, libraries, documentation, etc. |
/usr/bin |
Contains commands available to normal
users |
/usr/bin/X11 |
X Window system binaries |
/usr/include |
Holds include files used in C
programs |
/usr/share |
Contains shared directories for man
files, info files, etc. |
/usr/lib |
Library files searched by the linker
when programs are compiled |
/usr/local/bin |
Common executable application files
local to this system |
/usr/sbin |
Commands used by the super user for
system administrative functions |
/var |
Administrative files such as log
files, locks, spool files, and temporary files used by various utilities |
The contents of these directories will vary from system
to system but most of these directories will typically be present. Often when
you install software or a new device on a Linux system files will be added or
modified in these directories to make everything work.
This is an excerpt from "Easy
Linux Commands" by Linux guru Jon Emmons. You can purchase it for only
$19.95 (30%-off) at
this link.
How is Linux Structured?
Linux distributions are based on two parts: the kernel
(and kernel modules) and RPM
packages (for Redhat-like
distributions). When an installation of Linux is performed, choose all the
necessary packages that will be present on the server. A Linux package can
be composed of source codes, patches, configuration files, manuals or
binaries. A RPM
(Redhat Package Manager) package can be built from source files or patches.
Oracle requires specific RPM
packages to be installed in order to perform an installation of the Oracle
software. Those requirements will be covered in Chapter 6, Preparing Linux
for Oracle.
<
The Linux directory structure
/
Root (starting point of your directory structure)
|---root
Home reserved for root user
|---etc
Configuration files specific to the machine.
|---etc/inittab
describes processes to be started /stopped
|---etc/fstab
descriptive information about the file systems
| and
their mount points
|---etc/passwd
contains information for user account
|
|---home
Contains the user's home directories
|---bin
Commands needed during start-up
|---sbin
Commands run by system administrators
|---proc
This mount point is virtual
|---usr
Contains all commands, libraries, man pages and
|
static files
|---usr/doc
Documentation for the user apps
|---usr/src
Code sources files for the system's software,
|
contains also Linux kernel
|---usr/include
Header files for the C compiler
|---usr/X11R6
X Window System directory
|
|---boot
Files used during boot, LILO (vmlinuz Kernel
|
images can be stored).
|---lib
Shared libraries needed by the programs on the
|
root filesystem
|---dev
Device files for devices such as disk drives,
|
serial ports, etc.
|
|---var
Contains files that change for mail, log files,
|
man pages, temp files
|---mnt
Mount points for temporary mounts by the system
|
administrator.
|---tmp
Temporary files.
|---lost+found
Contains files to restores after a system crash
|
or partition not un-mounted before a system
|
shutdown