Unix Concepts   «Prev  Next»
Lesson 4 Displaying previous commands
Objective Use the history feature to display previous commands.

Displaying Previous Unix Commands

The previous two lessons described how aliases make the command line easier to use. The C shell provides another timesaving feature called command history, or sometimes just history.
The history feature lets you view previously entered commands, rerun them, or run modified versions of them. Before you can work with previously entered commands, you must define the C shell’s history variable, which tells the shell to start remembering the commands you enter.
The general syntax is: For example, to keep track of the 50 most recent commands, enter this:


The following series of imagesshows how command history works: Setting up and using Unix History Feature
1) This command starts the command history feature.
1) This command starts the command history feature. In this case, the 50 most recent commands will be remembered.

2) A few random commands are entered, which are now being tracked by the history feature
2) A few random commands are entered, which are now being tracked by the history feature

3) History command displays previous commands in a numbered list.
3) History command displays previous commands in a numbered list. In this case, there are five, including the history command itself.

4) A few additional commands are entered
4) A few additional commands are entered

5) With a  numeric argument, the history command displays a subset of the list. In this case, the last three commands are listed. Similarly, history 10 would list the last 10 commands.
5) With a numeric argument, the history command displays a subset of the list. In this case, the last three commands are listed. Similarly, history 10 would list the last 10 commands.

Command history:

If the history output scrolls beyond your screen, you can use the more program to pause the output. The command to use is this: history | more. Command history is a C shell feature that lets you display previously entered commands, rerun them, or run modified versions of them.
In the next lesson, history substitution to repeat previous commands will be discussed.

SEMrush Software 4 SEMrush Banner 4