Display the commands in the history list or modify the specified history command and execute it.
fc [-e ename] [-lnr] [first] [last]
fc -s [pat=rep] [command]
-e ename Select the editor to use. The default calling order is environment variable `FCEDIT`, environment variable `EDITOR`, and `vi`.
-l List instead of edit.
-n does not output line numbers when listing (requires -l option).
-r Lists commands in reverse order, with the most recently executed ones listed first (-l option required).
-s [pat=rep] [command] command (the last command executed when not specified) will be re-executed after replacing pat with rep.
first: optional; can be a string (the latest command starting with this string), a number (history list index, a negative number represents the offset of the current command number); if not specified, it is set to the previous command and the offset is - 16 (last 16 commands).
last: optional; can be a string (the latest command starting with this string) or a number (history list index, a negative number represents the offset of the current command number); if not specified, it is set to parameter first.
Returns the status of success or execution of the command, or a non-zero value when an error occurs.
Replace command parameters:
# List ~ directories
ls ~
# Replace ~ with / and list the root directory after replacement.
fc -s ~=/
Display the 10 most recently used historical commands:
[root@localhost ~]# fc -l -10
1039 type-a grep
1040 export
1041 history 10
1042ulimit-a
1043 shopt
1044 helpls
1045 help env
1046 help short
1047 helpshopt
1048 showkey -a
Edit the 1040th historical command:
[root@localhost ~]# fc 1040