hello.txt 会将双引号""写入文件中,而不是空文件。3、将新的数据写入文件,并替换原有内容echo This is a test. > hello.txt4、将新的数据追加到文件末尾echo append data success. >> hello.txt5、查看文件_cmd命令">
赞
踩
1、创建文件夹
mkdir test
2、创建空文件
type nul > hello.txt
注意:echo "" > hello.txt 会将双引号""写入文件中,而不是空文件。
3、将新的数据写入文件,并替换原有内容
echo This is a test. > hello.txt
4、将新的数据追加到文件末尾
echo append data success. >> hello.txt
5、查看文件内容
type hello.txt
6、删除文件
del hello.txt
7、复制文件
copy hello.txt hello.txt.bak
8、打开具有管理员权限的powershell
1)从提升的命令提示符(有管理员权限的cmd窗口)中打开
powershell
2)从未提升的命令提示符(无管理员权限的cmd窗口)中打开
- powershell start-process powershell -verb runas
- powershell -Command "Start-Process cmd -Verb RunAs -ArgumentList '/c 原本命令 && command -argument'"
9、设置标题
- cmd窗口下直接输入:
- title 服务器
-
- 或者在bat文件中使用:
- @ECHO OFF
- title 服务器
- cd ..
- pause
10、显示目录信息
- dir/w
- 缩略显示
- dir/p
- 按页显示,
- dir/a
- 显示全部
- dir/s
- 显示所有系统文件
- dir/p/w
- 将文件缩略起来按页显示
11、获取命令帮助,命令后接“/?”
- dir /?
- mkdir /?
- type /?
- ping /?
12、获取当前bat文件所在目录
cd /d %~dp0
13、获得命令的执行结果
1、直接输出
- FOR /F ["options"] %variable IN ('command') DO command [command-parameters]
-
- for /F %%i in ('dir /w') ^
- do (
- echo file=%%i
- )
2、先重定向到文件,再读取文件
- dir > C:\test.txt
- pause
14、@echo off 表示执行命令时不会将所执行的命令一行一行的显示出来
@echo on 表示执行命令时会将所执行的命令一行一行的显示出来
15、30分钟后关机
shutdown -s -t 1800
16、注册、删除、启动、停止windows服务
注册:
sc create myapp binpath= "C:\Program Files\test\myapp.exe" start= auto displayname= myapp
注意:如果你的exe不符合服务的规范,通过windows自带的sc安装后,可能启动报错,原因可能是:无法启动xx服务错误1053:服务没有及时响应启动或控制请求,排查方法。 - 百度文库
这时可以使用 instsrv+srvany 进行安装,见2种方法教你,如何将exe注册为windows服务,直接从后台运行 - 知乎
删除:
sc delete myapp
启动:
net start myapp
停止:
net stop myapp
17、pushd
保存当前目录以供 POPD 命令使用,然后改到指定的目录。
注意,其实是有两个步骤的操作,第一,把路径放入虚拟堆栈,第二,将当前目录切换到路径
18、popd
更改到 PUSHD 命令存储的目录。
19、监控程序未启动,则启动
- tasklist /nh|find /i "myapp.exe"
- if ERRORLEVEL 1 (pushd D:\app
- start myapp.exe)
-
- else (echo 程序已运行 exit)
20、more 逐屏显示输出
命令帮助:more /?
- P n Display next n lines
- S n Skip next n lines
- F Display next file
- Q Quit
- = Show line number
- ? Show help line
- <space> Display next page
- <ret> Display next line
1)逐屏显示命令的输出,按enter键后继续显示下一行内容
- C:\Users\tx>help | more
- For more information on a specific command, type HELP command-name
- ASSOC Displays or modifies file extension associations.
- ATTRIB Displays or changes file attributes.
- BREAK Sets or clears extended CTRL+C checking.
- BCDEDIT Sets properties in boot database to control boot loading.
- CACLS Displays or modifies access control lists (ACLs) of files.
- CALL Calls one batch program from another.
- CD Displays the name of or changes the current directory.
- CHCP Displays or sets the active code page number.
- CHDIR Displays the name of or changes the current directory.
- CHKDSK Checks a disk and displays a status report.
- CHKNTFS Displays or modifies the checking of disk at boot time.
- CLS Clears the screen.
- CMD Starts a new instance of the Windows command interpreter.
- COLOR Sets the default console foreground and background colors.
- COMP Compares the contents of two files or sets of files.
- COMPACT Displays or alters the compression of files on NTFS partitions.
- CONVERT Converts FAT volumes to NTFS. You cannot convert the
- current drive.
- COPY Copies one or more files to another location.
- DATE Displays or sets the date.
- DEL Deletes one or more files.
- DIR Displays a list of files and subdirectories in a directory.
- DISKPART Displays or configures Disk Partition properties.
- DOSKEY Edits command lines, recalls Windows commands, and
- creates macros.
- DRIVERQUERY Displays current device driver status and properties.
- ECHO Displays messages, or turns command echoing on or off.
- ENDLOCAL Ends localization of environment changes in a batch file.
- -- More --

