linux能记录日志的终端,Linux终端记录神器

原标题:Linux终端记录神器

导读我们在调试程序的时候,免不了要去抓一些 log ,然后进行分析。如果 log 量不是很大的话,那很简单,只需简单的复制粘贴就好。但是如果做一些压力测试,产生大量 log ,而且系统内存又比较小(比如嵌入式设备),那要怎么处理呢?当然,secureCRT 和 mobaXterm 都有将日志保存到本地的功能,使用起来也是很方便。但是有些工具,比如 putty,就没这样的功能了。这时终端里的记录器—— 就派上用场了。

使用场景

1、调试会产生大量 log 的应用程序,并且需要保存到本地进行进一步分析;

2、与同事协同工作,自己将工作完成了一半,可以将操作过程记录下来,发给同事,同事可以根据记录接着工作;

3、让人远程协助你,担心对方使坏,同时也可以留下案底,最好将他的操作记录下来

如何使用 命令?

默认情况下,直接输入 这个命令即可,它会在当前目录自动创建一个 type 文件,之后你在此终端的所有操作都会被记录在这个文件里。

记录文件是一个文本文件,可以使用任意的文本工具打开查看。

如果要退出记录,可以在终端里按快捷键 ctrl + D 或直接输入 exit 。在退出 前,你会发现,记录文件大小为 0 Kb,当退出后,文件大小会变大。

[alvin@VM_0_16_centos test]$

started, file is type

[alvin@VM_0_16_centos test]$ echo hello

hello

[alvin@VM_0_16_centos test]$ ls

test1.py test2 test2.cpp test2.py test3 test3.c test.py type WeixinBot wxpy wxRobot

[alvin@VM_0_16_centos test]$ exit

exit

done, file is type

如果我们想要自己起个文件名,或者将文件放在其它位置,那么我们可以直接在 后面跟上文件名即可。

[alvin@VM_0_16_centos test]$ ~/alvin-

started, file is /home/alvin/alvin-

[alvin@VM_0_16_centos test]$ ll

total 64

-rw-rw-r-- 1 alvin alvin 21 Nov 10 09:40 test1.py

-rwxrwxr-x 1 alvin alvin 14074 Dec 31 07:35 test2

-rw-rw-r-- 1 alvin alvin 403 Dec 31 07:35 test2.cpp

-rw-rw-r-- 1 alvin alvin 2093 Nov 10 10:50 test2.py

-rwxrwxr-x 1 alvin alvin 8553 Jan 7 20:03 test3

-rw-rw-r-- 1 alvin alvin 78 Jan 7 20:03 test3.c

-rw-rw-r-- 1 alvin alvin 94 Nov 9 23:25 test.py

-rw-rw-r-- 1 alvin alvin 489 Jan 11 12:07 type

drwxrwxr-x 6 alvin alvin 4096 Nov 10 11:19 WeixinBot

drwxrwxr-x 6 alvin alvin 4096 Nov 10 11:30 wxpy

drwxrwxr-x 11 alvin alvin 4096 Nov 10 11:34 wxRobot

[alvin@VM_0_16_centos test]$ echo hello

hello

[alvin@VM_0_16_centos test]$ exit

exit

done, file is /home/alvin/alvin-

学会这两个基本操作,可以应付很多场景下需要记录终端的场景。

如何使用 与同事协作?

现在有一项工作,需要与同事一起协作,我完成一半,他完成另一半。

首先,我来做我的工作,用 记录一下我的工作过程:

[alvin@VM_0_16_centos test]$ cooperate-job

started, file is cooperate-job

[alvin@VM_0_16_centos test]$ echo this is alvin_s job

this is alvin_s job

[alvin@VM_0_16_centos test]$ ls

cooperate-job test1.py test2 test2.cpp test2.py test3 test3.c test.py type WeixinBot wxpy wxRobot

[alvin@VM_0_16_centos test]$ exit

exit

done, file is cooperate-job

工作完成之后,将记录文件发给同事,他可以使用文本工具打开,就可以知道你的进度了,然后接着你的进度干活。

如果他要接着在你的记录文件里记录他的操作的话,可以加一个 -a 选项,即 append 的缩写。

[alvin@VM_0_16_centos test]$ -a cooperate-job

started, file is cooperate-job

[alvin@VM_0_16_centos test]$ echo this is harry_s job

this is harry_s job

[alvin@VM_0_16_centos test]$ pwd

/home/alvin/test

[alvin@VM_0_16_centos test]$ exit

exit

done, file is cooperate-job

请他人远程协助时,如何记录他的操作过程?

让他人登陆到自己的电脑,如果是熟人还好,是陌生人的话心里多少会有些不踏实。为了放心一下,我们还是偷偷记录一下他的所作所为吧。

我们可以将 命令添加到 Shell 配置文件中,用户一旦登录进来, 命令就自动启动,并记录操作者的所有操作过程。

实现这个目的,我们可以修改 .bash_profile 文件。

vim ~/.bash_profile

在最后一行,我们将 命令添加进去:

/usr/bin/ -qa your_path #补齐自己的路径

然后保存,使用 source 或 . 命令使它生效。下次其它人登录到系统时, 就会自动运行,并将记录文件保存在你所指定的位置。

在这里,-q 选项代表静默记录,对方将不知道你在后台记录。如果不使用这个选项,则他会收到这个提示:

Last login: Fri Jan 11 15:13:37 2019 from 119.33.28.6

started, file is /home/alvin/test/-file #提示返回搜狐,查看更多

责任编辑:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值