History
The history command can be used to display commands that have been executed, or to perform the required commands according to the treatment shown
N shows n recent records
-A Add records
-R reads records but does not add content records
-W Overwrite original history file
-C purge Record
-d< number >[n] Delete specified n records
-n< File > read the specified file
-r< files > read files but not record
-w< files > Overwrite existing files
Example 1
The code is as follows:
[Root@redhat ~]# History #查看所有执行过的命令
1 ls
2 pwd
3 fc-l
4 history
The code is as follows:
[Root@redhat ~]# History 2 #显示2条
4 history
5 History 2
The code is as follows:
[Root@redhat ~]#! 4 #执行编号是4的命令, note exclamation mark
History
1 ls
2 pwd
3 fc-l
4 history
5 History 2
6 history
The code is as follows:
[Root@redhat ~]# history-c #清除历史记录
!$ refers to the last argument of the previous command
The code is as follows:
[Tank@localhost workspace]$ Ls-all
Total dosage 1060
Drwxrwxr-x. Tank tank 4096 August 6 16:26.
DRWX------. Tank tank 4096 August 15 16:13.
-rw-r--r--1 root 2466 July 18:02 1.html
Drwxr-xr-x 7 tank tank 4096 July 03:02 CKEditor
Drwxr-xr-x. 2 tank tank 4096 May 00:08 Database
The code is as follows:
[Tank@localhost workspace]$!$ #取得-all
-all
BASH:-all:command not found
Example 2
The code is as follows:
[Root@redhat ~]#! -N #执行倒数第N条命令
[Root@redhat ~]#!! #执行上一条命令
Fc
The FC command can edit the commands that have been executed and let them be executed in batches
-1 List all orders between the first and last instruction
-N does not display number
-R Reverse Sort
-e< Text Editor > Specify text Editor edit, Default VI
-s< instruction > select command execution
Example 1
The code is as follows:
[Root@redhat ~]# fc-l #查看执行过的命令, root history, very similar
348 eval echo "AAA" ls
349 eval echo "AAA"; LS
The EXEC LS
351 apt-get Install MySQL
352 apt-get Install Mysql-server
353 exit
354 expr 4%6
355 Expr 4% 6
356 Expr 4<6
357 Expr 4 ' < ' 6
358 Expr 6 ' + ' 5
359 Expr 6 ' * ' 5
360 expr 6 ' > ' 5
361 Fc-l
362 Mans FC
363 FC--help
The code is as follows:
[Root@redhat ~]# fc-s 358 #执行第358个命令
Expr 6 ' + ' 5
11
The code is as follows:
[Root@redhat ~]# FC 358 #编辑第358个命令