:: 注释
rem @echo off
cd /d d:\\Redis
:: redis-cli
:: shutdown
:: exit
:: netstat -ano |findstr "6639"
:: taskkill /pid {pid} /F
redis-server redis.windows.conf
pause
1
2
3
4
5
6
7
8
9
10
cmd中替代grep的命令findstr
查看进程命令tastlist
杀死进程命令 taskkill /pid {pid} /F
@echo与echo
cmd查看环境变量
set 命令
set path 查看path变量值
1
2
bat脚本案例
杀死占用8888端口的进程
@echo off
set"port=8888"
REM 查找占用指定端口的进程
for /f "tokens=5" %%a in('netstat -a -n -o ^| findstr /r ":%port%"')do(set"pid=%%a")
REM 如果找到匹配的进程,杀死它
if defined pid (
taskkill /F /PID %pid%
echo Process with PID %pid% using port %port% has been terminated.
)else(echo No process found using port %port%.
)
1
2
3
4
5
6
7
8
9
10
11
12
13
杀死此目录下的.zip文件
@echo off
set"target_directory=C:\Your\Target\Directory" REM 替换为你的目标目录
cd /d "%target_directory%" REM 切换到目标目录
REM 删除所有 .zip 文件
for %%i in(*.zip)do(
del "%%i"echo Deleted "%%i")echo All .zip files in %target_directory% have been deleted.