Windows batch 命令学习记录

1. 复制文件:

copy 文件 目的地
例如 copy C:\software\a.txt C:\test\

2. 用7-zip软件解压.zip文件

7-zip安装到系统后,找到安装目录下的7z.exe 和7z.dll文件,复制粘贴到C:\Windows\System32便可以在DOS直接应用

7z x abc.zip -oC:\test

x表示解压缩并保留全路径,可替换成e, -o后面直接跟目的地文件夹,这里是C:\test

3. 结束某进程

taskkill /f xxxx

/f表示强制结束进程,xxxx表示进程名称,即windows 任务管理器里看到的进程名称

 4. 找到当前目录下最新创建的文件夹:

FOR /F "delims=" %%i IN ('dir /b /ad-h /t:c /od') DO SET a=%%i
echo Most recent subfolder: %a%

(%i for windows 10)

  • /b is for bare format
  • /ad-h only directories, but not the hidden ones
  • t:c means to use the creation date for sorting (use t:w for last write date)
  • /od sort oldest first
  • The for /F executes the command and sets a to the directory name, the last one is the newest one.

 5. 打印当前路径:

echo %cd%

注意,如下两种打印,值都一样(假设C盘下有folder1,里面有folder2)cd folder1
echo %cd%
cd folder2
echo %cd%

执行结果:
C:\folder1
C:\folder1

 6. 查看被占用端口的PID:

netstat -aon|findstr "8081"
posted @ 2021-09-06 05:23  钱_进  阅读(147)  评论(0编辑  收藏  举报