|
自由人
初级用户
 
积分 169
发帖 15
注册 2002-12-29
状态 离线
|
『楼 主』:
DOS命令技巧集锦
使用 LLM 解释/回答一下
批处理的技巧是很多的,能完成许多Windows下做不来或做不好的事。
@echo off //取消命令运行时在屏幕的显示
echo. |date| find "Current" //只显示日期
echo. |time| find "Current" //只显示时间
:: //相当于rem
call //调用另外一个批文件
del %0 //自我删除
if "%1" == "字符串" goto //如 if "%1" == "/p" goto p
if "%1" == "字符串" 命令 //if "%1" == "/p" dir /w/p c:
if exist 文件 命令 //如果文件存在则运行命令
copy /b //文件合并
fdisk /mbr //卸载主引导记录 如果被LILO覆盖了主引导记录,可以用来清除
prompt $p$g //恢复提示符
echo Free and Open > new DOS.txt //将Free and Open写入new DOS.txt
echo Happy New year >> new DOS.txt //继续将Happy New year写入new DOS.txt
lh //将设备载入高端 如lh smartdrv /x
mode 80 恢复显示默认设置
mode mono 激活单色显示器
mode con:cols=40-80 lines=25-50 //40-80;25-50为参数
键盘控制
mode con:rate=32 delay=1 //轻捷
mode con:rate=20 delay=4 //准确
mode con:rate=20 delay=2 //默认
打印控制
mode com1:9600,8,N,1 //快速
mode lpt1=com1
mode com1:2400,8,N,1 //慢速
mode lpt1=com1
echo 你好 > prn //测试打印
安装光驱
config.sys加中入
devicehigh=boot\CD-ROM.sys /d MSCD001
autoexec.bat加入
path boot
mscdex /d MSCD001 /m 12
//CD-ROM.sys 可用万能光驱IDE.sys代替
//菜单显示,选择
echo 1.
echo 2.
echo 3.
...
echo 9.
choice /c:123456789 /n 请选择:
if errorlevel 9 goto 9
if errorlevel 8 goto 8
if errorlevel 7 goto 7
if errorlevel 6 goto 6
if errorlevel 5 goto 5
if errorlevel 4 goto 4
if errorlevel 3 goto 3
if errorlevel 2 goto 2
if errotlevel 1 goto 1
简单的一个范例
@echo off
if "%1" == "/all" goto all
If exist c:\1.txt goto 1
echo 没有找到文件1.txt
goto end
:1
echo 文件1.txt存在,按任意键阅读...
pause > nul
type 1.txt | more
goto end
:all
dir /s/w/p 1.txt
:: 显示C盘子目录下所有1.txt
:end
Batch processing has many techniques and can accomplish many things that can't be done well in Windows.
@echo off //Cancel the display of command operation on the screen
echo. |date| find "Current" //Only display the date
echo. |time| find "Current" //Only display the time
:: //Equivalent to rem
call //Call another batch file
del %0 //Self - delete
if "%1" == "string" goto //For example, if "%1" == "/p" goto p
if "%1" == "string" command //if "%1" == "/p" dir /w/p c:
if exist file command //Run the command if the file exists
copy /b //Merge files
fdisk /mbr //Uninstall the master boot record. If the master boot record is overwritten by LILO, it can be used to clear it
prompt $p$g //Restore the prompt
echo Free and Open > new DOS.txt //Write Free and Open into new DOS.txt
echo Happy New year >> new DOS.txt //Continue to write Happy New year into new DOS.txt
lh //Load the device into the upper memory. For example, lh smartdrv /x
mode 80 Restore the default display settings
mode mono Activate the monochrome display
mode con:cols=40-80 lines=25-50 //40-80;25-50 are parameters
Keyboard control
mode con:rate=32 delay=1 //Agile
mode con:rate=20 delay=4 //Accurate
mode con:rate=20 delay=2 //Default
Print control
mode com1:9600,8,N,1 //Fast
mode lpt1=com1
mode com1:2400,8,N,1 //Slow
mode lpt1=com1
echo Hello > prn //Test printing
Install CD - ROM
Add in config.sys
devicehigh=boot\CD-ROM.sys /d MSCD001
Add in autoexec.bat
path boot
mscdex /d MSCD001 /m 12
//CD-ROM.sys can be replaced by universal CD - ROM IDE.sys
//Menu display, selection
echo 1.
echo 2.
echo 3.
...
echo 9.
choice /c:123456789 /n Please choose:
if errorlevel 9 goto 9
if errorlevel 8 goto 8
if errorlevel 7 goto 7
if errorlevel 6 goto 6
if errorlevel 5 goto 5
if errorlevel 4 goto 4
if errorlevel 3 goto 3
if errorlevel 2 goto 2
if errotlevel 1 goto 1
A simple example
@echo off
if "%1" == "/all" goto all
If exist c:\1.txt goto 1
echo The file 1.txt is not found
goto end
:1
echo The file 1.txt exists, press any key to read...
pause > nul
type 1.txt | more
goto end
:all
dir /s/w/p 1.txt
:: Display all 1.txt in the sub - directories of the C drive
:end
|
|
2002-12-31 00:00 |
|
|
nre
银牌会员
     nre