2)逐屏显示文件的内容,按enter键后继续显示下一行内容
- C:\Users\tx>more tsconfig.json
- {
- "compilerOptions": {
- /* Visit https://aka.ms/tsconfig to read more about this file */
-
- /* Projects */
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
-
- /* Language and Environment */
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
- // "jsx": "preserve", /* Specify what JSX code is generated. */
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React J-- More (16%) --
-

21、netstat
1) netstat -a 显示所有网络连接及监听的端口
2)netstat -n 显示已创建的有效连接,并以数字的形式显示本地地址和端口号
3) netstat -s 显示每个协议的各类统计数据,查看网络存在的连接,显示数据包的接收和发送情况
4) netstat -e 显示关于以太网的统计数据,包括传送的字节数、数据包、错误等
5) netstat -b,可显示在创建网络连接和侦听端口时所涉及的可执行程序
注意:此命令需要管理员权限
6)netstat -r 显示关于路由表的信息,还显示当前的有效连接
以下引用:https://www.iteye.com/blog/zenoh-1260771
这个表提供的信息为:
1,局域网是192。168。203的IP段,你的IP地址是128,网关设置为2,如果你访问的网络是任意网络(0.0.0.0),你将从网关192.168.203.2这个出口出去。
2,内部循环网络是规定为127.0.0.0的网段,你的内部地址是127.0.0.1,如果你ping localhost,将返回127.0.0.1的ping通信息,表明你的物理网卡和硬件设备正常。
3,如果你访问的网络是自己的网段(192.168.203.0),你将从自己的接口192.168.203.128出去,不经过网关。
4,发起广播的接口也是由自己出去。注:ip地址最后一位是255的,都是广播地址,关于广播这里不详述,建议查看相关资料
5,多播和组播,你不用理会 一般用不到。
6,你的默认网关是192.168.203.2.如果有其他网关,你访问网络将先从这个网关出去,
22、netsh
1)导入IE所配置的代理
netsh winhttp import proxy source=ie
23、隐藏(不显示)命令行
1)@ 在命令行前加入,表示不显示该行的命令
2)echo off 表示不显示该行之后的所有命令
3)@ echo off 表示不显示该行及该行之后的所有命令
- ::此命令会显示
- cd %programfiles%\Java
- ::dir前面加了@,则此命令不会显示
- @dir
- ::命令echo off会显示,但是之后的不会显示
- echo off
- c:
- echo hello world
-
-
- 以上命令执行结果:
-
- C:\>C:\Users\test\Desktop\1.bat
-
- C:\>cd C:\Program Files\Java
- 驱动器 C 中的卷没有标签。
- 卷的序列号是 E8D9-B285
-
- C:\Program Files\Java 的目录
-
- 2021/12/16 22:19 <DIR> .
- 2021/12/16 22:19 <DIR> ..
- 2021/12/16 22:19 <DIR> jdk-11.0.5
- 2021/09/20 16:30 <DIR> jdk1.8.0_121
- 2021/10/27 09:10 <DIR> jre1.8.0_311
- 0 个文件 0 字节
- 5 个目录 7,283,634,176 可用字节
-
- C:\Program Files\Java>echo off
- hello world

