linux查看执行过的命令行,在Linux命令终端中查看和编辑曾执行过的命令 – LINUX笔记 – CFEI.NET...

今天我们来讲讲linux的知识,积累的这些知识就是我们以后的财富,各位加油.

因为水平有限,难免有疏忽或者不准确的地方,希望大家能够直接指出来,我会及时改正。一切为了知识的分享。

history 命令可以用来显示曾执行过的命令,也可以根据显示的治疗来重新执行需要的命令

n 显示n个最近的记录

-a 添加记录

-r 读取记录,但不会添加内容记录

-w 覆盖原有的history 文件

-c 清除记录

-d[n] 删除指定n条记录

-n 读取指定文件

-r 读取文件但不记录

-w 覆盖原有文件

例1

[root@redhat ~]# history #查看所有执行过的命令

1  ls

2  pwd

3  fc -l

4  history

[root@redhat ~]# history 2 #显示2条

4  history

5  history 2

[root@redhat ~]# !4 #执行编号是4的命令,注意感叹号

history

1  ls

2  pwd

3  fc -l

4  history

5  history 2

6  history

[root@redhat ~]# history -c #清除历史记录

!$ 引用前一个命令的最后一个参数

[tank@localhost workspace]$ ls -all

总用量 1060

drwxrwxr-x. 15 tank tank    4096 8月   6 16:26 .

drwx------. 60 tank tank    4096 8月  15 16:13 ..

-rw-r--r--   1 root root    2466 7月  23 18:02 1.html

drwxr-xr-x   7 tank tank    4096 7月  17 03:02 ckeditor

drwxr-xr-x.  2 tank tank    4096 5月  29 00:08 database

[tank@localhost workspace]$ !$ #取得-all

-all

bash: -all: command not found

例2

[root@redhat ~]# ! -N #执行倒数第N条命令

[root@redhat ~]# !! #执行上一条命令

fcfc 命令可以编辑曾今执行过的命令,并以批处理的形式让这些命令重新执行

-1 列出第一个指令和最后一个指令之间额度所有指令

-n 不显示编号

-r 反向排序

-e 指定文本编辑器编辑,默认Vi

-s 选择指令执行

例1

[root@redhat ~]# fc -l #查看执行过的命令,根history,很相似

348      eval echo "aaa" ls

349      eval echo "aaa";ls

350      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'358      expr 6 '+' 5

359      expr 6 '*' 5

360      expr 6 '>' 5

361      fc -l

362      man fc

363      fc --help

[root@redhat ~]# fc -s 358 #执行第358个命令

expr 6 '+' 5

11

[root@redhat ~]# fc 358 #编辑第358个命令

好啦,今天飞哥就讲到这里,后续会有更多的精彩的内容分享给大家,希望对大家能够有所帮助,也希望大家能多多支持飞网,让我们共同进步。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以记录常用的linux命令,特别是比较长的,非常有用。使用方法:把该Q可执行文件考备份到linux上,任何目录都,第一次执行用./q的方式执行,第一次执行之后q程序会被加到系统目录,以后每次执行都可以像使用系统命令一样。例如 1.查看保存过的命令 [root@localhost ~]# q 1_____clear 2_____tar -xzvf 3_____tar -czvf 4_____rpm -ivh 5_____lsnrctl status 6_____lsnrctl start 7_____lsnrctl stop 8_____vi /home/oracle/ora/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora 9_____/opt/lampp/lampp start 10_____/opt/lampp/lampp restart 11_____/opt/lampp/lampp stop 2.添加新命令 [root@localhost ~]# q -a "sqlplus /as sysdba" 1_____clear 2_____tar -xzvf 3_____tar -czvf 4_____rpm -ivh 5_____lsnrctl status 6_____lsnrctl start 7_____lsnrctl stop 8_____vi /home/oracle/ora/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora 9_____/opt/lampp/lampp start 10_____/opt/lampp/lampp restart 11_____/opt/lampp/lampp stop 12_____sqlplus /as sysdba 3.删除命令 [root@localhost ~]# q -d 12 1_____clear 2_____tar -xzvf 3_____tar -czvf 4_____rpm -ivh 5_____lsnrctl status 6_____lsnrctl start 7_____lsnrctl stop 8_____vi /home/oracle/ora/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora 9_____/opt/lampp/lampp start 10_____/opt/lampp/lampp restart 11_____/opt/lampp/lampp stop 4.执行保存过的命令 [root@localhost ~]# q 10 Stopping XAMPP for Linux 1.8.1... XAMPP: Stopping Apache with SSL... XAMPP: Stopping MySQL... XAMPP: XAMPP-ProFTPD is not running. XAMPP stopped.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值