Linux Bible. Christopher Negus

Чтение книги онлайн.

Читать онлайн книгу Linux Bible - Christopher Negus страница 44

Linux Bible - Christopher Negus

Скачать книгу

This is the directory that was the working directory before you changed to the current working directory. OSTYPE This name identifies the current operating system. For Fedora Linux, the OSTYPE value is either linux or linux-gnu, depending on the type of shell you are using. (Bash can run on other operating systems as well.) PATH This is the colon-separated list of directories used to find commands that you type. The default value for regular users varies for different distributions but typically includes the following: /bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/X11R6/bin:~/bin. You need to type the full path or a relative path to a command that you want to run which is not in your PATH. For the root user, the value also includes /sbin, /usr/sbin, and /usr/local/sbin. PPID This is the process ID of the command that started the current shell (for example, the Terminal window containing the shell). PROMPT_COMMAND This can be set to a command name that is run each time before your shell prompt is displayed. Setting PROMPT_COMMAND=date lists the current date/time before the prompt appears. PS1 This sets the value of your shell prompt. There are many items that you can read into your prompt (date, time, username, hostname, and so on). Sometimes a command requires additional prompts, which you can set with the variables PS2, PS3, and so on. PWD This is the directory that is assigned as your current directory. This value changes each time you change directories using the cd command. RANDOM Accessing this variable causes a random number to be generated. The number is between 0 and 99999. SECONDS This is the number of seconds since the time the shell was started. SHLVL This is the number of shell levels associated with the current shell session. When you log in to the shell, the SHLVL is 1. Each time you start a new bash command (by, for example, using su to become a new user, or by simply typing bash), this number is incremented. TMOUT This can be set to a number representing the number of seconds the shell can be idle without receiving input. After the number of seconds is reached, the shell exits. This security feature makes it less likely for unattended shells to be accessed by unauthorized people. (This must be set in the login shell for it actually to cause the shell to log out the user.)

      While you are in the shell, you can check which aliases are set by typing the alias command. If you want to remove an alias, use unalias. (Remember that if the alias is set in a configuration file, it will be set again when you open another shell.)

      Exiting the shell

      To exit the shell when you are finished, type exit or press Ctrl+D. If you go to the shell from a Terminal window and you are using the original shell from that window, exiting causes the Terminal window to close. If you are at a virtual console, the shell exits and returns you to a login prompt.

      You can tune your shell to help you work more efficiently. You can set aliases to create shortcuts to your favorite command lines and environment variables to store bits of information. By adding those settings to shell configuration files, you can have the settings available every time you open a shell.

      Configuring your shell

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

Скачать книгу