24、&、|、&&、||
&:表示连续执行多个命令,前一个命令执行错误,也会继续执行下一个命令,直到所有命令都执行完成
|:管道符,或者表示连续执行多个命令,前一个命令执行错误,也会继续执行下一个命令,直到所有命令都执行完成
&&:表示连续执行多个命令,前一个命令执行错误,不会继续执行下一个命令
||:表示连续执行多个命令,直到某个命令执行成功,则结束,不再继续执行下一个命令
- // 以下命令表示:查找notepad.exe进程,如果存在,则结束,否则5秒后,结束notepad.exe进程
- tasklist | find /i "notepad.exe" || goto skip
- exit
- :skip
- timeout /t 5
- taskkill /f /im notepad.exe /t
25、taskkill
-
- TASKKILL [/S system [/U username [/P [password]]]]
- { [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]
-
- 描述:
- 使用该工具按照进程 ID (PID) 或映像名称终止任务。
-
- 参数列表:
- /S system 指定要连接的远程系统。
-
- /U [domain\]user 指定应该在哪个用户上下文执行这个命令。
-
- /P [password] 为提供的用户上下文指定密码。如果忽略,提示
- 输入。
-
- /FI filter 应用筛选器以选择一组任务。
- 允许使用 "*"。例如,映像名称 eq acme*
-
- /PID processid 指定要终止的进程的 PID。
- 使用 TaskList 取得 PID。
-
- /IM imagename 指定要终止的进程的映像名称。通配符 '*'可用来
- 指定所有任务或映像名称。
-
- /T 终止指定的进程和由它启用的子进程。
-
- /F 指定强制终止进程。
-
- /? 显示帮助消息。
-
- 筛选器:
- 筛选器名 有效运算符 有效值
- ----------- --------------- -------------------------
- STATUS eq, ne RUNNING |
- NOT RESPONDING | UNKNOWN
- IMAGENAME eq, ne 映像名称
- PID eq, ne, gt, lt, ge, le PID 值
- SESSION eq, ne, gt, lt, ge, le 会话编号。
- CPUTIME eq, ne, gt, lt, ge, le CPU 时间,格式为
- hh:mm:ss。
- hh - 时,
- mm - 分,ss - 秒
- MEMUSAGE eq, ne, gt, lt, ge, le 内存使用量,单位为 KB
- USERNAME eq, ne 用户名,格式为 [domain\]user
- MODULES eq, ne DLL 名称
- SERVICES eq, ne 服务名称
- WINDOWTITLE eq, ne 窗口标题
-
- 说明
- ----
- 1) 只有在应用筛选器的情况下,/IM 切换才能使用通配符 '*'。
- 2) 远程进程总是要强行 (/F) 终止。
- 3) 当指定远程机器时,不支持 "WINDOWTITLE" 和 "STATUS" 筛选器。
-
- 例如:
- TASKKILL /IM notepad.exe
- TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
- TASKKILL /F /IM cmd.exe /T
- TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
- TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
- TASKKILL /S system /U 域\用户名 /FI "用户名 ne NT*" /IM *
- TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"

26、获取一个命令执行结果,并将结果写入文件
-
- for /f "delims=" %%a in ('tasklist ^| findstr "notepad.exe"') do (
- echo %%a >> 1.txt
- )
-
- 输出:
- notepad.exe 26348 Console 1 38,240 K
- notepad.exe 27612 Console 1 40,652 K
-
- for /f %%a in ('tasklist ^| findstr "notepad.exe"') do (
- echo %%a >> 1.txt
- )
- 输出:
- notepad.exe
- notepad.exe
-
- 注意:
- 如果不使用参数“/f”,运行结果只显示括号里的文字字符“歌曲列表.txt”,而不能读取文本文件“歌曲列表.txt”中的内容。可见,“/f”是解析文本字符串的好工具
- 必须是%%a,
- 命令必须放在单引号中,
- 且|前面必须有^,^表示转义的意思
- > 表示覆盖写入
- >> 表示追加写入
- "delims=" 表示分割

