学校教育网

Windows常用命令大全

Windows操作系统提供了许多实用的命令行工具,通过命令行界面(Command Prompt)或Windows PowerShell,用户可以执行各种任务,如文件管理、系统维护、网络配置等。掌握这些命令不仅能提高工作效率,还能帮助用户解决许多复杂的问题。本系列文章将详细介绍Windows操作系统中的常用命令,帮助你成为Windows极客!

一、基础命令

dir

dir C:\Users

cd

cd C:\Windows

copy

copy C:\file.txt D:\

move

move C:\file.txt D:\

del

del C:\file.txt

md / mkdir

md C:\NewFolder

rd / rmdir

rd C:\OldFolder

二、文件和目录管理

attrib

attrib +r C:\file.txt

xcopy

xcopy C:\source D:\destination /s /e

robocopy

robocopy C:\source D:\destination /mir

tree

tree C:\ /f

ren / rename

ren C:\oldname.txt newname.txt

三、系统管理

tasklist

tasklist

taskkill

taskkill /pid 1234 /f

chkdsk

chkdsk C: /f

sfc

sfc /scannow

shutdown

shutdown /s /t 0

systeminfo

systeminfo

四、网络相关命令

ipconfig

ipconfig /all

ping

ping baidu.com
ping 192.168.1.1 -t

tracert

tracert baidu.com

netstat

netstat -an

nslookup

nslookup baidu.com

net

net user
net share

五、磁盘管理

diskpart

list disk
select disk 0
list partition
create partition primary size=10000

format

format D: /fs:ntfs

diskcopy

diskcopy A: B:

vol

vol C:

label

label C: NewLabel

用户管理

net user

net user newuser password /add

net localgroup

net localgroup administrators newuser /add

runas

其他有用命令

echo

echo Hello, World!

type

type C:\file.txt

find

find "search text" C:\file.txt

sort

type C:\file.txt | sort

fc

fc C:\file1.txt C:\file2.txt

cls

cls

prompt

prompt $p$g

批处理和脚本

批处理文件(Batch file)是包含一系列命令的文本文件,通过执行批处理文件,可以自动化执行多个命令。这些文件的扩展名通常为.bat.cmd

基本批处理命令

echo Hello, World!
@echo off
rem This is a comment
pause
if exist C:\file.txt echo File exists
goto label
:label
call anotherbatchfile.bat
exit

以下是一个简单的批处理文件示例,展示了如何使用上述命令:

@echo off
echo Starting the batch file
rem Check if a file exists
if exist C:\file.txt (
    echo File exists
) else (
    echo File does not exist
)
pause
echo End of batch file
exit

六、总结

基础命令

命令解释
dir列出目录中的文件和子目录
cd改变当前目录
copy复制文件到指定位置
move移动文件或重命名文件/目录
del删除一个或多个文件
md/mkdir创建新目录
rd/rmdir删除目录

文件和目录管理

命令解释
attrib显示或更改文件属性
xcopy复制文件和目录树
robocopy高级复制文件和目录
tree图形方式显示目录结构
ren/rename重命名文件和目录

系统管理

命令解释
tasklist显示当前运行的所有进程
taskkill终止进程
chkdsk检查磁盘并修复文件系统错误
sfc扫描并修复系统文件
shutdown关机、重启或注销计算机
systeminfo显示计算机的详细配置信息和操作系统属性

网络相关命令

命令解释
ipconfig显示所有当前TCP/IP网络配置值
ping通过发送ICMP回显请求检测网络连接
tracert跟踪数据包到达目标主机的路径
netstat显示网络连接、路由表、接口统计等信息
nslookup查询DNS信息
net用于网络命令的一个通用命令,可以执行许多网络管理任务

磁盘管理

命令解释
diskpart磁盘分区管理
format格式化磁盘
diskcopy复制整个磁盘的内容
vol显示磁盘卷标和序列号
label创建、改变或删除磁盘卷标

用户管理

命令解释
net user添加、删除或更改用户账户
net localgroup添加、显示或修改本地组
runas以其他用户身份运行程序
退出移动版