ping
发送 ICMP 包用于验证与远程计算机的连接,默认 ping 命令会发送 4 个包给目标服务器,如下:
D:\>ping 10.0.1.111
Pinging 10.0.1.111 with 32 bytes of data:
Reply from 10.0.1.111: bytes=32 time<1ms TTL=64
Reply from 10.0.1.111: bytes=32 time<1ms TTL=64
Reply from 10.0.1.111: bytes=32 time<1ms TTL=64
Reply from 10.0.1.111: bytes=32 time<1ms TTL=64
Ping statistics for 10.0.1.111:
Packets: Sent = 4, Received = 4, Lost = 0 (0
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
常用选项:
-
-t:持续ping,键入CTRL + C中断; -
-n <num>:指定发包的数量,默认为4; -
-l <num>:指定ping命令发出的每一个包的字节大小,默认为32; -
-r <num>:获取本机到目标地址所经历的指定个数的路由;
ipconfig
管理主机的网络相关配置。
D:\>ipconfig
Windows IP Configuration
Ethernet adapter 本地连接:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 10.0.1.31
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 10.0.1.2
常用选项:
-?:查看帮助信息;-all:查看网卡详细信息(包含 DNS);
nslookup
查看与主机名(域名)绑定的 IP 地址。
D:\>nslookup baidu.com
Server: public1.alidns.com
Address: 223.5.5.5
Non-authoritative answer:
Name: baidu.com
Addresses: 39.156.69.79, 220.181.38.148
dir
查看指定目录下的文件、及目录列表。
C:\>dir
驱动器 C 中的卷没有标签。
卷的序列号是 FCA1-B335
C:\ 的目录
2020-11-26 10:03 0 AUTOEXEC.BAT
2020-11-26 10:03 0 CONFIG.SYS
2020-11-26 10:08 <DIR> Documents an
2020-11-26 10:14 <DIR> Program File
2020-11-26 10:18 <DIR> WINDOWS
2 个文件 0 字节
3 个目录 8,354,410,496 可用字节
常用选项:
/a:显示所有文件(包含系统文件、隐藏文件);
md
创建目录。
D:\>md dir1
rd
删除目录。
D:\>rd dir1
echo
打印文本内容到 CMD。
D:\>echo hello zze
hello zze
可配合重定向创建文件并向文件写入内容:
:: 覆盖重定向
D:\>echo hello zze > hello.txt
:: 追加重定向
D:\>echo hello everyone >> hello.txt
type
查看文件内容:
D:\>type hello.txt
hello zze
hello everyone
copy
拷贝文件:
D:\>copy hello.txt hello1.txt
已复制 1 个文件。
D:\>dir
驱动器 D 中的卷是 新加卷
卷的序列号是 F861-515C
D:\ 的目录
2020-11-27 09:39 29 hello.txt
2020-11-27 09:39 29 hello1.txt
2 个文件 58 字节
0 个目录 32,141,574,144 可用字节
copy 命令除了可以拷贝文件以外,还可以直接输出多行内容到指定文件:
D:\>copy con hello2.txt
1 hello 1
2 hello 2
3 hello 3^Z
已复制 1 个文件。
D:\>type hello2.txt
1 hello 1
2 hello 2
3 hello 3
使用格式为 copy con <文件名>,输入后回车,然后可以键入需要的文本内容,可以是多行,键入完毕后按 CTRL + Z 然后回车即可保存文本内容到文件。
del
删除文件。
D:\>del hello2.txt
常用选项:
/s:递归删除子文件夹中的文件;/q:静默删除;/p:删除每一个文件前提示确认;/f:强制删除;/a:根据文件属性删除文件,R表示只读文件,S表示系统文件,H表示隐藏文件,A表示存档文件;/?:查看帮助;
move
移动文件。
D:\>move testfile.ini C:/
ren
重命名文件。
D:\>ren hello1.txt hello2.txt
attrib
在 DOS 下,文件的每个属性都是用一个字母来表示的。比如说,A 代表存档文件,S 代表系统文件,H 代表隐藏文件等等,而 attrib 命令就可以用来管理这些文件属性。可通过命令帮助查看到属性的详细信息:
D:\>attrib /?
Displays or changes file attributes.
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U]
[drive:][path][filename] [/S [/D]] [/L]
+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
O Offline attribute.
I Not content indexed file attribute.
X No scrub file attribute.
V Integrity attribute.
P Pinned attribute.
U Unpinned attribute.
B SMR Blob attribute.
[drive:][path][filename]
Specifies a file or files for attrib to process.
/S Processes matching files in the current folder
and all subfolders.
/D Processes folders as well.
/L Work on the attributes of the Symbolic Link versus
the target of the Symbolic Link
查看指定文件属性:
D:\>attrib hello1.txt
A D:\hello1.txt
为指定文件添加属性,以添加一个隐藏属性为例:
D:\>attrib +h hello1.txt
删除指定文件的某一项属性,以删除刚刚添加的隐藏属性为例:
D:\>attrib -h hello1.txt
cls
清屏,和 Linux 下的 clear 效果相同。
fsutil
强大的文件系统管理工具。
创建指定大小的文件(单位为字节):
D:\>fsutil file createnew testfile.ini 1024
已创建文件 D:\testfile.ini
上面用到的 file 只是它的一个子命令,所有可使用的子命令如下:
D:\>fsutil
---- 支持的命令 ----
behavior 控制文件系统行为
dirty 管理卷的被损坏的位数
file 文件特定命令
fsinfo 文件系统信息
hardlink 硬链接管理
objectid 对象 ID 管理
quota 配额管理
reparsepoint 重分析点管理
sparse 稀疏文件控制
usn USN 管理
volume 卷管理
这里就不详细说明,后续碰到相关场景能想到这个命令就行。
assoc
显示或修改文件扩展名关联。
不指定任何参数,直接执行 assoc,显示所有扩展名关联列表:
D:\>assoc
.386=vxdfile
.3g2=WMP11.AssocFile.3G2
.3gp=WMP11.AssocFile.3GP
.3gp2=WMP11.AssocFile.3G2
.3gpp=WMP11.AssocFile.3GP
.7z=WinRAR
.AAC=WMP11.AssocFile.ADTS
.accda=Access.ACCDAExtension.12
...
查看指定扩展名的关联信息:
D:\>assoc .exe
.exe=exefile
设置指定扩展名的关联信息:
D:\>assoc .txt=exefile
.txt=exefile
shutdown
关机重启相关,查看帮助信息如下:
D:\>shutdown /?
用法: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]
没有参数 显示此消息(与 ? 相同)
-i 显示 GUI 界面,必须是第一个选项
-l 注销(不能与选项 -m 一起使用)
-s 关闭此计算机
-r 关闭并重启动此计算机
-a 放弃系统关机
-m \\computername 远程计算机关机/重启动/放弃
-t xx 设置关闭的超时为 xx 秒
-c "comment" 关闭注释(最大 127 个字符)
-f 强制运行的应用程序关闭而没有警告
-d [u][p]:xx:yy 关闭原因代码
u 是用户代码
p 是一个计划的关闭代码
xx 是一个主要原因代码(小于 256 的正整数)
yy 是一个次要原因代码(小于 65536 的正整数)
logoff
注销,效果和 shutdown -l 相同。
more
分页查看内容,键入 q 退出查看。
D:\>assoc | more
.386=vxdfile
.3g2=WMP11.AssocFile.3G2
.3gp=WMP11.AssocFile.3GP
.3gp2=WMP11.AssocFile.3G2
.3gpp=WMP11.AssocFile.3GP
.7z=WinRAR
.AAC=WMP11.AssocFile.ADTS
.accda=Access.ACCDAExtension.12
.accdb=Access.Application.12
.accdc=Access.ACCDCFile.12
.accde=Access.ACCDEFile.12
.accdr=Access.ACCDRFile.12
.accdt=Access.ACCDTFile.12
.accdu=Access.WizardUserDataFile.12
.accountpicture-ms=accountpicturefile
.ace=WinRAR
.acl=ACLFile
.ade=Access.ADEFile.12
.adn=Access.BlankProjectTemplate.12
.adp=Access.Project.12
.ADT=WMP11.AssocFile.ADTS
.ADTS=WMP11.AssocFile.ADTS
.aif=WMP11.AssocFile.AIFF
.aifc=WMP11.AssocFile.AIFF
.aiff=WMP11.AssocFile.AIFF
.ani=anifile
.appcontent-ms=ApplicationContent
.application=Application.Manifest
.appref-ms=Application.Reference
-- More --
评论区