# Windows 控制台命令教学指南
本教程涵盖 Windows 系统中最常用的 CMD 和 PowerShell 命令,每个命令都配有模拟控制台输出,让你像在真实终端中操作一样直观理解。适合初学者快速上手。
目录
一、文件与目录操作
1. dir - 列出目录内容
dir 是 Windows 中最常用的目录列表命令,相当于 Linux 的 ls。
基本用法:显示当前目录
dirC:\Users\John> dir
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\John
05/12/2026 09:30 AM <DIR> .
05/12/2026 09:30 AM <DIR> ..
05/10/2026 02:22 PM <DIR> Desktop
05/11/2026 06:05 PM <DIR> Documents
05/09/2026 10:15 AM <DIR> Downloads
04/28/2026 10:00 AM <DIR> Music
05/01/2026 08:15 PM <DIR> Pictures
04/15/2026 08:30 AM <DIR> Videos
0 File(s) 0 bytes
8 Dir(s) 150,000,000,000 bytes free输出解读:
Volume in drive C:C 盘的卷标名称<DIR>:表示这是一个目录(文件夹).和..:分别表示当前目录和上级目录- 底部统计:文件数、目录数、剩余空间
宽列表格式:每行显示多个项目
dir /wC:\Users\John> dir /w
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\John
[.] [..] Desktop Documents
Downloads Music Pictures Videos
0 File(s) 0 bytes
8 Dir(s) 150,000,000,000 bytes free输出解读:/w 以宽列表格式显示,适合快速浏览。显示所有文件:包括隐藏文件和系统文件
dir /aC:\Users\John> dir /a
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\John
05/12/2026 09:30 AM <DIR> .
05/12/2026 09:30 AM <DIR> ..
05/01/2026 12:00 PM <DIR> AppData
05/01/2026 12:00 PM 220 .bash_history
05/01/2026 12:00 PM 1,200 NTUSER.DAT
05/10/2026 02:22 PM <DIR> Desktop
...输出解读:/a 显示所有文件,包括隐藏文件和系统文件。按日期排序:最旧的在前
dir /o:dC:\Users\John> dir /o:d
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\John
04/15/2026 08:30 AM <DIR> Videos
04/28/2026 10:00 AM <DIR> Music
05/01/2026 08:15 PM <DIR> Pictures
05/09/2026 10:15 AM <DIR> Downloads
05/10/2026 02:22 PM <DIR> Documents
05/11/2026 06:05 PM <DIR> Desktop
...输出解读:/o:d按日期排序(最旧的在前)。/o:-d则相反(最新的在前)。
递归显示:包含所有子目录
dir /sC:\Users\John> dir /s
Volume in drive C is Windows
Volume Serial Number is XXXX-XXXX
Directory of C:\Users\John\Documents
05/10/2026 02:22 PM <DIR> .
05/10/2026 02:22 PM <DIR> ..
05/10/2026 02:22 PM 5,120 report.docx
05/11/2026 09:30 AM 2,048 notes.txt
2 File(s) 7,168 bytes
Directory of C:\Users\John\Documents\Projects
05/11/2026 10:00 AM <DIR> .
05/11/2026 10:00 AM <DIR> ..
05/11/2026 10:00 AM 15,360 project.pptx
1 File(s) 15,360 bytes
Total Files Listed:
3 File(s) 22,528 bytes
10 Dir(s) 150,000,000,000 bytes free输出解读:/s 递归显示所有子目录的内容,并在最后给出总计统计。2. cd / chdir - 切换目录
cd(Change Directory)用于在不同的目录之间切换。
进入指定目录
cd DocumentsC:\Users\John> cd Documents
C:\Users\John\Documents>返回上一级目录
cd ..C:\Users\John\Documents\Projects> cd ..
C:\Users\John\Documents>返回上两级目录
cd ..\..C:\Users\John\Documents\Projects\Web\Frontend> cd ..\..
C:\Users\John\Documents>输出解读:Windows 使用反斜杠 \ 作为路径分隔符。返回根目录
cd \C:\Users\John\Documents> cd \
C:\>返回用户主目录
cd %USERPROFILE%C:\Windows\System32> cd %USERPROFILE%
C:\Users\John>输出解读:%USERPROFILE% 是环境变量,表示当前用户的主目录。切换到不同驱动器
cd /d D:\GamesC:\Windows\System32> cd /d D:\Games
D:\Games>输出解读:/d 参数允许切换到不同驱动器。3. mkdir / md - 创建目录
mkdir(Make Directory)用于创建新目录,可以简写为 md。
创建单个目录
mkdir MyFolderC:\Users\John> mkdir MyFolder
C:\Users\John> dir
...
05/12/2026 10:00 AM <DIR> MyFolder
...创建多级目录
mkdir Parent\Child\GrandchildC:\Users\John> mkdir Parent\Child\Grandchild
C:\Users\John> tree Parent
Folder PATH listing
Volume serial number is XXXX-XXXX
C:\USERS\JOHN\PARENT
└───Child
└───Grandchild输出解读:Windows 的 mkdir 默认会自动创建所有不存在的父目录,不需要像 Linux 那样加参数。同时创建多个目录
md Folder1 Folder2 Folder3C:\Users\John> md Folder1 Folder2 Folder3
C:\Users\John> dir
...
05/12/2026 10:05 AM <DIR> Folder1
05/12/2026 10:05 AM <DIR> Folder2
05/12/2026 10:05 AM <DIR> Folder3
...4. rmdir / rd - 删除目录
rmdir(Remove Directory)用于删除目录,可以简写为 rd。
删除空目录
rmdir EmptyFolderC:\Users\John> rmdir EmptyFolder
C:\Users\John> dir
...删除非空目录会报错
rmdir MyFolderC:\Users\John> rmdir MyFolder
The directory is not empty.输出解读:如果目录不为空,需要加 /s 参数才能删除。递归删除目录:会询问确认
rmdir /s MyFolderC:\Users\John> rmdir /s MyFolder
MyFolder, Are you sure (Y/N)? y
C:\Users\John>安静模式删除:不询问确认
rmdir /s /q TempFolderC:\Users\John> rmdir /s /q TempFolder
C:\Users\John>输出解读:/q 安静模式,不询问确认,直接删除。⚠️ 谨慎使用!5. del / erase - 删除文件
del 用于删除文件,是 Windows 中最需要谨慎使用的命令之一。
删除单个文件
del notes.txtC:\Users\John\Documents> dir
...
05/10/2026 02:22 PM 5,120 report.docx
05/11/2026 09:30 AM 2,048 notes.txt
...
C:\Users\John\Documents> del notes.txt
C:\Users\John\Documents> dir
...
05/10/2026 02:22 PM 5,120 report.docx
...批量删除:使用通配符
del *.tmpC:\Users\John\Documents> del *.tmp
C:\Users\John\Documents>输出解读:使用通配符 * 删除所有匹配的文件。删除前确认
del /p important.txtC:\Users\John\Documents> del /p important.txt
C:\Users\John\Documents\important.txt, Delete (Y/N)? n输出解读:输入 n 取消删除。强制删除只读文件
del /f /q *.logC:\Users\John\Documents> del /f /q *.log
C:\Users\John\Documents>输出解读:
/f强制删除只读文件,/q安静模式不询问。⚠️ 警告:
del /f /s /q C:\*会尝试删除 C 盘所有文件,切勿执行!
6. copy - 复制文件
copy 用于复制文件。
基本用法:复制单个文件
copy report.docx backup.docxC:\Users\John\Documents> copy report.docx backup.docx
1 file(s) copied.
C:\Users\John\Documents> dir
...
05/10/2026 02:22 PM 5,120 report.docx
05/12/2026 10:15 AM 5,120 backup.docx
...批量复制:使用通配符
copy *.txt D:\Backup\C:\Users\John\Documents> copy *.txt D:\Backup\
notes.txt
readme.txt
todo.txt
3 file(s) copied.输出解读:会列出每个被复制的文件名。
复制并重命名
copy report.docx D:\Backup\weekly_report.docxC:\Users\John\Documents> copy report.docx D:\Backup\weekly_report.docx
1 file(s) copied.覆盖时不询问
copy /y config.txt config.bakC:\Users\John> copy /y config.txt config.bak
1 file(s) copied.输出解读:/y 覆盖现有文件时不询问确认。7. xcopy - 高级复制
xcopy 是功能更强大的复制命令,支持复制目录树。
复制目录:包括空目录
xcopy Documents D:\Backup\Documents /s /eC:\Users\John> xcopy Documents D:\Backup\Documents /s /e
Does D:\Backup\Documents specify a file name
or directory name on the target (F = file, D = directory)? d
Documents\report.docx
Documents\notes.txt
Documents\Projects\project.pptx
3 File(s) copied输出解读:
/s复制目录和子目录(不包括空目录)/e复制目录和子目录(包括空目录)- 系统会询问目标是文件还是目录
完整参数示例
xcopy C:\Project D:\Backup\Project /s /e /h /r /y输出解读:
/h复制隐藏文件和系统文件/r覆盖只读文件/y覆盖时不询问确认
8. robocopy - 可靠的文件复制
robocopy(Robust File Copy)是 Windows 最强大的复制工具,适合大量文件或网络复制。
镜像模式:使目标与源完全一致
robocopy Documents D:\Backup\Documents /MIRC:\Users\John> robocopy Documents D:\Backup\Documents /MIR
-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows
-------------------------------------------------------------------------------
Started : Saturday, May 12, 2026 10:30:00 AM
Source : C:\Users\John\Documents\
Dest : D:\Backup\Documents\
Files : *.*
Options : *.* /S /E /DCOPY:DA /COPY:DAT /PURGE /MIR /R:1000000 /W:30
------------------------------------------------------------------------------
3 C:\Users\John\Documents\
New File 5120 report.docx
New File 2048 notes.txt
New Dir 15360 Projects\
New File 15360 project.pptx
------------------------------------------------------------------------------
Total Copied Skipped Mismatch FAILED Extras
Dirs : 2 2 0 0 0 0
Files : 3 3 0 0 0 0
Bytes : 22.5 k 22.5 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00
Ended : Saturday, May 12, 2026 10:30:02 AM输出解读:
/MIR镜像模式,会删除目标中多余的文件- 详细的统计报告:目录数、文件数、字节数、耗时
网络复制:支持断点续传和多线程
robocopy C:\Data \\Server\Share /E /Z /R:3 /W:5 /MT:8输出解读:
/E包括空目录/Z可重启模式(网络中断后可恢复)/R:3失败重试 3 次/W:5每次重试等待 5 秒/MT:8使用 8 个线程并行复制
9. move - 移动或重命名文件
move 用于移动文件到其他目录,或者给文件重命名。
重命名文件
move oldname.txt newname.txtC:\Users\John\Documents> move oldname.txt newname.txt
1 file(s) moved.
C:\Users\John\Documents> dir
...
05/12/2026 10:20 AM 2,048 newname.txt
...移动文件到其他目录
move report.docx D:\Archive\C:\Users\John\Documents> move report.docx D:\Archive\
1 file(s) moved.批量移动
move /y C:\Temp\*.* D:\Backup\C:\Users\John> move /y C:\Temp\*.* D:\Backup\
15 file(s) moved.10. rename / ren - 重命名文件
rename 专门用于重命名文件,可以简写为 ren。
基本用法
ren report.docx monthly_report.docxC:\Users\John\Documents> ren report.docx monthly_report.docx
C:\Users\John\Documents> dir
...
05/10/2026 02:22 PM 5,120 monthly_report.docx
...批量重命名
ren *.txt *.bakC:\Users\John\Documents> ren *.txt *.bak
C:\Users\John\Documents> dir
...
05/11/2026 09:30 AM 2,048 notes.bak
05/11/2026 09:35 AM 1,024 readme.bak
...输出解读:将所有.txt文件改为.bak。
11. type - 查看文件内容
type 相当于 Linux 的 cat,用于显示文本文件内容。
基本用法
type notes.txtC:\Users\John\Documents> type notes.txt
This is my first note.
Remember to backup files regularly.
Meeting at 3 PM tomorrow.合并多个文件
type file1.txt file2.txt > merged.txtC:\Users\John\Documents> type file1.txt file2.txt > merged.txt
C:\Users\John\Documents> type merged.txt
Content from file1
Content from file212. findstr - 文本搜索
findstr 是 Windows 的文本搜索工具,相当于 Linux 的 grep。
基本搜索
findstr "ERROR" server.logC:\Users\John\Logs> findstr "ERROR" server.log
2026-05-12 08:03:15 ERROR Failed to send email: connection refused
2026-05-12 09:58:00 ERROR Disk space low: C: at 92%显示行号
findstr /n "ERROR" server.logC:\Users\John\Logs> findstr /n "ERROR" server.log
6:2026-05-12 08:03:15 ERROR Failed to send email: connection refused
50:2026-05-12 09:58:00 ERROR Disk space low: C: at 92%输出解读:/n 显示行号。忽略大小写
findstr /i "error" server.logC:\Users\John\Logs> findstr /i "error" server.log
2026-05-12 08:03:15 ERROR Failed to send email: connection refused
2026-05-12 08:15:00 error retrying connection to database
2026-05-12 09:58:00 ERROR Disk space low: C: at 92%输出解读:/i 忽略大小写。递归搜索
findstr /s "TODO" *.txtC:\Users\John\Logs> findstr /s "TODO" *.txt
Projects\readme.txt:TODO: Add installation instructions
Projects\todo.txt:TODO: Fix memory leak
Documents\notes.txt:TODO: Update documentation输出解读:/s递归搜索当前目录及子目录中的所有.txt文件。
反向匹配
findstr /v "INFO" server.logC:\Users\John\Logs> findstr /v "INFO" server.log
2026-05-12 08:01:30 WARN Request timeout for /api/data
2026-05-12 08:03:15 ERROR Failed to send email: connection refused
2026-05-12 09:56:30 WARN Memory usage at 85%
2026-05-12 09:58:00 ERROR Disk space low: C: at 92%输出解读:/v 反向匹配,只显示不包含 "INFO" 的行。13. tree - 显示目录结构
tree 以树形结构显示目录层次。
只显示目录
treeC:\Users\John> tree
Folder PATH listing
Volume serial number is XXXX-XXXX
C:\USERS\JOHN
├───Desktop
├───Documents
│ ├───Projects
│ │ └───Web
│ └───Reports
├───Downloads
├───Music
├───Pictures
└───Videos同时显示文件和目录
tree /fC:\Users\John> tree /f
Folder PATH listing
Volume serial number is XXXX-XXXX
C:\USERS\JOHN
├───Desktop
│ shortcut.lnk
│
├───Documents
│ │ report.docx
│ │ notes.txt
│ │
│ ├───Projects
│ │ │ project.pptx
│ │ │
│ │ └───Web
│ │ index.html
│ │ style.css
│ │
│ └───Reports
│ annual_report.pdf
...输出解读:/f 同时显示文件,不只是目录。二、文件查看与编辑
1. more - 分页查看文件
more 用于分页查看大文件内容。
基本用法
more server.logC:\Users\John\Logs> more server.log
2026-05-12 08:00:01 INFO Server started on port 8080
2026-05-12 08:00:05 INFO Database connection established
2026-05-12 08:00:12 INFO User admin logged in
2026-05-12 08:01:30 WARN Request timeout for /api/data
2026-05-12 08:02:00 INFO Cache cleared successfully
-- More (24%) --输出解读:显示文件内容,底部显示进度百分比。按空格键继续,按 q 退出。more 常用按键
| 按键 | 功能 |
|---|---|
空格 | 向下翻页 |
Enter | 向下滚动一行 |
q | 退出 |
2. notepad - 打开记事本
打开或创建文件
notepad notes.txtC:\Users\John\Documents> notepad notes.txt输出解读:使用系统自带的记事本打开或创建文件。
三、系统管理
1. systeminfo - 查看系统信息
systeminfo 显示详细的系统配置信息。
基本用法
systeminfoC:\Users\John> systeminfo
Host Name: DESKTOP-ABC123
OS Name: Microsoft Windows 11 Pro
OS Version: 10.0.26100 N/A Build 26100
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Workstation
OS Build Type: Multiprocessor Free
Registered Owner: John
Product ID: XXXXX-XXXXX-XXXXX-XXXXX
Original Install Date: 1/15/2026, 10:00:00 AM
System Boot Time: 5/12/2026, 8:00:00 AM
System Manufacturer: Dell Inc.
System Model: XPS 15 9520
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: Intel64 Family 6 Model 154 Stepping 3 GenuineIntel ~2500 Mhz
BIOS Version: Dell Inc. 1.15.0, 3/15/2026
Total Physical Memory: 32,768 MB
Available Physical Memory: 12,345 MB
Virtual Memory: Max Size: 65,536 MB
Virtual Memory: Available: 45,678 MB
Virtual Memory: In Use: 19,858 MB
Network Card(s): 2 NIC(s) Installed.
[01]: Intel(R) Wi-Fi 6E AX211
[02]: Bluetooth Device (Personal Area Network)输出解读:包含操作系统版本、硬件信息、内存使用、网络配置等详细信息。
2. ver - 查看 Windows 版本
基本用法
verC:\Users\John> ver
Microsoft Windows [Version 10.0.26100.1]输出解读:显示 Windows 内核版本号。Windows 11 显示为 10.0.xxx 是因为它与 Windows 10 共享内核。
3. hostname - 查看计算机名
基本用法
hostnameC:\Users\John> hostname
DESKTOP-ABC1234. cls - 清屏
基本用法
clsC:\Users\John> cls输出解读:清空屏幕上的所有内容。
5. echo - 显示消息
显示文本
echo Hello, World!C:\Users\John> echo Hello, World!
Hello, World!显示环境变量
echo %date%
echo %PATH%C:\Users\John> echo Current date: %date%
Current date: 2026/05/12 周一
C:\Users\John> echo %PATH%
C:\Windows\system32;C:\Windows;C:\Program Files\nodejs;...输出解读:%变量名% 是 Windows 的环境变量引用方式。6. set - 查看/设置环境变量
查看所有环境变量
setC:\Users\John> set
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\John\AppData\Roaming
COMPUTERNAME=DESKTOP-ABC123
HOMEDRIVE=C:
HOMEPATH=\Users\John
PATH=C:\Windows\system32;C:\Windows;...
TEMP=C:\Users\John\AppData\Local\Temp
TMP=C:\Users\John\AppData\Local\Temp
USERDOMAIN=DESKTOP-ABC123
USERNAME=John
USERPROFILE=C:\Users\John
...查看特定变量
set JAVA_HOMEC:\Users\John> set JAVA_HOME
JAVA_HOME=C:\Program Files\Java\jdk-17设置临时变量
set MY_VAR=HelloC:\Users\John> set MY_VAR=Hello
C:\Users\John> echo %MY_VAR%
Hello输出解读:设置临时环境变量(只在当前 CMD 窗口有效)。
四、网络相关
1. ping - 测试网络连通性
基本用法
ping google.comC:\Users\John> ping google.com
Pinging google.com [142.250.80.14] with 32 bytes of data:
Reply from 142.250.80.14: bytes=32 time=12ms TTL=117
Reply from 142.250.80.14: bytes=32 time=11ms TTL=117
Reply from 142.250.80.14: bytes=32 time=13ms TTL=117
Reply from 142.250.80.14: bytes=32 time=12ms TTL=117
Ping statistics for 142.250.80.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 11ms, Maximum = 13ms, Average = 12ms输出解读:
- 默认发送 4 个数据包
time=12ms:往返延迟TTL=117:生存时间0% loss:无丢包,网络良好
自定义数据包数量和大小
ping -n 10 -l 1024 192.168.1.1输出解读:
-n 10发送 10 个数据包-l 1024每个数据包大小为 1024 字节
2. ipconfig - 查看网络配置
基本用法
ipconfigC:\Users\John> ipconfig
Windows IP Configuration
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . : home.network
IPv6 Address. . . . . . . . . . . : 2408:8210:1234:5678::1000
IPv4 Address. . . . . . . . . . . : 192.168.1.100
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1输出解读:
IPv4 Address:本机 IP 地址Subnet Mask:子网掩码Default Gateway:默认网关(路由器地址)
显示完整配置
ipconfig /all输出解读:/all 显示完整配置,包括 MAC 地址、DHCP 服务器、DNS 服务器等。释放并重新获取 IP 地址
ipconfig /release
ipconfig /renewC:\Users\John> ipconfig /release
C:\Users\John> ipconfig /renew输出解读:解决网络问题时常用。
清除 DNS 缓存
ipconfig /flushdnsC:\Users\John> ipconfig /flushdns
Windows IP Configuration
Successfully flushed the DNS Resolver Cache.3. netstat - 查看网络连接
基本用法
netstat -anC:\Users\John> netstat -an
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 192.168.1.100:49234 142.250.80.14:443 ESTABLISHED
TCP 192.168.1.100:49235 13.107.42.14:443 ESTABLISHED
TCP 192.168.1.100:49236 140.82.121.4:443 ESTABLISHED输出解读:
LISTENING:正在监听传入连接ESTABLISHED:已建立的连接-a显示所有连接和监听端口-n以数字形式显示地址和端口
查看特定端口
netstat -ano | findstr :80C:\Users\John> netstat -ano | findstr :80
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4567
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 5678输出解读:
-o显示进程 ID(PID)- 查找占用 80 端口的进程
4. tracert - 路由追踪
tracert(Trace Route)显示数据包到达目标的路由路径。
基本用法
tracert google.comC:\Users\John> tracert google.com
Tracing route to google.com [142.250.80.14]
over a maximum of 30 hops:
1 1 ms 1 ms 1 ms 192.168.1.1
2 10 ms 10 ms 10 ms 10.0.0.1
3 12 ms 12 ms 12 ms 172.16.0.1
4 15 ms 15 ms 15 ms beijing-router.net [202.96.12.34]
5 20 ms 20 ms 20 ms 142.250.80.14
Trace complete.输出解读:
- 显示从本机到目标经过的每一跳路由器
- 三列时间分别是三次探测的往返时间
- 可以判断网络延迟发生在哪一段
5. nslookup - DNS 查询
基本用法
nslookup google.comC:\Users\John> nslookup google.com
Server: UnKnown
Address: 192.168.1.1
Non-authoritative answer:
Name: google.com
Addresses: 2404:6800:4003:c02::64
142.250.80.14输出解读:
Server:当前使用的 DNS 服务器Name:查询的域名Addresses:域名对应的 IP 地址
查询 MX 记录
nslookup -type=mx gmail.com6. curl - 网络请求(Windows 10+)
Windows 10 版本 1803 及以后内置了 curl 命令。
GET 请求
curl https://api.github.com/users/githubC:\Users\John> curl https://api.github.com/users/github
{
"login": "github",
"id": 9919,
"type": "Organization",
"name": "GitHub",
"company": null,
"blog": "https://github.com/about",
"location": "San Francisco, CA",
...
}下载文件
curl -o file.zip https://example.com/file.zipC:\Users\John> curl -o file.zip https://example.com/file.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15.0M 100 15.0M 0 0 5200k 0 0:00:02 0:00:02 --:--:-- 5205k五、进程与服务
1. tasklist - 查看进程列表
tasklist 相当于 Linux 的 ps,显示正在运行的进程。
基本用法
tasklistC:\Users\John> tasklist
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
system idle process 0 Services 0 8 K
System 4 Services 0 140 K
explorer.exe 4520 Console 1 156,780 K
chrome.exe 5624 Console 1 245,760 K
Code.exe 6789 Console 1 312,456 K
notepad.exe 3456 Console 1 12,345 K
cmd.exe 7890 Console 1 8,192 K输出解读:
Image Name:进程名PID:进程 ID(结束进程时需要)Mem Usage:内存使用量
查找特定进程
tasklist | findstr "chrome"C:\Users\John> tasklist | findstr "chrome"
chrome.exe 5624 Console 1 245,760 K
chrome.exe 8940 Console 1 123,456 K显示服务信息
tasklist /svcC:\Users\John> tasklist /svc
Image Name PID Services
========================= ======== ============================================
svchost.exe 780 DcomLaunch, PlugPlay, Power
svchost.exe 888 RpcEptMapper, RpcSs, TermService
svchost.exe 960 Dhcp, Dnscache, NlaSvc, Themes2. taskkill - 结束进程
taskkill 用于结束一个或多个进程。
根据 PID 结束进程
taskkill /PID 3456C:\Users\John> taskkill /PID 3456
SUCCESS: Sent termination signal to the process with PID 3456.根据进程名结束进程
taskkill /F /IM notepad.exeC:\Users\John> taskkill /F /IM notepad.exe
SUCCESS: The process "notepad.exe" with PID 3456 has been terminated.输出解读:
/F强制终止/IM指定进程名(Image Name)
结束所有同名进程
taskkill /F /IM chrome.exeC:\Users\John> taskkill /F /IM chrome.exe
SUCCESS: The process "chrome.exe" with PID 5624 has been terminated.
SUCCESS: The process "chrome.exe" with PID 8940 has been terminated.
SUCCESS: The process "chrome.exe" with PID 9012 has been terminated.3. sc - 服务控制
sc(Service Control)用于查询、启动、停止系统服务。
查询所有服务
sc queryC:\Users\John> sc query
SERVICE_NAME: Dhcp
DISPLAY_NAME: DHCP Client
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING
SERVICE_NAME: Dnscache
DISPLAY_NAME: DNS Client
TYPE : 20 WIN32_SHARE_PROCESS
STATE : 4 RUNNING查询特定服务
sc query MySQLC:\Users\John> sc query MySQL
SERVICE_NAME: MySQL
TYPE : 10 WIN32_OWN_PROCESS
STATE : 4 RUNNING输出解读:STATE: 4 RUNNING 表示服务正在运行。停止服务
sc stop MySQLC:\Users\John> sc stop MySQL
SERVICE_NAME: MySQL
TYPE : 10 WIN32_OWN_PROCESS
STATE : 3 STOP_PENDING启动服务
sc start MySQLC:\Users\John> sc start MySQL
SERVICE_NAME: MySQL
TYPE : 10 WIN32_OWN_PROCESS
STATE : 2 START_PENDING
PID : 56784. net - 网络服务管理
net 命令功能丰富,可以管理服务、用户、共享等。
查看已启动的服务
net startC:\Users\John> net start
These Windows services are started:
Application Host Helper Service
Background Tasks Infrastructure Service
COM+ Event System
DHCP Client
DNS Client
Windows Event Log
Windows Update
Workstation
The command completed successfully.启动服务
net start MySQLC:\Users\John> net start MySQL
The MySQL service is starting.
The MySQL service was started successfully.停止服务
net stop MySQLC:\Users\John> net stop MySQL
The MySQL service is stopping.
The MySQL service was stopped successfully.5. shutdown - 关机/重启
关机:60 秒后
shutdown /s /t 60C:\Users\John> shutdown /s /t 60
Windows will shut down in less than a minute.输出解读:
/s关机/t 6060 秒后执行
立即重启
shutdown /r /t 0输出解读:
/r重启/t 0立即执行
取消关机/重启
shutdown /a强制关闭正在运行的应用程序
shutdown /s /f /t 0输出解读:/f 强制关闭正在运行的应用程序。六、磁盘管理
1. chkdsk - 检查磁盘
只读模式检查
chkdskC:\Users\John> chkdsk
The type of the file system is NTFS.
Stage 1: Examining basic file system structure ...
256000 file records processed.
File verification completed.
Stage duration (File record verification): 2.34 seconds.
Stage 2: Examining file name linkage ...
320000 index entries processed.
Index verification completed.
Stage duration (Index verification): 5.67 seconds.
Windows has scanned the file system and found no problems.
499999999 KB total disk space.
200000000 KB in 125000 files.
50000000 KB in 34561 indexes.
174999999 KB available on disk.
Total duration: 10.54 seconds (10540 ms).输出解读:只读模式检查磁盘,不会修复问题。
检查并修复磁盘
chkdsk D: /fC:\Users\John> chkdsk D: /f
The type of the file system is NTFS.
Cannot lock the drive.
Chkdsk cannot run because the volume is in use by another
process. Would you like to schedule this volume to be
checked the next time the system restarts? (Y/N)? y
This volume will be checked the next time the system restarts.输出解读:如果磁盘正在使用,可以安排在下次重启时检查。
2. diskpart - 磁盘分区工具
diskpart 是强大的磁盘管理工具,需要管理员权限。
查看磁盘列表
diskpart
list disk
select disk 0
list partition
exitC:\Users\John> diskpart
Microsoft DiskPart version 10.0.26100.1
DISKPART> list disk
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 500 GB 0 B *
Disk 1 Online 1000 GB 200 GB
DISKPART> select disk 0
Disk 0 is now the selected disk.
DISKPART> list partition
Partition ### Type Size Offset
------------- ---------------- ------- -------
Partition 1 System 100 MB 1024 KB
Partition 2 Reserved 16 MB 101 MB
Partition 3 Primary 499 GB 117 MB
DISKPART> exit输出解读:显示磁盘和分区的详细信息。
3. format - 格式化磁盘
基本用法
format D: /fs:ntfs /v:DataDriveC:\Users\John> format D: /fs:ntfs /v:DataDrive
The type of the file system is NTFS.
Enter current volume label for drive D: OldData
WARNING, ALL DATA ON NON-REMOVABLE DISK
DRIVE D: WILL BE LOST!
Proceed with Format (Y/N)? y
Formatting 1000.0 GB
0 percent completed.
...
100 percent completed.
Volume Serial Number is XXXX-XXXX输出解读:
/fs:ntfs指定文件系统为 NTFS/v:DataDrive设置卷标名称⚠️ 警告:格式化会删除所有数据!
七、用户管理
1. net user - 管理用户账户
查看所有用户
net userC:\Users\John> net user
User accounts for \\DESKTOP-ABC123
-------------------------------------------------------------------------------
Administrator DefaultAccount Guest
John WDAGUtilityAccount
The command completed successfully.查看用户详细信息
net user JohnC:\Users\John> net user John
User name John
Full Name John Smith
Country/region code 000 (System Default)
Account active Yes
Account expires Never
Password last set 1/15/2026 10:00:00 AM
Password expires Never
Password required Yes
Local Group Memberships *Administrators *Users
The command completed successfully.创建新用户
net user NewUser Password123 /addC:\Users\Administrator> net user NewUser Password123 /add
The command completed successfully.删除用户
net user NewUser /deleteC:\Users\Administrator> net user NewUser /delete
The command completed successfully.2. net localgroup - 管理用户组
查看所有组
net localgroupC:\Users\John> net localgroup
Aliases for \\DESKTOP-ABC123
-------------------------------------------------------------------------------
*Administrators
*Backup Operators
*Distributed COM Users
*Event Log Readers
*Guests
*Users
The command completed successfully.添加用户到组
net localgroup Administrators NewUser /addC:\Users\Administrator> net localgroup Administrators NewUser /add
The command completed successfully.查看组成员
net localgroup AdministratorsC:\Users\Administrator> net localgroup Administrators
Alias name Administrators
Comment Administrators have complete and unrestricted access
Members
-------------------------------------------------------------------------------
Administrator
John
NewUser
The command completed successfully.八、注册表操作
1. reg - 注册表操作
查询注册表项
reg query "HKEY_CURRENT_USER\Environment"C:\Users\John> reg query "HKEY_CURRENT_USER\Environment"
HKEY_CURRENT_USER\Environment
TEMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp
TMP REG_EXPAND_SZ %USERPROFILE%\AppData\Local\Temp添加注册表值
reg add "HKEY_CURRENT_USER\Environment" /v MY_VAR /t REG_SZ /d "Hello" /fC:\Users\John> reg add "HKEY_CURRENT_USER\Environment" /v MY_VAR /t REG_SZ /d "Hello" /f
The operation completed successfully.输出解读:
/v值名称/t数据类型(REG_SZ = 字符串)/d数据值/f强制操作不提示
删除注册表值
reg delete "HKEY_CURRENT_USER\Environment" /v MY_VAR /fC:\Users\John> reg delete "HKEY_CURRENT_USER\Environment" /v MY_VAR /f
The operation completed successfully.九、批处理与脚本
1. 批处理文件基础
创建备份脚本
@echo off
echo ========================================
echo Backup Script Started
echo Date: %date% Time: %time%
echo ========================================
echo.
set SOURCE=C:\Users\John\Documents
set DEST=D:\Backup\Documents_%date:~0,4%%date:~5,2%%date:~8,2%
echo Source: %SOURCE%
echo Destination: %DEST%
echo.
if not exist "%DEST%" mkdir "%DEST%"
xcopy "%SOURCE%\*.*" "%DEST%\" /s /e /h /r /y
echo.
echo ========================================
echo Backup Completed
echo ========================================
pause运行脚本
backup.batC:\Users\John> backup.bat
========================================
Backup Script Started
Date: 2026/05/12 周一 Time: 10:30:00.00
========================================
Source: C:\Users\John\Documents
Destination: D:\Backup\Documents_20260512
Documents\report.docx
Documents\notes.txt
...
3 File(s) copied
========================================
Backup Completed
========================================
Press any key to continue . . .2. 常用批处理变量
| 变量 | 说明 |
|---|---|
%date% | 当前日期(如:2026/05/12 周一) |
%time% | 当前时间(如:10:30:00.00) |
%cd% | 当前目录 |
%~dp0 | 批处理文件所在目录 |
%1, %2, ... | 命令行参数 |
十、实用技巧
1. 管道与重定向
输出重定向(覆盖)
echo Hello > hello.txtC:\Users\John> echo Hello > hello.txt
C:\Users\John> type hello.txt
Hello输出重定向(追加)
echo World >> hello.txtC:\Users\John> echo World >> hello.txt
C:\Users\John> type hello.txt
Hello
World错误输出重定向
dir C:\nonexistent 2> error.txtC:\Users\John> dir C:\nonexistent 2> error.txt
C:\Users\John> type error.txt
File Not Found管道
dir | findstr "2026"C:\Users\John> dir | findstr "2026"
05/12/2026 09:30 AM <DIR> Documents
05/11/2026 06:05 PM <DIR> Downloads
...2. 命令历史与快捷键
CMD 常用快捷键
| 快捷键 | 功能 |
|---|---|
↑ / ↓ | 浏览历史命令 |
Tab | 自动补全文件/目录名 |
F7 | 显示命令历史列表 |
F8 | 搜索历史命令 |
Ctrl + C | 终止当前命令 |
Ctrl + L | 清屏 |
3. 常用组合命令
查找可执行文件位置
where notepadC:\Users\John> where notepad
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe输出解读:where查找可执行文件的位置,相当于 Linux 的which。
查看文件类型关联
assoc .txt
ftype txtfileC:\Users\John> assoc .txt
.txt=txtfile
C:\Users\John> ftype txtfile
txtfile=C:\Windows\system32\NOTEPAD.EXE %14. PowerShell 命令(推荐)
Windows 推荐使用 PowerShell,功能更强大。
列出目录:Get-ChildItem
Get-ChildItemPS C:\Users\John> Get-ChildItem
Directory: C:\Users\John
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 5/12/2026 9:30 AM Desktop
d---- 5/10/2026 2:22 PM Documents
d---- 5/11/2026 6:05 PM Downloads
-a--- 5/12/2026 10:00 AM 2048 notes.txt输出解读:Get-ChildItem(别名ls、dir、gci)列出目录内容。
查看进程:Get-Process
Get-Process | Where-Object {$_.ProcessName -like "chrome*"}PS C:\Users\John> Get-Process | Where-Object {$_.ProcessName -like "chrome*"}
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
456 22 245760 156780 5.23 5624 1 chrome
234 15 123456 98765 2.15 8940 1 chrome输出解读:Get-Process(别名ps)查看进程,Where-Object(别名?)过滤结果。
查看运行中的服务
Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object -First 10PS C:\Users\John> Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object -First 10
Status Name DisplayName
------ ---- -----------
Running AdobeARMservice Adobe Acrobat Update Service
Running BFE Base Filtering Engine
Running Dhcp DHCP Client
Running Dnscache DNS Client附录:CMD vs PowerShell 对照表
| CMD 命令 | PowerShell 命令 | 功能 |
|---|---|---|
dir | Get-ChildItem / ls | 列出目录 |
cd | Set-Location / cd | 切换目录 |
type | Get-Content / cat | 查看文件内容 |
del | Remove-Item / rm | 删除文件 |
copy | Copy-Item / cp | 复制文件 |
move | Move-Item / mv | 移动文件 |
ren | Rename-Item / ren | 重命名 |
mkdir | New-Item -ItemType Directory / mkdir | 创建目录 |
tasklist | Get-Process / ps | 查看进程 |
taskkill | Stop-Process / kill | 结束进程 |
findstr | Select-String / grep | 文本搜索 |
sc | Get-Service / Start-Service / Stop-Service | 服务管理 |
附录:常用命令速查表
| 命令 | 功能 | 常用示例 | |
|---|---|---|---|
dir | 列出目录 | dir /s /b | |
cd | 切换目录 | cd Documents | |
mkdir | 创建目录 | mkdir Folder\SubFolder | |
rmdir | 删除目录 | rmdir /s /q Folder | |
del | 删除文件 | del *.tmp | |
copy | 复制文件 | copy file.txt D:\Backup\ | |
xcopy | 高级复制 | xcopy C:\Source D:\Dest /s /e | |
robocopy | 可靠复制 | robocopy C:\Source D:\Dest /MIR | |
move | 移动/重命名 | move file.txt D:\Archive\ | |
ren | 重命名 | ren old.txt new.txt | |
type | 查看文件 | type file.txt | |
findstr | 搜索文本 | findstr "error" *.log | |
tree | 目录结构 | tree /f | |
tasklist | 查看进程 | `tasklist \ | findstr chrome` |
taskkill | 结束进程 | taskkill /F /IM notepad.exe | |
systeminfo | 系统信息 | systeminfo | |
ping | 网络测试 | ping google.com | |
ipconfig | 网络配置 | ipconfig /all | |
netstat | 网络连接 | netstat -ano | |
tracert | 路由追踪 | tracert google.com | |
shutdown | 关机/重启 | shutdown /s /t 60 | |
chkdsk | 磁盘检查 | chkdsk C: /f | |
format | 格式化 | format D: /fs:ntfs | |
net user | 用户管理 | net user | |
sc | 服务控制 | sc query MySQL |
📚 学习建议:
- 每天练习几个命令,逐步积累
- 使用
命令 /?查看帮助(如dir /?)- 优先学习 PowerShell,它是未来的趋势
- 使用
where查找命令位置- 善用 Tab 自动补全
- 不确定的命令先在虚拟机或测试环境练习
本文档持续更新,欢迎收藏备用!