-->
Previous | Table of Contents | Next |
When the history command is used with no options, the entire contents of the history list are displayed. The list that is displayed onscreen might resemble the following list:
1 mkdir /usr/games/pool 2 cp XpoolTable-1.2.linux.tar.z /usr/games/pool 3 cd /usr/games/pool/ 4 ls 5 gunzip XpoolTable-1.2.linux.tar.z 6 tar -xf XpoolTable-1.2.linux.tar 7 ls 8 cd Xpool 9 ls 10 xinit 11 exit 12 which zip 13 zip 14 more readme 15 vi readme 16 exit
Using the n with the history command causes only the last n lines in the history list to be shown. So, for example, history 5 shows only the last five commands.
The second method of using the history command is to modify the contents of the history file or the history list. The command has the following command-line syntax:
history [-r|w|a|n] [filename]
In this form, the -r option tells the history command to read the contents of the history file and use them as the current history list. The -w option causes the history command to write the current history list to the history file (overwriting what is currently in the file). The -a option appends the current history list to the end of the history file. The -n option causes the lines that are in the history file to be read into the current history list.
All of the options for the second form of the history command can use the filename option as the name of the history file. If no filename is specified, the history command uses the value of the HISTFILE shell variable.
The fc command can be used in two different ways to edit the command history. In the first way, the fc command is entered using the following command-line syntax:
fc [-e editor_name] [-n] [-l] [-r] [first] [last]
where all options given in braces are optional. The -e editor name option is used to specify the text editor to be used for editing the commands. The first and last options are used to select a range of commands to take out of the history list. first and last refer either to the number of a command in the history list or to a string that fc will try to find in the history list.
The -n option is used to suppress command numbers when listing the history commands. The -r option lists the matched commands in reverse order. The -l command lists the matched commands to the screen. In all casesexcept when the -l command option is usedthe matching commands are loaded into a text editor.
Note:
The text editor used by fc is found by taking the value of editor name if the -e editor name option is used. If this option is not used, fc uses the editor specified by the variable FCEDIT. If this variable does not exist, fc uses the value of the EDITOR variable. Finally, if none of these variables exists, the editor that is chosen is vi, by default.
Another way that bash makes life easier for you is by supporting command aliases. Command aliases are commands that the user can specify. Alias commands are usually abbreviations of other commands, designed to save keystrokes.
For example, if you are entering the following command on a regular basis, you might be inclined to create an alias for it to save yourself some typing:
cd /usr/X11/lib/X11/fvwm/sample-configs
Instead of typing this command every time you want to go to the sample-configs directory, you can create an alias called goconfig, which causes the longer command to be executed. To set up an alias like this you must use the bash alias command. To create the goconfig alias, enter the following command at the bash prompt:
alias goconfig=cd /usr/X11/lib/X11/fvwm/sample-configs
Now, until you exit from bash, the goconfig command will cause the original, longer command to be executed as if you had just typed it.
If you decide after you have entered an alias that you do not need it, you can use the bash unalias command to delete the alias:
unalias goconfig
There are a number of useful aliases that most users find helpful. These can be written in a file that executes when you log in to save you from typing them each time. Some aliases that you may want to define are:
If you are a DOS user and used to using DOS file commands, you can use the alias command to define the following aliases so that Linux behaves like DOS:
Tip:
When defining aliases, dont include spaces on either side of the equal sign or the shell cant properly determine what you want to do. Quotation marks are necessary only if the command within them contains spaces or other special characters.
If you enter the alias command without any arguments, it displays all of the aliases that are already defined. The following listing illustrates a sample output from the alias command:
alias dir=ls alias ll=ls -l alias ls=ls -F alias md=mkdir alias net=term < /dev/modem > /dev/modem 2> /dev/null& alias rd=rmdir
Previous | Table of Contents | Next |