00. 目录
01. 命令概述
fc命令自动掉用vi编辑器修改已有历史命令,当保存时立即执行修改后的命令,也可以用来显示历史命令。fc命令编辑历史命令时,会自动调用vi编辑器。fc保存文件后,会自动执行所编辑过的命令。
02. 命令格式
用法:fc [选项] [参数]
03. 常用选项
-e<文本编辑器> 指定用来编辑命令的文本编辑器,默认是vi
-l 列出第一条和最后一天命令范围内的历史命令,如果不跟命令范围则默认显示最近使用过的16条历史命令
-n 显示历史命令时不显示命令序号
-r 反序显示所有历史命令
-s<命令名> 从历史命令中当前位置往前找到指定命令,并执行
04. 参考示例
4.1 显示历史命令列表(默认打印最近的16条历史命令)
[deng@localhost ~]$ fc -l
985 ifconfig
986 ls
987 clear
988 ls
989 help seq
990 man seq
991 ls
992 clear
993 ls
994 ifconfig ens33
995 wd
996 pwd
997 ifconfig ens33
998 help set
999 ls
1000 su - root
[deng@localhost ~]$
4.2 指定使用vim文本编辑器编辑命令
/tmp/bash-fc-1568721904 ASCII=102,HEX=66,1,1 1-100%
[deng@localhost ~]$ fc -e vim
fc -l
986 ls
987 clear
988 ls
989 help seq
990 man seq
991 ls
992 clear
993 ls
994 ifconfig ens33
995 wd
996 pwd
997 ifconfig ens33
998 help set
999 ls
1000 su - root
1001 fc -l
[deng@localhost ~]$
4.3 显示历史命令列表但不显示命令序号
[deng@localhost ~]$ fc -n
fc -l
986 ls
987 clear
988 ls
989 help seq
990 man seq
991 ls
992 clear
993 ls
994 ifconfig ens33
995 wd
996 pwd
997 ifconfig ens33
998 help set
999 ls
1000 su - root
1001 fc -l
[deng@localhost ~]$
4.4 反序显示所有历史命令
[deng@localhost ~]$ fc -r
fc -l
986 ls
987 clear
988 ls
989 help seq
990 man seq
991 ls
992 clear
993 ls
994 ifconfig ens33
995 wd
996 pwd
997 ifconfig ens33
998 help set
999 ls
1000 su - root
1001 fc -l
[deng@localhost ~]$
4.5 从历史命令中找到ls命令,并执行
[deng@localhost ~]$ fc -s ls
ls
bak oradiag_deng sz12 test.sh 视频 音乐
bj34 projects test.c test.txt 图片 桌面
instantclient_11_2 scott_data.sql testCode 公共 文档
oracle_client_11gR2.tar.gz share test.cpp 模板 下载
[deng@localhost ~]$
4.6 显示10条历史命令
[deng@localhost ~]$ fc -l -10
994 ifconfig ens33
995 wd
996 pwd
997 ifconfig ens33
998 help set
999 ls
1000 su - root
1001 fc -l
1002 ls
1003 fc -l 10
[deng@localhost ~]$
4.7 编辑序号为1000的命令并且执行
[deng@localhost ~]$ fc 1000
su - root
密码:
4.8 执行序号为994的命令
[deng@localhost ~]$ fc -s 994
ifconfig ens33
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.0.61 netmask 255.255.254.0 broadcast 172.16.1.255
inet6 fe80::16e5:9e6b:b4d5:68de prefixlen 64 scopeid 0x20<link>
ether 00:50:56:26:d8:88 txqueuelen 1000 (Ethernet)
RX packets 631421 bytes 132226406 (126.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3925 bytes 782296 (763.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[deng@localhost ~]$
05. 附录
转载:https://blog.csdn.net/dengjin20104042056/article/details/100937319
查看评论