积分 1210
发帖 361
注册 2002-12-28
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
不错不错~ 不过希望再归归类,这样的方式不方便查找和学习
请教个问题 DEL %0 怎么用?
更正一下上面一些不妥的地方
FDISK/MBR 不是删除MBR(主引导记录),而是用默认的主引导记录覆盖当前的MBR内容
copy /b 仅这个不能实现合并,/B是指定以2进制方式合并, /A就是ASIIC文件。
copy 文件1 + 文件2 +。。。文件N 目标文件
choice,mode,more都是外部命令,编BAT时如果用到这些命令,要考虑到文件存在否
Not bad~ But I hope to classify them again, because this way is not convenient for searching and learning.
Ask a question: How to use DEL %0?
Correct some improper places above.
FDISK/MBR does not delete the MBR (Master Boot Record), but overwrites the current MBR content with the default master boot record.
copy /b alone cannot achieve merging. /B specifies merging in binary mode, and /A is for ASIIC files.
copy file1 + file2 +... fileN target file
choice, mode, more are all external commands. When compiling BAT, if these commands are used, it is necessary to consider whether the file exists.
|

Teamwork ! |
|
2002-12-31 00:00 |
|
|
自由人
初级用户
 
积分 169
发帖 15
注册 2002-12-29
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
谢谢NRE指正不妥之处
把del %0加在批处理文件的最后嘛 完成后就自我删除了
上面绝大多数命令都可以直接插入批处理文件中使用
只是仅仅列出一部分技巧及不常用的命令参数,还有许多待我整理后将一一列出。当然如果有人有这方面的问题的话,我会很乐意为你解答。
Thanks to NRE for pointing out the inappropriate parts. Add "del %0" at the end of the batch file, and it will self-delete after completion. Most of the above commands can be directly inserted and used in the batch file. It's just that only a part of the skills and less commonly used command parameters are listed, and there are many more to be listed after I sort them out. Of course, if anyone has questions in this regard, I will be happy to answer for you.
|
|
2003-1-1 00:00 |
|
|
nre
银牌会员
     nre
积分 1210
发帖 361
注册 2002-12-28
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
DEL 的这种用法还是第一次看到,经典~
我试了一下,%0里存的是调用文件的文件名,不包括扩展名
所以 需要加上扩展名 del %0.bat 才能实现自动删除
不过这么做,运行之后会出现BATCH FILE MISSING的提示
This is the first time I've seen this usage of DEL. Classic~
I tried it, and %0 stores the file name of the called file, excluding the extension. So you need to add the extension. del %0.bat to achieve automatic deletion. But when doing this, after running, there will be a prompt of BATCH FILE MISSING.
|

Teamwork ! |
|
2003-1-1 00:00 |
|
|
tanglu_sd
高级用户
   
积分 948
发帖 271
注册 2002-12-13 来自 sd
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
用win98自带的启动盘启动后的虚拟的盘,是怎么建立出来的?
How is the virtual disk created after booting with the built-in startup disk of Win98?
|
|
2003-1-1 00:00 |
|
|
小臣
初级用户
 
积分 123
发帖 6
注册 2003-1-6
状态 离线
|
『第 6 楼』:
可以教一下我吗?
使用 LLM 解释/回答一下
DEL %0 自我删除 有什么作用的呢???
What is the function of DEL %0 self-deletion????
|
|
2003-1-6 00:00 |
|
|
小臣
初级用户
 
积分 123
发帖 6
注册 2003-1-6
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
照你的写法来看,在DOS下,是不是要装UCDOS呢??
According to your writing, in DOS, do you need to install UCDOS?
|
|
2003-1-6 00:00 |
|
|
小臣
初级用户
 
积分 123
发帖 6
注册 2003-1-6
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
有谁可以教教我在DOS下,我只会用FDISK CD DIR DEL SCANDISK MD RD 等这几个命令,请问DOS高手门还有没有其它的呢???请多多多多多指教!
Who can teach me under DOS, I only know how to use FDISK CD DIR DEL SCANDISK MD RD and other commands. Is there any other ones for DOS masters??? Please give more more more guidance!
|
|
2003-1-6 00:00 |
|
|
mys
元老会员
        
