where git echo [{on | off}] [message] echo on type a.txt echo 现在关闭命令显示!!! echo off type a.txt @ 是于禁止当前执行的命令回显在屏幕上。 @ [command] @echo on @type a.txt type a.txt @ 命令只对当前命令行起作用;而 echo 命令影响设置之后的所有命令 goto label @echo off echo 跳过中间的命令,只执行最后一条 goto last dir type a.txt :last dir a.txt pause 命令用于暂停批处理的执行,并给出提示信息 @echo off echo pause命令测试…… pause type a.txt [ctrl+c 中断并回到命令行状态] call [ [Drive:] [Path] FileName [BatchParameters] ] [:label [arguments] ] @echo off echo 正在调用called.bat ... call called.bat echo called.bat 调用完毕! echo 现在开始调用 “xx”标号后的语句 ... call :xx :xx echo 在xx标号后的命令 ... start 命令用于重新启用一个单独的命令行窗口,然后在新窗口执行指定的程序或命令 参数: /wait 启动应用程序,并等待其结束 @echo off echo 将在新窗口中显示 a.txt 文件的内容 start "a.txt" /wait type a.txt echo 已从新命令窗口返回。 rem 是一个注释命令 @echo off rem 这是一个简单的批处理文件 type a.txt dir *.rm if string1==string2 if exist a.txt (echo 找到了a.txt文件,其内容为: type a.txt) else ( echo 找不到文件a.txt。 ) set 用来创建、设置、查看或删除环境变量 set [ [/a [expression]] [/p [variable=]] string] 参数 /a 将 string 设置称可求值的数字表达式 expression 合法的表达式 /p 将variable的值设置称输入行 variable 指定需要设置或修改的变量 string 指定要与变量关联的字符串 /? 显示帮助 @echo off set xxx="C:\" echo 显示所有以字母 x 开头的变量: set x dir /w %xxx% rem 删除名为 xxx 的变量 set xxx= setlocal 设置临时变量环境 @echo off setlocal path=d:\ echo 局部环境变量path的值 set path endlocal echo 系统环境变量path的值 set path shift 用于更改参数的位置 /n 设置从第n个参数开始移位,n在0~8之间 @echo off :round if "%1"=="" goto end echo %1内容如下: type %1 echo. shift goto round :end 说明:符号%0~%9 专用于批处理从命令行获得的参数 如: test.bat a.txt b.txt c.txt 则:%0=test.bat; %1=a.txt; %2=b.txt; %3=c.txt for {%variable|%%variable} in (set) do command [CommandLineOptions] @echo off set /a sum=0 for %%x in (*.txt) do ( echo %%x文件的内容如下: type %%x echo. set /a sum=sum+1 ) echo 一共显示了%sum%个文件! 通配符 * 多个字符,包含零个; ? 任意单个字符 @echo off if exist *.txt echo 当前文件夹有文本文件! echo 以 p 开头的目录如下: dir /d /w /b p* echo. echo 以 dk 开头,第三个字符为任意字符,第四个字符为t、扩展名为三个字符且以do开头的文件如下: dir /b /w dk?t.do? 重定向符 < > >> 其中,<的右边是数据源,左边是数据目的地; >会替换目的数据; >> 只是添加数据源到目的数据后 @echo off echo 正在自动创建的批处理…… echo echo 进入auto.bat 批处理文件中…… echo type a.txt >auto.bat echo dir /b /w >>auto.bat echo 被自动创建的auto.bat文件的内容如下: type auto.bat echo. echo 排序后的auto.bat为: sort < auto.bat 管道符 | 将一个命令的输出数据提取出来,然后将它作为另一个命令的输入。 @echo off find "requirements" gpl.txt | sort >result.txt echo 对包含 requirements 单词的行排序后,如下: type result.txt 首先在 gpl.txt 文件中找出所有包含 requirements 的行, 接着将找出的结果通过 | 传给 sort 命令进行排序, 最后将排序结果保存到 result.txt 文件。 @echo off cls echo. echo. echo -----------请选择要执行的操作---------- echo ----------1 输入数字 1 并按回车键,启动 Telnet 服务 echo ----------2 输入数字 2 并按回车键,停止 Telnet 服务 echo ----------3 输入数字 3 并按回车键,暂停 Telnet 服务 echo ----------4 输入数字 4 并按回车键,恢复被暂停的 Telnet 服务 echo ----------5 输入其它字符,直接退出批处理 echo. echo. set /p num=请选择要执行的操作: if "%num%"=="1" ( echo. echo. tlntadmn start>nul echo 成功启动 Telnet 服务 goto exit ) if "%num%"=="2" ( echo. echo. tlntadmn stop>nul echo 成功停止 Telnet 服务 goto exit ) echo 你输入了%num%字符,批处理自动退出…… :exit
C:\Users\admin>tracert www.baidu.com 通过最多 30 个跃点跟踪 到 www.a.shifen.com [180.101.50.242] 的路由: 1 1 ms 1 ms 2 ms 10.1.16.1 2 3 ms 3 ms 1 ms 171.1.1.251 3 4 ms 5 ms 10 ms 61.153.49.97 4 5 ms 5 ms 3 ms 125.123.254.111 5 * * * 请求超时。 6 * * * 请求超时。 7 * * 12 ms 202.97.94.109 8 11 ms * * 180.110.207.10 9 14 ms 15 ms 13 ms 58.213.95.206 10 19 ms 27 ms 22 ms 58.213.96.50 11 * * * 请求超时。 12 * * * 请求超时。 13 * * * 请求超时。 14 * * * 请求超时。 15 15 ms 15 ms 15 ms 180.101.50.242 跟踪完成。
起始列显示从 1 开始的跃点编号,并沿从设备到目标的路由随每个跃点递增。 每个跃点表示一个数据包到达最终目标时通过的中间设备,例如路由器。 三个中心列显示数据包在特定跃点从设备到路由器再返回到设备的往返时间(毫秒)。 它被称为“ping 时间”或“ping 延迟”,并用于度量数据前往路由器并返回的延迟(以毫秒为单位)。 网络延迟可能会受到网络拥塞、网络链接质量以及跃点之间距离等因素的影响。 结束列显示在网络路径中该特定跃点处的路由器或中间设备的 IP 地址或主机名。 在大多数情况下,你将看到 IP 地址,但如果反向 DNS 查找成功,它将显示主机名,这有助于按名称标识路由器。