Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

Chapter 8 User Environment Settings 277

#If power was restored before the shutdown kicked in, cancel it. pr:12345:powerokwait:/sbin/shutdown -c “Power Restored; Shutdown Cancelled”

#Run gettys in standard runlevels

1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2

#Run gettys in standard runlevels 1:2345:respawn:/sbin/mingetty tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

#Run xdm in runlevel 5

#xdm is now a separate service x:5:respawn:/etc/X11/prefdm -nodaemon

The previous file shows how the INIT process sets up the system for a certain runlevel. The INIT process is used to start specific services for specific run levels and general services for every run level. In the preceding example, the default run level is indicated in the line si::sysinit:/etc/rc.d/rc.sysinit, several items run in standard run levels, and the X Window System runs in run level 5. Editing the configuration file for the INIT process can be useful to start services for a specific run level or all run levels. One of the major jobs of the inittab file is to set up the environment variable TERM, which should normally contain the name of the type of terminal, console, or display-device type to be used.

The /etc/inittab file will control the TERM environment, so be familiar with the location and format of the file.

This information is critical to any program that is screen-oriented, including editors, mailers, and remote access programs. A default TERM value is set on a per-line basis and nearly always provides all the services needed for a workstation console. However, you can edit the terminal parameters to use a different configuration depending on the needs of a user. Use the inittab file to set up user-specific TERM environment specifications when the default settings are not acceptable.

BASH

3.11 Identify the purpose and characteristics of configuration files (e.g., BASH, inittab, fstab, /etc/*)

3.12 Edit basic configuration files (e.g., BASH files, inittab, fstab)

The Bourne Again SHell (BASH), is the shell, or command language interpreter, for the GNU operating system and is standard for most Linux systems. BASH has many

278 Part III Configuration

features that allow it to perform well in the Linux environment, including command and filename completion, command line editing, history commands and events, detailed shell operational control, and aliasing. BASH is widely used because of these abilities. To verify the use of BASH on a system, use the env command to list information shown below:

bash-2.04$ env PWD=/home/bill TMPDIR=/tmp/ LC_MESSAGES=en_US REMOTEHOST=192.168.0.6 HOSTNAME=dhcppc1

NLSPATH=/usr/share/locale/%l/%N

LESSKEY=/etc/.less LESSOPEN=|/usr/bin/lesspipe.sh %s LANGUAGE=en_US:en

PS1=\s-\v\$ LESS=-MM USER=bill

LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;0 1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.b tm=01;32:*.bat=01;32:*.tar=01;31:*.tgz=01;31:*.tbz2=01;31:*.arc=01;31:*.arj=01;3 1:*.taz=01;31:*.lzh=01;31:*.lha=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31 :*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01 ;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:*.tiff=01;35:

LC_TIME=en_US MACHTYPE=i586-mandrake-linux-gnu MAIL=/var/spool/mail/bill INPUTRC=/etc/inputrc

LANG=en LC_NUMERIC=en_US TMP=/tmp/ LOGNAME=bill SHLVL=1 LC_CTYPE=en_US SHELL=/bin/bash HOSTTYPE=i586 OSTYPE=linux-gnu HISTSIZE=1000 TERM=ansi HOME=/home/bill

PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games SECURE_LEVEL=3

LC_MONETARY=en_US RPM_INSTALL_LANG=en_US:en LC_COLLATE=en_US _=/usr/bin/env

Notice the line

SHELL=/bin/bash

Chapter 8 User Environment Settings 279

that sets this system to use BASH as the default shell. The configuration files for BASH are .bash_profile, .bashrc, and .bash_logout. The . bash_profile is the login initialization file for BASH. The shell is initialized in a couple of ways — one upon boot and the other interactively. Both ways look for the .bashrc file, which contains the configuration. The file is executed each time the BASH shell or any sub-shells are entered. A global file, usually located at /etc/bashrc, and a user specific file, usually located in /home/username/.bashrc, are the configurations that BASH will use. Any changes to these initialization files will take effect the next time the system is restarted, or the changes can be activated during the current session by running the initialization program. This allows the special features to

be activated.

To learn more about the features of BASH, see the MAN pages. The most common options that can be enabled are noclobber, ignoreeof, and alias. Alias is especially useful because it simplifies the use of common commands, such as adding alias cp ‘cp -i’ to allow only the cp command to be used instead of cp -i command. The home directory of each user also contains the . bash_profile and . bash_logout files. The . bash_logout file can be edited to perform tasks when a user logs out. A common addition to this file is the ability to display messages on logout. A common . bash_logout file may look like this:

# ~/.bash_logout

clear

echo “Exiting the system”

These BASH commands clear the screen and then display the message, “Exiting the system.” The . bash_profile may also be named .profile and is the BASH login initialization file, which is a script that is executed whenever a user logs in. You can also use the BASH logon initialization file to define special environmental variables used to manage the shell, and to set PATH variables for Linux to use to provide quick access to your application programs that are located in other directories. You can do this by using the following simple method:

#.bash_profile

#Get the aliases and functions if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

#User specific environment and startup programs

PATH=$PATH:$HOME/bin

BASH_ENV=$HOME/.bashrc

export BASH_ENV PATH unset USERNAME

280 Part III Configuration

Notice the PATH lines in the preceding example; the first path line sets the $PATH, which holds the directories searched for any command entered, and $HOME, which holds the path of the users home directory. The /bin adds the user’s bin directory to the directories searched when a command is entered. The next line sets the BASH_ENV to the user’s home directory and to that user’s . bashrc for individual configuration. Notice also the export command, which is used to export the variables to any sub-shells that may be used. By using an editor, you can customize the . bash_profile as illustrated here:

#Get the aliases and functions if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

#User specific environment and startup programs

PATH=$PATH:$HOME/bin

BASH_ENV=$HOME/.bashrc

MAILDIR=$HOME/nsmail

MAIL=$HOME/nsmail/Inbox

export BASH_ENV PATH unset USERNAME

The available configurations are virtually limitless — thus making BASH an excellent shell for most environments. Table 8-5 shows the location and purpose of the BASH shell configuration files.

Table 8-5

Shell Configuration Files

Shell

File

Function

 

 

 

BASH

.bash_profile

Login initialization file

 

 

 

BASH

.bashrc

Shell configuration file

 

 

 

BASH

.bash_logout

Logout functions

 

 

 

By using the files in Table 8-5, you are able to control and configure the shell environment for all users or individual users.

Соседние файлы в предмете Операционные системы