积分 5170
发帖 1637
注册 2002-10-16 来自 广东佛山
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
还有很多。
diskcopy
msav
xcopy
smartdrv
help
deltree
format
sys
...
There are still many.
diskcopy
msav
xcopy
smartdrv
help
deltree
format
sys
...
|

我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
|
|
2003-1-6 00:00 |
|
|
Wengier
系统支持
             “新DOS时代”站长
积分 27736
发帖 10521
注册 2002-10-9
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
DEL %0这个命令很有问题,因为%0参数其实返回的是用于执行此批处理文件的命令行。例如,当我想执行ABC.BAT批文件的时候,在命令行上输入ABC或ABC.BAT都可以执行,这样,%0的值就可能完全不同,也就是说它的值为“ABC”或“ABC.BAT”等都可能。而若为前者的话,DEL %0也就是DEL ABC是不可能将ABC.BAT自身删除的。
The command DEL %0 is quite problematic because the %0 parameter actually returns the command line used to execute this batch file. For example, when I want to execute the ABC.BAT batch file, I can enter ABC or ABC.BAT on the command line to execute it. In this way, the value of %0 may be completely different, that is, its value may be "ABC" or "ABC.BAT", etc. And if it is the former, DEL %0, that is, DEL ABC, is impossible to delete the ABC.BAT itself.
|

Wengier - 新DOS时代
欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/
E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)
 |
|
2003-1-6 00:00 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
要不就执行两句:
DEL %0
DEL %0.BAT
两条都写上,总有一个可以正常删掉自己~:)
Then execute two lines:
DEL %0
DEL %0.BAT
Write both, there will always be one that can delete itself normally~:)
|
|
2006-9-29 06:17 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
del %~f0
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-9-29 07:27 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
C:\TEMP\t 1 2 3>type demo.bat
echo.
echo %0
echo %~f0
pause
del %~f0
C:\TEMP\t 1 2 3>
系统提示:
C:\TEMP\t 1 2 3>demo.bat
C:\TEMP\t 1 2 3>echo.
C:\TEMP\t 1 2 3>echo demo.bat
demo.bat
C:\TEMP\t 1 2 3>echo C:\TEMP\t 1 2 3\demo.bat
C:\TEMP\t 1 2 3\demo.bat
C:\TEMP\t 1 2 3>pause
请按任意键继续. . .
C:\TEMP\t 1 2 3>del C:\TEMP\t 1 2 3\demo.bat
系统找不到指定的文件。
C:\TEMP\t 1 2 3>
原来带空格的目录名DEL时没引号:)
C:\TEMP\t 1 2 3>type demo.bat
del "%~f0"
执行:
C:\TEMP\t 1 2 3>demo.bat
C:\TEMP\t 1 2 3>del "C:\TEMP\t 1 2 3\demo.bat"
被删掉了~:)
感谢 electronixtar 的精彩 %~f0 代码,我又学到好多东东~:)
后来for /? 的注释: %~fI - 将 %I 扩展到一个完全合格的路径名
这个 %~f0 用的真精彩~:)
C:\TEMP\t 1 2 3>type demo.bat
echo.
echo %0
echo %~f0
pause
del %~f0
C:\TEMP\t 1 2 3>
System prompt:
C:\TEMP\t 1 2 3>demo.bat
C:\TEMP\t 1 2 3>echo.
C:\TEMP\t 1 2 3>echo demo.bat
demo.bat
C:\TEMP\t 1 2 3>echo C:\TEMP\t 1 2 3\demo.bat
C:\TEMP\t 1 2 3\demo.bat
C:\TEMP\t 1 2 3>pause
Press any key to continue . . .
C:\TEMP\t 1 2 3>del C:\TEMP\t 1 2 3\demo.bat
The system cannot find the file specified.
C:\TEMP\t 1 2 3>
Original note: When deleting a directory name with spaces, there were no quotes in the DEL command :)
C:\TEMP\t 1 2 3>type demo.bat
del "%~f0"
Execution:
C:\TEMP\t 1 2 3>demo.bat
C:\TEMP\t 1 2 3>del "C:\TEMP\t 1 2 3\demo.bat"
It was deleted~ :)
Thanks to electronixtar for the wonderful %~f0 code, I learned a lot more~ :)
Later, the comment for for /? : %~fI - Expand %I to a fully qualified pathname
This %~f0 is really wonderful~ :)
|
|
2006-9-29 07:47 |
|
|
jieok3375
中级用户
  
积分 282
发帖 130
注册 2006-9-20 来自 广东
状态 离线
|
|
2006-9-30 03:52 |
|
|
winzip126
新手上路

积分 18
发帖 6
注册 2006-10-21
状态 离线
|
|
2006-10-23 23:24 |
|