Читать книгу Linux Bible - Christopher Negus - Страница 114

Configuring your shell

Оглавление

Several configuration files support how your shell behaves. Some of the files are executed for every user and every shell, whereas others are specific to the user who creates the configuration file. Table 3.6 shows the files that are of interest to anyone using the bash shell in Linux. (Notice the use of ~ in the filenames to indicate that the file is located in each user's home directory.)

To change the /etc/profile or /etc/bashrc files, you must be the root user. It is better to create an /etc/profile.d/custom.sh file to add system-wide settings instead of editing those files directly, however. Users can change the information in the $HOME/.bash_profile, $HOME/.bashrc, and $HOME/.bash_logout files in their own home directories.

TABLE 3.6 Bash Configuration Files

File Description
/etc/profile This sets up user environment information for every user. It is executed when you first log in. This file provides values for your path in addition to setting environment variables for such things as the location of your mailbox and the size of your history files. Finally, /etc/profile gathers shell settings from configuration files in the /etc/profile.d directory.
/etc/bashrc This executes for every user who runs the bash shell each time a bash shell is opened. It sets the default prompt and may add one or more aliases. Values in this file can be overridden by information in each user's ~/.bashrc file.
~/.bash_profile This is used by each user to enter information that is specific to his or her use of the shell. It is executed only once—when the user logs in. By default, it sets a few environment variables and executes the user's .bashrc file. This is a good place to add environment variables because, once set, they are inherited by future shells.
~/.bashrc This contains the information that is specific to your bash shells. It is read when you log in and also each time you open a new bash shell. This is the best location to add aliases so that your shell picks them up.
~/.bash_logout This executes each time you log out (exit the last bash shell).

Until you learn to use the vi editor, described in Chapter 5, “Working with Text Files,” you can use a simple editor called nano to edit plain-text files. For example, enter the following to edit and add stuff to your $HOME/.bashrc file:

 $ nano $HOME/.bashrc

With the file open in nano, move the cursor down to the bottom of the file (using the down arrow key). Type the line you want (for example, you could type alias d='date +%D'). To save the file, press Ctrl+O (the letter O); to quit, press Ctrl+X. The next time you log in or open a new shell, you can use the new alias (in this case, just type d). To have the new information you just added to the file available from the current shell, type the following:

 $ source $HOME/.bashrc $ d 06/29/19

The following sections provide ideas about items to add to your shell configuration files. In most cases, you add these values to the .bashrc file in your home directory. However, if you administer a system, you may want to set some of these values as defaults for all your Linux system's users.

Linux Bible

Подняться наверх