(转)Linux清除历史记录命令
Link:http://blog.csdn.net/sflsgfs/article/details/6313452
步骤如下:
1、建立一个文件来存储常用命令,例如/root/history.txt,把常用命令当成文本写进去,每个命令占一行
2、在终端运行history -c,清除杂乱的历史记录
3、运行history -r /root/history.txt,把命令读进来作为当前bash的历史记录
4、运行history,就得到一个整洁的命令列表了,例如:
[root@localhost windata]# history -c
[root@localhost windata]# history -r /root/history.txt
[root@localhost windata]# history
1 history -r /root/history.txt
2 mount -t msdos -o iocharset=gb2312 /dev/sda1 /mnt/usb
3 mount -t vfat -o iocharset-gb2312 /dev/hda5 /mnt/windata
4 umount /mnt/windata
5 mount -t vfat -o iocharset-gb2312 /dev/hda5 /mnt/windata
6 cd /mnt/windata
7 history
[root@localhost windata]#
5、以后命令乱了,重复1-4的步骤,又可以使命令很清晰了。
1、清除登陆系统成功的记录,也就是last命令看到的记录
[root@linuxzgf ~]echo > /var/log/wtmp 此文件默认打开时乱码的,里面可以看到ip等等信息
验证过程
[root@linuxzgf ~]#last
root pts/0 10.5.10.51 Thu Sep 2 00:59 still logged in
root pts/2 10.5.10.60 Wed Sep 1 16:11 - 17:47 (01:35)
root pts/2 10.5.10.60 Wed Sep 1 16:08 - 16:10 (00:02)
root pts/0 10.5.10.61 Wed Sep 1 14:16 - 23:02 (08:46)
root pts/3 10.5.10.59 Wed Sep 1 11:28 - 19:38 (08:10)
root pts/2 10.5.10.60 Wed Sep 1 11:18 - 16:07 (04:49)
root pts/1 10.5.10.191 Wed Sep 1 11:17 - 19:12 (07:55)
。。。。。。。。。。。。。。。。。。。。。。。
[root@linuxzgf ~]#echo >/var/log/wtmp
[root@linuxzgf ~]#last
wtmp begins Thu Sep 2 01:04:34 2010
[root@linuxzgf ~]#
此时即看不到用户登录信息
2、清除登陆系统失败的记录,也就是lastb命令看到的记录
[root@linuxzgf ~]echo > /var/log/btmp 此文件默认打开时乱码的
验证方法
在执行命令前执行lastb如下
[root@linuxzgf ~]#lastb
root ssh:notty 10.5.10.60 Wed Sep 1 16:11 - 16:11 (00:00)
tty6 Mon Aug 30 22:53 - 22:53 (00:00)
tty6 Mon Aug 30 18:52 - 18:52 (00:00)
tty6 Mon Aug 30 18:52 - 18:52 (00:00)
++++++ tty6 Mon Aug 30 18:52 - 18:52 (00:00)
linuxzgf ssh:notty 10.5.10.60 Mon Aug 30 11:21 - 11:21 (00:00)
linuxzgf ssh:notty 10.5.10.60 Mon Aug 30 09:37 - 09:37 (00:00)
。。。。。。。。。
然后执行
[root@linuxzgf ~]#echo > /var/log/btmp
[root@linuxzgf ~]#lastb
btmp begins Thu Sep 2 01:01:06 2010
此时就没有结果输出了
是不是很爽
3、清除历史执行命令
[root@linuxzgf ~]history -c
或者
清空用户目录下的这个文件即可
[root@linuxzgf ~]> ~/.bash_history
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· [AI/GPT/综述] AI Agent的设计模式综述