You are on page 1of 3

Linux+ Notes Started 4/9/2011

INIT and Run Levels

Runlevel Description Directory


This is the halt state. In runlevel 0, the system has no daemons in memory and is ready
0 /etc/rc.d/rc0.d
to be turned off.
1
s This is single user mode. In single user mode, the system uses only enough daemons to
/etc/rc.d/rc1.d
S allow a single user to log in. The user is automatically logged in as the root user.
single
This is multi-user mode. In multi-user mode, the system allows multiple users to log in.
2 /etc/rc.d/rc2.d
It also provides networking services with the exception of the Network File System.
This is extended multi-user mode. In extended multi-user mode, the system provides
3 multi-user mode support in addition to all network services, including Network File /etc/rc.d/rc3.d
System.
4 This runlevel is not used. However, you can manually define it, if you wish. /etc/rc.d/rc4.d
This is graphical mode. In graphical mode, the system provides the same capabilities as
5 /etc/rc.d/rc5.d
in extended user mode. However, the system also supports graphical log ins.
This is the reboot runlevel. In this runlevel, the system re-starts itself. Do not set the
6 /etc/rc.d/rc6.d
runlevel to 6.

Use chkconfig (-add, -del, -list) to view/add/change/remove services from various runlevels. Syntax is ckhconfig –level #
service on|off.

Use init # or telinit # to change runlevels.

Services

Services can be maintained by using their corresponding script in /etc/rc.d/init.d directory; possible arguments are
start, stop, restart, reload, status, or * (shows all available options).

To view all services and their current status use service –status-all
Environment Variables

Variable Description
DISPLAY Redirects X Windows output to another computer.
HISTFILE The filename where past commands are stored.
HISTFILESIZE The number of past commands HISTFILE stores.
HOME The absolute path of the user's home directory.
LANG The language the operating system uses.
PAGER Used by the man command to specify the program in which to display man pages.
The directory prefixes used to search for programs and files. Use a colon to separate entries in
PATH
the PATH variable.
SHELL The user's login shell.

Use... To... Example


echo $SHELL displays the current shell's path.
echo $variable View the variable identifier's value.
echo $TERM displays the terminal settings.
Display all the variables in the
env
system.
Export a user-defined variable to export HOMEDIR makes the HOMEDIR user-
export variable
make it available to child sessions. defined variable available to child sessions.
Display the set environment
set
variables.
unset variable Remove a variable. unset HOMEDIR removes the HOMEDIR variable.
HOMEDIR=/projects creates the HOMEDIR
VARIABLE=value Create a user-defined variable.
variable with a value of /projects.

Script Files

File Description
This file executes immediately after a user logs in. It is a systemwide initialization file that is
/etc/profile
used primarily to set environment variables.
This file executes after /etc/profile. It is also a systemwide file that is often executed by
/etc/bashrc
individual users' .bashrc file. It is most commonly used for aliases and functions.
~/.bash_profile After /etc/profile executes, the system searches for these files in the user's home directory.
or These are optional files in which users can create settings specific to their systems.
~/.bash_login ~/.bash_login only executes in the absence of ~/.bash_profile. ~/.profile only executes in the
or absence of the other two. (The ~/ is a bash home directory variable. It eliminates your need to
~/.profile know where a user's home directory is.)
~/.bashrc This file executes when bash runs. It is often used to include /etc/bashrc in its scripts.
This script file relates to the init process. Scripts in this file execute after all the entries in the
/etc/rc.d/rc.local
/etc/inittab file have executed.

Backup/Restores
TAR – the tar command can be used to create uncompressed backups (uses gzip or bz2 via flags for compression); it may
also be used to uncompress previously created tar files, a.k.a. tarballs. Examples below:

tar –cvzf /etcbkup.tar.gz /etc – compress (gzip), backup the /etc directory to /etcbkup.tar.gz in verbose mode
tar –cjf /confbk.tar.bz2 /etc – compress (bz2), backup the /etc directory to /confbk.tar.bz2 in quite mode

The –C flag can be used to include the directory path structure in the tar: tar -cjvf report.tar.bz2 -C /mkt/reports. The
tar command also saves/restores permissions.

CPIO – pipes output from commands like ls and find to create a backup;

ls /etc/c* | cpio –ovd > /dev/rfd0 – the ls command is piped to the cpio command which is redirected to the
device mounted on rfd0 (floppy 0). Flag –o (create), -v (verbose), -d (restore to saved directory path), -i (extract).

You might also like