Recalling command history
From Linux Shell Scripting Tutorial - A Beginner's handbook
| ← Customize the bash shell environments | Home | Path name expansion → |
- Bash keeps a command history in buffer or a default file called ~/.bash_history.
- The history buffer can hold many commands.
- Use history command to display a list of command you entered at a shell prompt. You can also repeat commands stored in history.
- The history command displays the history list with line numbers.
- By default history is enabled but can be disabled using set builtin command.
- You can recall the basic command with arrow keys.
Contents |
[edit] See list of executed commands
Type the following command
historySample outputs:
3 tail -f /var/log/maillog
4 cat /etc/resolv.conf
5 vnstat
6 vnstat -m
7 rpm -qa | grep vnstat
8 yum update vnstat
9 cd /opt/
10 wget http://humdi.net/vnstat/vnstat-1.9.tar.gz
11 tar -zxvf vnstat-1.9.tar.gz
12 cd vnstat-1.9
13 ls
14 vi INSTALL
15 make
16 cd examples/
17 ls
18 vi vnstat.cgi
19 cd ..
20 ls
21 cd cfg/
22 ls
23 vi vnstat.conf
24 cd /t,
25 cd /tmp/
26 yumdownloader --source vnstat
27 rpm -ivh vnstat-1.6-1.el5.src.rpm
28 cd -
[edit] Recall commands
Simply hit [Up] and [Down] arrow keys.
[edit] Interactively search history
Press [CTRL-r] from the shell prompt to search backwords through history buffer or file for a command:
(reverse-i-search)`rpm ': rpm -ql rhn-client-tools-0.4.20-9.el5
[edit] To repeat last command
Just type !! at a shell prompt:
date !!
[edit] To repeat last command started with ...
Recall the most recent command starting with vn
date vnstat ls ifconfig route -n !vn
[edit] To repeat a command by its number
Recall to command line number 13:
history !13
See history command help page for more detailed information about the events and usage:
man bash help history
| ← Create the constants variable | Home | Path name expansion → |

