bat批处理:win2000命令行方式批处理BAT文件技巧来源: 发布时间:星期三, 2008年12月17日 浏览:10次 评论:0
win2000命令行方式批处理BAT文件窍门技巧
www.netsill.com2002-11-29 10:57:14 网嗅网络安全网 文章结构 1. 所有内置命令帮助信息 2. 环境变量概念 3. 内置特殊符号(实际使用中间注意避开) 4. 简单批处理文件概念 5. 附件1 tmp.txt 6. 附件2 sample.bat ###################################################################### 1. 所有内置命令帮助信息 ###################################################################### ver cmd /? /? rem /? /? echo /? goto /? for /? sht /? call /? 其他需要常用命令 type /? find /? findstr /? copy /? ______________________________________________________________________ 下面将所有上面帮助输出到个文件 echo ver >tmp.txt ver >>tmp.txt echo cmd /? >>tmp.txt cmd /? >>tmp.txt echo rem /? >>tmp.txt rem /? >>tmp.txt echo /? >>tmp.txt /? >>tmp.txt echo goto /? >>tmp.txt goto /? >>tmp.txt echo for /? >>tmp.txt for /? >>tmp.txt echo sht /? >>tmp.txt sht /? >>tmp.txt echo call /? >>tmp.txt call /? >>tmp.txt echo type /? >>tmp.txt type /? >>tmp.txt echo find /? >>tmp.txt find /? >>tmp.txt echo findstr /? >>tmp.txt findstr /? >>tmp.txt echo copy /? >>tmp.txt copy /? >>tmp.txt type tmp.txt ______________________________________________________ ###################################################################### 2. 环境变量概念 ###################################################################### _____________________________________________________________________________ C:\Program Files> ALLUSERSPROFILE=C:\Documents and Settings\All Users Comm:\Program Files\Common Files COMPUTERNAME=FIRST ComSpec=C:\WINNT\system32\cmd.exe NUMBER_OF_PROCESSORS=1 OS=Windows_NT Os2LibPath=C:\WINNT\system32\os2\dll; Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\WBEM PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 6 Model 6 Stepping 5, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=0605 ProgramFiles=C:\Program Files PROMPT=$P$G Drive=C: Root=C:\WINNT TEMP=C:\WINNT\TEMP TMP=C:\WINNT\TEMP USERPROFILE=C:\Documents and Settings\Default User windir=C:\WINNT _____________________________________________________________________________ path: 表示可执行搜索路径. 我建议是你把你copy 到 %windir%\system32\. 这个目录里面. 般就可以自动搜索到. 语法: copy mychenxu.exe %windir%\system32\. 使用点(.) 便于目了然 对环境变量引用使用(英文模式,半角)双引号 %windir% 变量 %%windir%% 2次变量引用. 我们常用还有 %temp% 临时文件目录 %windir% 系统目录 %errorlevel% 退出代码 输出文件到临时文件目录里面.这样便于当前目录整洁. 对有空格参数. 你应该学会使用双引号("") 来表示比如对porgram file文件夹操作 C:\>dir p* C:\ 目录 2000-09-02 11:47 2,164 PDOS.DEF 1999-01-03 00:47 <DIR> Program Files 1 个文件 2,164 字节 1 个目录 1,505,997,824 可用字节 C:\>cd pro* C:\Program Files> C:\> C:\>cd "Program Files" C:\Program Files> ###################################################################### 3. 内置特殊符号(实际使用中间注意避开) ###################################################################### 微软里面内置了下列不能够在创建文件名中间使用 con nul aux \ / | || && ^ > < * You can use most characters as variable values, including white space. If you use the special characters <, >, |, &, or ^, you must precede them with the escape character (^) or quotation marks. If you use quotation marks, they are d as part of the value because everything following the equal sign is taken as the value. Consider the following examples: (大意: 要么你使用^作为前导表示.或者就只有使用双引号""了) To create the variable value &name, type: varname=^&name To create the variable value "&name", type: varname="&name" The ampersand (&), pipe (|), and parentheses ( ) are special characters that must be preceded by the escape character (^) or quotation marks when you pass them as arguments. find "Pacic Rim" < trade.txt > nwtrade.txt IF EXIST filename. (del filename.) ELSE echo filename. missing > 创建个文件 >> 追加到个文件后面 @ 前缀.表示执行时本行在cmd里面不显示, 可以使用 echo off关闭显示 ^ 对特殊符号( > < &)前导. 第个只是显示aaa 第 2个输出文件bbb echo 123456 ^> aaa echo 1231231 > bbb 包含命令 (echo aa & echo bb) , 和空格样缺省分隔符号. ; 注释,表示后面为注释 : 标号作用 | 管道操作 & Usage:第条命令 & 第 2条命令 [& 第 3条命令...] 用这种思路方法可以同时执行多条命令而不管命令是否执行成功 dir c:\*.exe & dir d:\*.exe & dir e:\*.exe && Usage:第条命令 && 第 2条命令 [&& 第 3条命令...] 当碰到执行出错命令后将不执行后面命令如果直没有出错则直执行完所有命令; || Usage:第条命令 || 第 2条命令 [|| 第 3条命令...] 当碰到执行正确命令后将不执行后面命令如果没有出现正确命令则直执行完所有命令; 常用语法格式 IF [NOT] ERRORLEVEL number command para1 para2 IF [NOT] 12 command para1 para2 IF [NOT] EXIST filename command para1 para2 IF EXIST filename command para1 para2 IF NOT EXIST filename command para1 para2 IF "%1""" goto END IF "%1""net" goto NET IF NOT "%2""net" goto OTHER IF ERRORLEVEL 1 command para1 para2 IF NOT ERRORLEVEL 1 command para1 para2 FOR /L %%i IN (start,step,end) DO command [command-parameters] %%i FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do echo %i %j %k 按照字母顺序 ijklmnopq依次取参数. eol=c - 指个行注释结尾(就个) skip=n - 指在文件开始时忽略行数 delims=xxx - 指分隔符集这个替换了空格和跳格键默认分隔符集 ###################################################################### 4. 简单批处理文件概念 ###################################################################### echo This is test > a.txt type a.txt echo This is test 11111 >> a.txt type a.txt echo This is test 22222 > a.txt type a.txt 第 2个echo是追加 第 3个echo将清空a.txt 重新创建 a.txt netstat -n | find "3389" 这个将要列出所有连接3389用户ip. [ft=,,]____ 0
相关文章
读者评论
发表评论 |