To list previous commands, fc has the option “-l” (list). Only the last 16 commands are listed without any further arguments:
[user01@aixe01 ~]$ fc -l
5 ls -l
6 cat passwd
7 cd
8 pwd
9 ls -l log*
10 tail log
11 tail -30 log
12 pwd
13 cd /usr/bin
14 find . -name "ta*"
15 which tail
16 id
17 cd
18 ls -l *.old
19 rm file.old
20 pwd
[user01@aixe01 ~]$
If you want to see more (or fewer) commands, simply enter the number from which you want to see the commands as an argument, e.g. from command 15:
[user01@aixe01 ~]$ fc -l 15
15 which tail
16 id
17 cd
18 ls -l *.old
19 rm file.old
20 pwd
21 fc -l
[user01@aixe01 ~]$
Since you typically don’t have the command numbers in your head, but still want to see the last 5 commands, for example, you can do this by specifying a negative number. In order to display the last 5 commands, “-5” is specified as the argument:
[user01@aixe01 ~]$ fc -l -5
18 ls -l *.old
19 rm file.old
20 pwd
21 fc -l
22 fc -l 15
[user01@aixe01 ~]$
Note: This works with the history command by specifying a positive number, “history 5” lists the last 5 commands.
A second number can be specified as an argument with the “fc –l” command. The two specified numbers then form a range “first” – “last“. E.g. the commands from number 9 to number 14:
[user01@aixe01 ~]$ fc -l 9 14
9 ls -l log*
10 tail log
11 tail -30 log
12 pwd
13 cd /usr/bin
14 find . -name "ta*"
[user01@aixe01 ~]$
Or from command 9 to the third last (-3) command:
[user01@aixe01 ~]$ fc -l 9 -3
9 ls -l log*
10 tail log
11 tail -30 log
12 pwd
13 cd /usr/bin
14 find . -name "ta*"
15 which tail
16 id
17 cd
18 ls -l *.old
19 rm file.old
20 pwd
21 fc -l
[user01@aixe01 ~]$
The history command does not offer such a range specification.
Instead of numbers and negative numbers, you can also specify character strings as arguments, e.g. the range of commands from the last cat command to the command with the number 16:
[user01@aixe01 ~]$ fc -l cat 16
6 cat passwd
7 cd
8 pwd
9 ls -l log*
10 tail log
11 tail -30 log
12 pwd
13 cd /usr/bin
14 find . -name "ta*"
15 which tail
16 id
[user01@aixe01 ~]$
A search is then made for the last command that begins with the specified character string (here “cat“).
If you don’t want to display the numbering, you can use the “-n” option:
[user01@aixe01 ~]$ fc -ln cat find
cat passwd
cd
pwd
ls -l log*
tail log
tail -30 log
pwd
cd /usr/bin
find . -name "ta*"
[user01@aixe01 ~]$
Or the history can be shown in reverse order by using the “-r” (reverse) option:
[user01@aixe01 ~]$ fc -lr cat find
14 find . -name "ta*"
13 cd /usr/bin
12 pwd
11 tail -30 log
10 tail log
9 ls -l log*
8 pwd
7 cd
6 cat passwd
[user01@aixe01 ~]$