27、Ping
1)ping 大包,即:加入指定大小的负载,默认是32字节数
- >ping 182.61.200.7 -l 100
-
- 正在 Ping 182.61.200.7 具有 100 字节的数据:
- 来自 182.61.200.7 的回复: 字节=100 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=100 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=100 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=100 时间=3ms TTL=51
-
- 182.61.200.7 的 Ping 统计信息:
- 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
- 往返行程的估计时间(以毫秒为单位):
- 最短 = 3ms,最长 = 3ms,平均 = 3ms
2)ping 指定次数,加 -n,默认4次
- >ping -n 6 182.61.200.7
-
- 正在 Ping 182.61.200.7 具有 32 字节的数据:
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
-
- 182.61.200.7 的 Ping 统计信息:
- 数据包: 已发送 = 6,已接收 = 6,丢失 = 0 (0% 丢失),
- 往返行程的估计时间(以毫秒为单位):
- 最短 = 3ms,最长 = 3ms,平均 = 3ms
2)ping 无限次数,加 -t
- >ping -t 182.61.200.7
-
- 正在 Ping 182.61.200.7 具有 32 字节的数据:
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=4ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
- 来自 182.61.200.7 的回复: 字节=32 时间=3ms TTL=51
28、注释
1)::,注释一行,使用此方式所注释的代码不会在控制台显示,注意是两个英文输入法下冒号
2) Rem,此为命令方式注释,如果Rem前不加@,或者之前没有@echo off,则此行注释会显示,注意不是执行
29、bat方式配置、关闭代理参见:
批处理 - bat 脚本一键开启和关闭 Windows 系统代理 - 知乎
29、启动服务
两种方式,其中后缀.exe可有可无:
1)start hello.exe 或 start hello
2) hello.exe -s start
1、截屏快捷方式
start snippingtool 打开截图工具:
30、打开IE属性:inetcpl.cpl
31、打开代理设置:ms-settings:network-proxy
32、ms-settings更多快捷方式参见:2019-9-2-windows-10「设置」应用完整ms-settings快捷方式汇总_lindexi_gd的博客-CSDN博客
33、打开远程桌面:mstsc
34、arp命令
arp缓存表记录了IP地址与物理地址之间的映射关系,以便更快的发送和接收数据。当一个主机准备发送数据到另一主机时,会首先查询arp缓存表,如果存在P地址与物理地址之间的映射关系,就不再发送arp报文了,直接发送报文,从而提高传输速度。一般windows每2小时、linux每20分钟清空一次arp缓存表。
网络层通过arp协议,获取IP地址对应的物理地址(mac),并维护两者之间的关系
arp -a // 查看本地缓存列表
arp -d // 删除本地缓存列表
35、列出本地网卡信息及IDX
- C:\Users\tst> netsh i i show in
-
- Idx Met MTU 状态 名称
- --- ---------- ---------- ------------ ---------------------------
- 1 75 4294967295 connected Loopback Pseudo-Interface 1
- 19 25 1500 disconnected WLAN
- 17 65 1500 disconnected 蓝牙网络连接
- 40 25 1500 disconnected 本地连接* 8
- 18 35 1500 connected 以太网
- 57 55 1500 connected 本地连接* 11
- 7 25 1500 connected 以太网 2
- 4 55 1400 disconnected 以太网 3
36、启动服务、查找正在运行的服务
- # 启动网络登录服务
- net start netlogon
-
- # net start 后面不跟服务名称时,显示所有已启动的服务
-
- E:\Program Files\nginx-1.24.0>net start
- 已经启动以下 Windows 服务:
-
- Application Information
- Application Layer Gateway Service
- AVCTP 服务
- Background Tasks Infrastructure Service
- Base Filtering Engine
- Bonjour 服务
- cbdhsvc_9ff0d
- CDPUserSvc_9ff0d
- CNG Key Isolation
- COM+ Event System
- Connected User Experiences and Telemetry
- CoreMessaging
- Credential Manager
- Cryptographic Services

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。