专业的编程技术博客社区

网站首页 > 博客文章 正文

Windows终端保存历史记录工具(windows终端怎么查看目录)

baijin 2024-08-08 23:02:29 博客文章 88 ℃ 0 评论

Windows终端cmd貌似没有保存历史记录的功能,每次打开一个终端都空空如也,当然也有一些Windows终端软件可以使用,可我偏想折腾一下。

原理很简单就是用.bat批处理文件实现的,下图就是所有文件。



使用方法

在终端分别输入下面指令实现保存、查看、删除

hysave 保存当前cmd输入过的历史记录

hyshow 显示所有保存的记录

hyrm 删除指定行的内容

配置方法

将下面的脚本和文件放在一个自定义的文件夹内

将此文件夹添加到环境变量中

脚本及文件

创建三个文本文件

cmd.txt 用于保存显示的内容(会去重)

cmdall.txt 用于保存所有的历史记录(去重后保存到cmd.txt中)

cmdtemp.txt 删除指定行内容的临时文件

创建四个脚本

保存所有的历史记录到cmdall.txt文件中

@echo off
set currentdir=%~dp0
doskey /history >> %currentdir%\cmdall.txt
hycompare.bat

cmdall.txt与cmd.txt对比cmd.txt中没有的命令则添加(去重)

@echo off
rem 首先输入下面命令 打开 延迟环境变量 这样可以使用!find!获取变量
rem cmd /v:on
rem 或用下面的
setlocal EnableDelayedExpansion
rem 保存历史记录到文件
rem doskey /history >> d:\cmdall.txt
set currentdir=%~dp0
set file1=%currentdir%\cmdall.txt
set file2=%currentdir%\cmd.txt
if not exist %file1% type NUL > %file1%
if not exist %file2% type NUL > %file2%
set find=0
for /f "delims=" %%i in (%file1%) do (
set find=0
for /f "delims=" %%j in (%file2%) do (
if %%i equ %%j (
set find=1
)
)
if "!find!"=="0" echo %%i>> %file2%
)

显示cmd.txt文本内容

@echo off
set currentdir=%~dp0
cat %currentdir%\cmd.txt

删除指定行内容

@echo off
setlocal EnableDelayedExpansion
set currentdir=%~dp0
set file1=%currentdir%\cmdall.txt
set file2=%currentdir%\cmd.txt
set file3=%currentdir%\cmdtemp.txt
type NUL > %file1%
type NUL > %file3%
set /a find=0
for /f "tokens=*" %%i in (%file2%) do (
set /a find+=1
if !find! neq %1 echo %%i>>%file3%
)
copy %file3% %file2%
hyshow.bat

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表