Windows命令提示符长期以来一直是Windows操作系统的核心部分。有一些CMD
命令非常有用且易于使用,即使是普通用户也将
Windows命令提示符视为操作系统的关键部分。
总是有传言说它会在某个时候被淘汰,但这不太可能很快发生。
如果您想更好地控制您的 Windows PC ,以下是您应该知道的 21 个最佳CMD命令。(CMD)
此外,请务必查看我们的 YouTube 视频,我们在其中介绍了本文中列出的命令:
1. ASSOC:修复文件关联
CMD命令库中最强大的工具之一是ASSOC命令。
您的计算机将某些文件扩展名与某些程序相关联。这就是您的计算机知道双击PDF文件时打开Adobe或双击DOC文件时打开(DOC)Microsoft Word的方法。
您可以通过在命令窗口中键入ASSOC来查看计算机知道的所有文件关联。您将看到文件扩展名和与之关联的程序。
您可以通过键入类似assoc .doc=Word.Document.8的内容来设置关联。
2. FC:文件比较
有时当文件随着时间的推移而更改时,很难记住版本之间的差异。您可能不知道
CMD命令提供了比较文件和查看所有差异的能力,但这是真的。
FC命令执行 ascii 或二进制文件比较,并将列出它发现的所有差异。
Fc /a File1.txt
File2.txt将比较两个 ascii 文件。
Fc /b Picture1.jpg
Picture2.jpg将对两个图像进行二进制比较。
3.IPCONFIG:IP配置
网络(Network)故障排除从来都不是一件简单的事情,但是一个更容易的命令是IPCONFIG。
在CMD(CMD)命令提示符中使用此命令会返回有关当前网络适配器连接的详细信息,包括:
此信息可以帮助您解决路由器问题和您的网络适配器可能遇到的其他连接问题。
4. NETSTAT:网络统计
担心在您不知情的情况下,您的计算机上正在运行连接到 Internet 位置的恶意软件?
如果您在命令提示符下运行NETSTAT命令,您可以从您的计算机
获取所有活动TCP连接的列表。(TCP)
5. PING:发送测试包
IT 分析师最好的朋友是PING命令。运行此命令通过网络将测试数据包发送到目标系统。
您可以使用 PING 命令测试您的计算机是否可以访问另一台计算机、服务器甚至网站。它可以帮助揭示网络断开连接。它还以毫秒为单位提供数据包的传输时间,因此它也揭示了不良的网络连接。
6. TRACERT:追踪路线
TRACERT是一个令人着迷的Windows 命令(Windows Command)。如果您想知道互联网流量从浏览器到远程系统(如Google
服务器)的路径,您可以使用TRACERT来查看它。
该命令代表“跟踪路由”,它将数据包发送到远程目标(服务器或网站),并为您提供以下所有信息:
- (Number)到达目的地之前的跃点数(中间服务器)
- 到达每一跳所需的时间
- IP,有时是每个跃点的名称
TRACERT 可以根据您访问网络的位置显示您的 Internet 请求的路由如何变化。它还有助于对可能有问题的本地网络上的路由器或交换机进行故障排除。
7. POWERCFG:电源配置
您(Are)是否对笔记本电脑似乎没电的速度感到沮丧?可能是您的电源设置已尽可能有效地配置。有一个名为POWERCFG (电源配置)的 Windows (POWERCFG)CMD命令可以提供帮助。以管理员身份运行命令提示符并键入powercfg –energy以获取完整的电源效率报告。
该过程最多可能需要一分钟,但完成后,您会看到是否有任何警告或错误可以帮助您提高系统的电源效率。
查看 energy-report.html 文件以查看这些错误和警告的详细信息。
8. 关机:关闭电脑
SHUTDOWN命令是一个非常通用的
命令,可让您关闭计算机但控制该关闭的行为。在将补丁应用到计算机系统后,它通常用作计划任务或 IT 批处理作业的一部分。
从命令提示符键入shutdown /i
将启动关闭,但它会在GUI上为用户提供是否重新启动或完全关闭的选项。如果您不想弹出任何GUI ,您可以发出(GUI)shutdown /s命令。
您可以使用一长串其他参数来执行注销、休眠、重新启动等操作。只需(Just)键入不带任何参数的shutdown即可查看所有内容。
9. SYSTEMINFO:系统信息
如果您需要知道您拥有的网卡品牌、处理器详细信息或您的Windows 操作系统(Windows OS)的确切版本,SYSTEMINFO命令可以提供帮助。
此命令轮询您的系统并提取有关您的系统的最重要信息。它以易于阅读的简洁格式列出信息。
10. SFC:系统文件检查器
如果您曾经担心病毒或某些其他软件可能损坏了您的核心系统文件,那么有一个Windows命令可以扫描这些文件并确保它们的完整性。
您需要以管理员身份启动CMD(右键单击并选择Run as Administrator)。键入
SFC /SCANNOW将检查所有受保护系统文件的完整性。如果发现问题,将使用备份的系统文件修复文件。
SFC 命令还允许您:
- /VERIFYONLY:检查完整性但不修复文件。
- /SCANFILE:扫描特定文件的完整性,如果损坏则修复。
- /VERIFYFILE:验证特定文件的完整性,但不修复它们。
- /OFFBOOTDIR:使用它对脱机引导目录进行修复。
- /OFFWINDIR:使用它对离线Windows目录进行修复。
- /OFFLOGFILE : 指定保存扫描结果的日志文件的路径。
扫描最多可能需要 10 或 15 分钟,所以请给它一些时间。
11. NET 使用:映射驱动器
如果你想映射一个新的驱动器,你总是可以打开文件资源管理器,右键单击这台电脑,然后通过映射网络驱动器(Map Network Drive)向导。但是,使用NET USE命令,您可以使用一个命令字符串执行相同的操作。
例如,如果您在网络上的计算机上有一个名为\\OTHER-COMPUTER\SHARE\的共享文件夹,您可以通过键入以下命令将其映射为您自己的 Z: 驱动器:
Net use Z: “\\OTHER-COMPUTER\SHARE”
/persistent:yes
永久(persistent)开关告诉您的
计算机,您希望每次重新登录计算机时都重新映射此驱动器。
12. CHKDSK:检查磁盘
虽然SFC命令只检查核心系统文件的完整性,但您可以使用CHKDSK
命令扫描整个驱动器。
检查 C: 驱动器并修复任何问题的命令,以管理员身份启动命令窗口并键入CHKDSK /f C:。
此命令检查以下内容:
该命令可以修复任何磁盘错误(如果可能)。命令完成后,您将看到扫描状态以及已采取的操作。
13.SCHTASKS:安排任务
Windows 附带一个用于创建计划任务的向导。例如,也许你有一个存储在 C:emp 上的BAT文件,你想每天中午运行它。
您必须单击“计划任务(Scheduled Task)”向导来配置它。或者,您可以键入单个SCHTASKS
命令进行设置。
SCHTASKS /Create /SC
HOURLY /MO 12 /TR Example /TN c:\temp\File1.bat
预定的开关接受分钟、每小时、每天和每月等参数。然后使用 /MO 命令指定频率。
如果您输入正确的命令,您将看到响应,
成功:计划任务“示例”已成功创建(SUCCESS: The scheduled task “Example”
has successfully been created)。
14. ATTRIB:更改文件属性
在Windows中,您可以通过右键单击文件并找到要更改的正确属性来更改文件属性。但是,您可以使用ATTRIB(ATTRIB)命令设置文件属性,而不是四处寻找文件属性。
例如,如果您键入:ATTRIB +R +H C:\temp\File1.bat,它会将File1.bat设置为隐藏的只读文件。
成功时没有响应,因此除非您看到错误消息,否则该命令有效。
其他 Windows CMD 命令
如您所见,如果您知道正确的命令,则可以使用Windows命令提示符执行一些强大且有用的操作。
信不信由你,还有更多的命令可以让你通过输入一个简单的命令来完成一些你可能从未意识到的事情。
- BITSADMIN:通过网络或互联网启动上传或下载作业,并监控这些文件传输的当前状态。
- COLOR:更改命令提示符窗口的背景颜色。
- COMP:比较任何两个文件的内容以查看差异。
- FIND/FINDSTRASCII文件中搜索字符串。
- PROMPT:将命令提示符从 C:> 更改为其他内容。
- TITLE:更改命令提示符窗口的标题。
- REGEDIT:编辑Windows注册表中的键(谨慎使用)。
- ROBOCOPY : Windows中内置的强大文件复制实用程序。
如果您有兴趣了解更多信息,Microsoft提供了包含在最新版本Windows 操作系统中的所有(Windows OS)Windows CMD 命令(Windows CMD commands)的完整列表。
21 CMD Commands All Windows Users Should Know
The Windows command prompt is a featυre that’s been a core
part of the Windows operating system for a long time. There are some CMD
commands that are so useful and easy to use that even regular users see the
Windowѕ command prompt as a key part of the operating system.
There are always rumors that it will be phased out at some
point, but that’s unlikely to happen any time soon.
The following are 21 of the best CMD commands you should know if you want to have more control over your Windows PC.
Also, be sure to check out our YouTube video where we go over the commands listed in this article:
1. ASSOC: Fix File Associations
One of the most powerful tools in the CMD command library is
the ASSOC command.
Your computer associates certain file extensions with
certain programs. This is how your computer knows to open Adobe when you double
click a PDF file, or Microsoft Word when you double click a DOC file.
You can view all the file associations your computer knows
about by typing ASSOC in the command
window. You’ll see the file extension and the program it’s associated with.
You can set the association by typing something like assoc .doc=Word.Document.8.
2. FC: File Compare
Sometimes when files are changed over time, it’s hard to
remember what the differences were between versions. You may not know that a
CMD command offers the ability to compare files and see all differences, but
it’s true.
The FC command
performs either an ascii or a binary file comparison and will list all of the
differences that it finds.
Fc /a File1.txt
File2.txt will compare two ascii files.
Fc /b Picture1.jpg
Picture2.jpg will do a binary compare on two images.
3. IPCONFIG: IP Configuration
Network troubleshooting is never simple, but one command
that makes it much easier is IPCONFIG.
Using this command in the CMD command prompt returns detailed
information about your current network adapter connection including:
- Current IP Address
- Subnet Mask
- Default Gateway IP
- Current domain
This information can help you troubleshoot router issues and
other connection issues you could be having with your network adapter.
4. NETSTAT: Network Statistics
Concerned that you could have malware running on your
computer that’s connecting to internet locations without you knowing about it?
If you run a NETSTAT
command in the command prompt, you can get a list of all active TCP connections
from your computer.
5. PING: Send Test Packets
An IT Analyst’s best friend is the PING command. Running this
command sends test packets over the network to the target system.
You can use the PING command to test whether your computer
can access another computer, a server, or even a website. It can help with
revealing network disconnections. It also provides transit time for the packets
in milliseconds, so it also reveals a bad network connection as well.
6. TRACERT: Trace Route
TRACERT is a
fascinating Windows Command to use. If you’re ever curious to see the path your
internet traffic takes to get from your browser to a remote system like Google
servers, you can use TRACERT to see it.
The command stands for “Trace Route”, which sends packets
out to a remote destination (server or website), and provides you with all of
the following information:
- Number of hops (intermediate servers) before
getting to the destination
- Time it takes to get to each hop
- The IP and sometimes the name of each hop
TRACERT can reveal how the routes of your internet requests
change depending where you’re accessing the web. It also helps with
troubleshooting a router or switch on a local network that may be problematic.
7. POWERCFG: Power Configuration
Are you frustrated with how quickly your laptop seems to run
out of power? It could be that your power settings are configured as
efficiently as possible. There’s a windows CMD command called POWERCFG (power configuration) that can
help. Run the command prompt as an administrator and type powercfg – energy to get a full power efficiency report.
The process can take up to about a minute, but when it’s done,
you’ll see whether there are any warnings or errors that might help you improve
the power efficiency of your system.
View the energy-report.html file to see the details of those
errors and warnings.
8. SHUTDOWN: Turn Off Computer
The SHUTDOWN
command is a pretty versatile command that lets you shutdown the computer but
control the behavior of that shutdown. It’s commonly used as a scheduled task
or part of an IT batch job after patches have been applied to a computer
system.
Typing shutdown /i
from the command prompt will initiate a shutdown, but it’ll upon a GUI to give
the user an option on whether to restart or do a full shutdown. If you don’t
want to have any GUI pop up, you can just issue a shutdown /s command.
There is a long list of other parameters you can use to do a
log off, hibernate, restart, and more. Just type shutdown without any arguments to see them all.
9. SYSTEMINFO: System Information
If you need to know what brand of network card you have,
processor details, or the exact version of your Windows OS, the SYSTEMINFO command can help.
This command polls your system and pulls the most important
information about your system. It lists the information in a clean format
that’s easy to read.
10. SFC: System File Checker
If you’re ever concerned that a virus or some other software
might have corrupted your core system files, there’s a Windows command that can
scan those files and ensure their integrity.
You need to launch CMD as administrator (right click and
choose Run as Administrator). Typing
SFC /SCANNOW will check the integrity of all protected system files. If a
problem is found, the files will be repaired with backed-up system files.
The SFC command also lets you:
- /VERIFYONLY:
Check the integrity but don’t repair the files.
- /SCANFILE:
Scan the integrity of specific files and fix if corrupted.
- /VERIFYFILE:
Verify the integrity of specific files but don’t repair them.
- /OFFBOOTDIR:
Use this to do repairs on an offline boot directory.
- /OFFWINDIR:
Use this to do repairs on an offline Windows directory.
- /OFFLOGFILE:
Specify a path to save a log file with scan results.
The scan can take up to 10 or 15 minutes, so give it time.
11. NET USE: Map drives
If you want to map a new drive, you could always open File
Explorer, right click on This PC, and go through the Map Network Drive wizard.
However, using the NET USE command,
you can do the same thing with one command string.
For example, if you have a share folder on a computer on
your network called \\OTHER-COMPUTER\SHARE\, you can
map this as your own Z: drive by typing the command:
Net use Z: “\\OTHER-COMPUTER\SHARE”
/persistent:yes
The persistent
switch tells your computer that you want this drive remapped every time you log
back into your computer.
12. CHKDSK: Check Disk
While the SFC command only checks the integrity of core
system files, you can use the CHKDSK
command to scan an entire drive.
The command to check the C: drive and repair any problems,
launch the command window as an administrator and type CHKDSK /f C:.
This command checks for things like:
- File fragmentation
- Disk errors
- Bad sectors
The command can fix any disk errors (if possible). When the
command is finished, you’ll see a status of the scan and what actions were
taken.
13. SCHTASKS: Schedule Tasks
Windows comes with a wizard for creating scheduled tasks.
For example, maybe you have a BAT file stored on C:\temp that you want to run
every day at noon.
You’d have to click through the Scheduled Task wizard to
configure this. Or you can type a single SCHTASKS
command to set it up.
SCHTASKS /Create /SC
HOURLY /MO 12 /TR Example /TN c:\temp\File1.bat
The scheduled switch accepts arguments like minute, hourly,
daily, and monthly. Then you specify the frequency with the /MO command.
If you typed the command correctly, you’ll see the response,
SUCCESS: The scheduled task “Example”
has successfully been created.
14. ATTRIB: Change File Attributes
In Windows, you can change file attributes by right clicking
on a file and finding the right property to change. However, instead of hunting
around for the file attribute, you can use the ATTRIB command to set the file attributes.
For example, if you type: ATTRIB +R +H C:\temp\File1.bat, it’ll set File1.bat as a hidden,
read-only file.
There is no response when it’s successful, so unless you see
an error message, the command worked.
Other Windows CMD Commands
As you can see, there are some powerful and useful things
you can do with the Windows command prompt, if you know the right commands.
Believe it or not, there are even more commands that will
give you the ability to do some things you probably never realized just by
typing a simple command.
- BITSADMIN:
Initiate upload or download jobs over the network or internet and monitor the
current state of those file transfers.
- COLOR:
Change the background color of the command prompt window.
- COMP:
Compare the contents of any two files to see the differences.
- FIND/FINDSTR:
Search for strings inside of any ASCII files.
- PROMPT:
Change the command prompt from C:\> to something else.
- TITLE:
Change the title of the command prompt window.
- REGEDIT:
Edit keys in the Windows registry (use with caution).
- ROBOCOPY:
A powerful file copy utility built right into Windows.
If you’re interested in learning more, Microsoft offers a full list of all of the Windows CMD commands included in the latest version of the Windows OS.