Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

100 examples of DOS techniques


May 22, 2021 DOS Command learning manual




100 examples of DOS techniques


Source: http://www.cn-dos.net/forum/viewthread.php?tid=23999&fpage=0&highlight=&page=1

tianzizhi

2006-10-20 18:36


1, a short history of . .

You can use it. Instead, for example, delete all files in the current directory:

Del.

2, return the parent directory is the parent directory

Cd..

3, the list of directory files into the text file

DIR>filename

4, view any properties in the current directory of the file

Method one: DIR,

Method 2: DIR/A

5. Cancel all properties of all files in the current directory (in fact, you can only view the properties and not cancel the -jm bet)

ATTRIB,

If you execute this command in the C disk root directory, and then use DIR to view, you can see IO .SYS, MSDOS. Implicit files such as SYS

6. Display all subdirectdirectle names in the current directory

DIR/AD

7, continuous display of the contents of multiple files

COPY *.* CON

8, split-screen display file content

Method one: MORE-lt;filename

Method 2: TYPE filename |more

9, change the registration time of disk files

Method one: COPY filename and NUL

Method two: COPY filename plus,

10. How do I mask the output information of DOS lines?

The method is to redirect the screen output to the DOS empty device NUL, for example:

COPY MYPROG. EXE A:>NUL

11. In the DOS state, the contents of the WPS file edited in D are displayed directly

COPY filename.wps CON/B

12, append data to the text file

Method one: COPY filename and CON

Method 2: TYPE CON.gt;filename

When the input is complete, press the F6 or Ctrl-Z key to end.

13. A simple screen for keyboard fingering exercises or Chinese character input exercises

COPY CON NUL

14, directly print keyboard input

Method 1: COPY CON PRN

Method II: MORE> PRN

Method 3: SORT.PRN

After entering, press the F6 or Ctrl-Z key.

15, DOS under the direct editing of the generated file

In the absence of any editing software (e.g. EDLIN, EDIT, etc.), you can temporarily use the following six methods to edit the generated file from the keyboard, when the contents of the file is finished, press F6 key or press Ctrl-Z key deposit exit:

Method one: COPY CON filename

Method 2: TYPE CON>filename

Method 3: MORE> filename

Method FOUR: SORT>filename

Method 5: FIND "XXX" / V / N> filename

Method 6: SORT | FIND"XXX"/V/N>filename

Method four, five, six have special uses, readers may wish to try.

16, the generation of zero-byte files

Method: TYPE NUL;filename

The above method is often used to deal with disk files that need to be kept confidential, and plays the role of deleting the contents of the files, which are generally not recoverable after they are deleted.

17, the copy of the zero-byte file, can not use the COPY command, can only use the XCOPY command.

For example: XCOPY filename1 filename2

18, the replication of all files and subdirectts in the directory

XCOPY directory name. Drive signal: /S

19. How do I use COPY and XCOPY commands correctly?

When you join several files into one file, you should use the COPY command.

Copy a single file smaller than 64KB and use the COPY command. XCOPY commands should be used to copy files larger than 64KB.

Copy multiple files should use the XCOPY command.

Copy the contents of the subdirect directory and use the XCOPY/S command. Copy a batch of files to a floppy disk and use the XCOPY/M command.

20. When do I use the XCOPY command/D switch item?

Sometimes you need to "select" files from a directory that have been established or modified from a certain day and back them up, at which point you can use the XCOPY/D command. F or example, the following command may copy files in the C: directory that were established or modified after 1 July 1996 to disk A:

XCOPY C:*.* A:/D:07-01-96

21, single floppy copy floppy disk

Some PCs are equipped with only one floppy drive, which is used both as an A disk and as a B disk, and if you want to copy a floppy disk on such a system, use the following XCOPY command:

XCOPY A: B:

22. Organize the pieces in the floppy disk to improve the efficiency of use

After a floppy disk has been set up and deleted many times, some file records will be stored in the floppy disk space in an unsequel form, resulting in many pieces of floppy disk space, affecting the read and write operation performance of the floppy disk, which can lead to read and write failure in severe cases.

To resolve the above issues, you can use the COPY command to make a copy of the whole disk, so that the files on the new disk remain in continuous storage.

23. Multiple documents were tortured into multiple floppy disks in a row.

First, set the document characteristics of each file with the ATTRIB command:

ATTRIB+A *.*/S

The XCOPY command is then used to insert a new disk when the floppy disk is full, depending on the document characteristics, to determine which files need to be copied and which do not.

XCOPY *.* A∶/S/M/W

24. Use the TYPE command to "copy" the file

Copying files usually uses the COPY command or the XCOPY command, in fact, TYPE also has the purpose of "copying" the file:

TYPE filenamel>filename2

This approach is very effective for copying implied files. F or example: TYPE IO. SYS>A∶IO.SYS

25. Display the file or directory in a small case

DIR/L

26. Only file names and subdirecter names are displayed, and information such as file size and build time is not displayed

DIR/B

27. Make the DIR always display the files in alphabetical order of the file name

The following command can be added to AUTOEXEC BAT:

SET DIRCMD=/O

28. The file directory created by the column on the same day

If you would like to know how many documents were established on that day (e.g. 21 October 1996), you can list them using the following command:

DIR| FIND"10 21 1996"

29. If you don't want someone else to use the DIR command for a list of directory files, what's the way?

Method 1: DOSKEY DIR - You can not use DIR!

Method 2: Add the command line in AUTOEXEC BAT: SET DIRCMD=0

The function of this command is to display only "File not found" when the file is displayed with the DIR command, which can act as a temporary secret. To display files and directories, only specify a specific file name or path.

Methods III: SET DIRCMD s DIR;NUL

This command, which is executed and then uses the DIR command, will output information that is not documented and is confusing.

30. Out of all directories of files

CHKDSK/V|MORE

31. How to find files on disks with multiple directories

Method 1: CHKDSK/V|find "file name" Chinese the first part of the name must be capital letters.

Method 2: DIR/S file name

32. Control the line or page change of the printer in real time

ECHO-PRN (Line Change)

ECHO-L-PRN (Page Change)

33. Make the computer sound on the DOS command line

ECHO ^G

34. Automatic response to questions on DOS commands

For example:

ECHO Y| DEL C∶

ECHO N| CHKDSK C∶/F

35. Make the ECHO command show empty lines

When the ECHO command is followed directly by the space character, echo will display the current information echo state (ON or OFF) instead of echoing the empty line directly to the screen. In fact, the following very simple command format can make the ECHO command display empty lines:

ECHO ECHO, ECHO; ECHO+

ECHO[ ECHO] ECHO/ ECHO\par

36. Feed the car character back to the interactive DOS command with the ECHO command

For example:

ECHO+| D ATE| F IND"Current date"

ECHO+| T IME| F IND"Current time"

This technique can be used in autoexEC .BAT to display the current date and time information directly after each power-up, without having to press the enter key to continue.

37. Power-on time black box

Sometimes it is necessary to record the date and time of each use of the computer in order to enhance machine management. The above techniques can be used only by adding the following commands .BAT auto-documents:

ECHO+| DATE>>ABC

ECHO+| TIME>>ABC

This automatically records the date and time in the file ABC each time the computer is started, and the execution command TYPE ABC can view the previous boot date and time.

38. Automatically count the run time of a command or file

Here is a timer TIMETEST .BAT to implement the automatic statistical command or file run time:

@ECHO OFF

TIME 0

COMMAND /C %1 %2 %3 %4

ECHO %1 %2 %3 %4 runs at:

ECHO+| T IME| FIND"time is"

@ECHO ON

For example, test AUTOEXEC .BAT run time:

C>TIMETEST AUTOEXEC. BAT ┆

AUTOEXEC. BAT runs at:

Current time is 0∶00∶03 49

Explain that AUTOEXEC .BAT running for 3.49 seconds.

39. Skip or step through the CONFIG .SYS and AUTOEXEC .BAT files

Method 1: Start the computer, the screen appears Arting MS-DOS... When pressed F5 or SHIFT, DOS skips the CONFIG.SYS and AUTOEXEC .BAT files and starts the machine with the basic environment configuration in which the system operates.

Method 2: When the above prompt appears, press the F8 key, and through the keyboard one by one to answer Y or N to choose to execute the command.

Method 3: Add "?" .SYS the command of the CONFEG file. n umber. For example, DOS? .

40. Can I save the two seconds to wait for F8 or F5 to start at DOS?

Yes. This is done by adding the statement SWITCHES=/F to the head of the CONFIG SYS file, after which the previous function can also be implemented by pressing the F8 or F5 keys when "Starting MS-DOS..." does not appear.

41. Step through the batch files

COMMAND/Y/C (batch file name)

Switch/Y tells DOS to pause before executing each line, prompting the user if it is performing.

42. Get help with DOS commands quickly

Method one: FAST HELP command name

Method 2: Command name/?

Method 3: Command name/H

43. Easily change the subdirecter name

The following MOVE command changes the name of the C:directory to C::

MOVE C∶ C∶

44. When do I use the MOVE command to move files?

The biggest feature of the MOVE command is that you can list multiple files to be moved from one command line, and the "and" numbers are available between the files. For example, move all executables in the current directory into the directory:

MOVE *.COM,*. E XE,*. BAT

45. Use the MOVE command to simply encrypt or decrypt the subdirection

Encryption: If the C: directory uses half a Chinese character for simple encryption, you can execute the command:

MOVE C: C (half characters)

Decryption: Conversely, you can use the MOVE command to change the unrecognized directory name to a different name for decryption purposes by combining the wildcard, or ?.

46. Quickly enter the deep subdirecte

Drive identifiers can be set with the SUBST command, replacing deep subdirectdirector paths, making it easy to enter deep subdirectdirectors. For example, the following command simulates subdirection C: as an M disk:

SUBST M∶ C∶

This allows you to enter the PRG subdirect directory by simply turning the current drive into M in any directory.

47. How do I cancel the disc character set by SUBST?

For example, to cancel the M disk in the example above, you only need to execute the command SUBST M:/D.

48. Establish and enter the MD command for the new directory

The MD command in DOS can only be set up subdirecter, built and then entered with CD command, in fact, you can use:

DOSKEY MD=MD $1 $T CD $1

The MD command is redefined, and when MD is used thereafter, the establishment of the directory and the entry of the directory are synchronized.

49. List of exclusion files

Wildcards are supported in diR commands, and? I nstead of other characters, it does not provide the ability to exclude characters, and the exclusion list can be easily implemented with the /V parameters in the FIND command. T he following command removes. All files other than BAK files and subdirectts are listed:

DIR| F IND/V"BAK"| FIND/V"<DIR>"

The difference between 50. and . .

DIR/DIRLIST: If a DIRLIST file exists, the contents of the file are cleared and new content is entered into the file.

DIR?gt;DIRLIST: If a DIRLIST file exists, attach the output data to the end of the file.

When the DIRLIST file does not exist, the two are equivalent.

51. Quickly add a search path

PATH=%PATH%;%1

52. An automatic search path is established for non-executable files such as data files and text files generated by word handlers.

The APPEND command adds a specified set of directories to the logical extension of the current directory, allowing you to open this set of files without specifying a path. APPEND can be put into multiple directories, as long as the use of ";" can be separated, for example:

APPEND C∶;C∶;C∶;C∶;

53. Hide the directory name

Because the ATTRIB command can change the properties of a directory, it allows you to hide the directory name. For example, hide directory C:

ATTRIB +H C∶

54. Quickly delete the tree

The DELTREE command allows you to quickly delete a specified directory, regardless of how many subdirectts and directories and files are properties in the directory. For example: DELTREE C:

55. Prevent the deletion of files by mistake

The DEL command is a dangerous command that can be redefined with the following command, so that there is a confirmation prompt when deleting a file:

DOSKEY DEL=DEL $1/P

56. If certain files are deleted by mistake, what are the ways to recover them in a timely manner?

The UNDELETE command can be used to recover deleted files, and the following command can recover deleted files from the current directory:

UNDELETE *.*/ALL

The first character of the file name recovered by this command becomes the s, which can be changed to the original file name using the REN command.

57. When deleting files with multiple file names with no common characteristics, it is difficult to use wildcards and can only be deleted one by one, which is cumbersome. Is there any other convenient way?

Yes. Using the DEL../P command, all files in the specified directory are listed one by one, asking the user if they want to delete them, and answering Y to the file you want to delete, or answer N.

58. Encrypting file names

Add the ASCII character 255 at the end of the file name to be encrypted. T he method is to enter the file name, press the ALT key, and then enter 255. In this way, when the file is listed with the DIR command, this character is not displayed, i.e. no change is visible from the file name, which plays a certain role in encryption.

59. Recall used commands

After executing the DOSKEY command, the commands entered by the user are stored, and later, to recall the commands used, you can always use the "

60. Illegal access to a drive is prohibited

Add the following two commands to autoEXEC.BAT file, you can prohibit illegal access to the D disk, when you enter D:, the screen is turned off, only those who know the password ZM can enter the D disk:

DOSKEY D∶=ECHO OFF

DOSKEY ZM=D∶

61. Prevent others from misformatting the C disk

In order to protect the C disk from formatting others, the FORMAT command can be redefined with DOSKEY, for example:

DOSDEY FORMAT=You can not format C∶!

In this way, someone else will be prompted by Yor can not format C:! when using FORM, so that the C disk is protected. If you want to use FORMAT, then use the following command to resume:

DOSKEY FORMAT=

62. Check the screen status for reports on the number of characters and lines displayed on the screen

MODE CON

63. Set the number of characters and the number of lines per screen on each line of the screen

For example:

MODE CON COLS=80 LINES=25

64. Improve the responsiveness of the keyboard

MODE CON∶RATE=32 DELAY=1

65. What if I don't like the default settings for the Num Lock key when the system starts?

Add the NUMLOCK command to the CONFIG SYS file to specify the status of the NUMLOCK key when the system starts, depending on your hobby:

NUMLOCK -ON (or OFF)

66. Simple keyboard lock

When you use the computer, if you only leave for a while, and do not want to shut down, in order not to let others use at will, you can compile a simple keyboard lock LOCK BAT program (as follows):

@ECHO OFF

Cls

CHOICE/C:*/N

After running, the same as the crash, the number is the key to the keyboard lock, do not know the person can not decipher.

67. The selection of documents is displayed

Suppose there are MY1 TXT, MY2 TXT、...、MY10. T XT a total of 10 files, now want to show my2.TXT, MY3. T XT、MY6. TXT and MY9 .TXT 4 files that can be easily implemented with the following commands:

FOR %A IN(2369)DO TYPE MY%A.TXT

68. Delete the misd copy of the file

When using the COPY A: . . . command to copy all the files on the A disk to a subdirection of the hard disk, but inadvertently copied to the hard disk root directory, such as the number of files mistakenly copied, and the file name does not have any characteristics, when you want to delete these files, usually the practice is to use PCTOOLS tool software to choose to delete, more troublesome. Using the FOR command is much simpler:

A>FOR %A IN(*.*)DO DEL C∶%A

69. Since the FIND command cannot accept wildcards, if you want to find a string insert in several text files, you can only use the FIND command in turn for each file.

Yes. Use the FOR command to mate with the FIND command in the format:

FOR%A IN (file group) DO FIND "string"%A

70.FOR commands cannot be nested, is there any way to achieve FOR loop nesting?

Yes. Y ou can COMMAND.COM as a command in the first layer loop, and let it execute another FOR loop command. For example, the following command can display 12 lines of "Welcome you" on the screen: FOR %A IN(123) DO COMMAND/C FOR %B IN (1234) DO ECHO Welcome you

71. Double colon: the role of the comment line

At the beginning of a DOS batch file, the REM comment command is often used plus a header. For example, suppose you have a batch file named TEST.BAT that has a text file named Input Parameter, and if you start with a comment line that states its usage, you use a comment line with the words "lt; and "gt;" and parentheses, i.e.:

REM TEST<filename>

When the program executes this command, doS displays "File not found" information because it assumes that fileame is the source file for a redirect input operation that cannot be found in the current directory. How to solve this problem?

Very simple, only need to change the REM to double colon "::", that is:

∶∶TEST<filename>

72. IF ERRORLEVEL in batch

Be careful when using the IF ERRORLEVEL command in batch files because DOS considers any export status value greater than or equal to the set value to be equivalent. Exit status values should usually be tested in order from large to small, such as:

IF ERRORLEVEL 2 ECHO TWO

IF ERRORLEVEL 1 ECHO ONE

IF ERRORLEVEL 0 ECHO ZERO

73. Can I test the exit status values in order from small to large?

Yes. However, it should be judged in the form of IF NOT, for example, the command in 72 cases should be changed to:

IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 ECHO ZERO

IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 ECHO ONE

IF ERRORLEVEL 2 IF NOT ERRORLEVEL 3 ECHO TWO

74. In the batch file, the command is not displayed on the screen using the character

Because DOS displays individual commands on the screen before they are executed, even if you set the ECHO command as OFF, it will appear on the screen itself. To suppress its display, you can add the character ECHO OFF before the ECHO command line

75. Count the number of rows in the source program

Assuming that the source program is named ZM.PRG, the following FIND command can easily count how many rows it has:

FIND/V/C" "ZM. PRG

76. Sort text files

SORT commands are often used to sort and display some text-line-based files. F or example, display a checklist file with a phone number by the first letter of the name. Command format:

SORT[/R][/+n]<filename1>filename2

Where ,/R indicates reverse sorting, /n means sorting from the first few lines, filename1 is the source file name, and filename2 is the sorted file name.

77. Set meaningful prompts with PROMPT

The PROMPT command is used to set a new DOS system prompt. For example:

THE $P the current drive name and directory as a prompt using $G

THE $D $G to take the current system date as a prompt.

78. How do I set the screen color?

Assuming that the .SYS is already installed in memory, the following command sets the screen to red on a white background:

PROMPT $E[31;47m

79. Date and time information is displayed in the selected location on the screen

Combining ANSI SYS screen and cursor control with PROMPT's set DOS command prompt function, special information can be displayed at selected locations on the screen. For example, by adding the following command line to AUTOEXEC BAT, you can move the date and time information to the bottom right of the screen:

PROMPT $E[S $E[25; 52H $D$T $E[u $P$G

80. Edit the last command with the F2 key

The last command can be copied with the F1 or F3 function keys, similar to F2 keys can get some of the last commands, when the F2 key is pressed, DOS copies the contents of the last command to the characters typed after pressing F2 keys (not included).

For example, type the following command:

C>DIR.COM<enter>

Press the F2 key and the M key, you can get:

C>DIR

Then press INS insert key, enter R, and then press F3 key to copy the rest of the last command, get the correct command:

C>DIR.COM

81, edit the last command with the F4 key

When the F4 key is pressed, doS copies the last command from the letter pressed after pressing the F4 key. For example, the last command was:

C>DIR[enter]

Press the F4 key, enter F, and then press F3, and the DOS will display the FORMat command:

C>FORMAT

82, use the SHELL command to change the size of the environment space

By increasing the space of the environment variable to 1KB, the command line .SYS can be added to the CONFIG file:

SHELL=C∶.COM/P/E∶1024

83. Reference environment variables in the batch file

Batch files can refer to environment variables that are defined on the system. T his is done by placeing a percent sign "%" before and after the name of the environment variable. For example, to display the contents of the environment variable PATH in a batch file, you can add command line:

ECHO %PATH%

84. View individual environment variables

If you use environment variables frequently, the list can be long and the screen can be cluttered when all currently allocated environment variables are displayed with the SET command. For convenience, you can use the following batch fileVIEWENV .BAT display a single environment variable directly on the command line:

SET| FIND/I "%1"

For example, to look at the contents of COMSPEC, you only need to perform:

VIEWENV COMSPEC

85, the production of DOS system disk

Method one: FORMAT A:/S

Method TWO: SYS A:

86, regularly organize the hard disk

Specific steps:

Delete unnecessary files from your hard drive

Run CHKDSK/F

Run DEFRAG

87, understand the type of memory

Regular memory: 0 to 640KB

Upper Memory Area (UMA): 640KB to 1MB

Extended memory: extends upward from 1MB

High Memory Area (HMA): An extended memory area of less than 1MB that is slightly less than 64KB

Expand memory

88. Move DOS to a high memory area

In order for the user to have a large amount of available basic memory, the following commands can be added to the CONFIG.SYS file to load theIMEM .SYS and move the DOS into the High Memory Area (HMA):

DEVICE=C∶.SYS

DOS=HIGH

89. Load device drivers and memory resident programs into upper memory (UMB)

Add a command .SYS CONFIG file:

DEVICE=C∶.EXE NOEMS

DOS=UMB

90, load the program into a high memory area

The way to load a program into an HMA is to add a/U switch to the command line, for example:

MOUSE/U

91, the use of upper memory

In order to resident the program in upper memory, use LOADHIGH (or LH)

LH MOUSE

92. How do I show how a particular program is using memory?

MEM/M module

Where module represents a specific program file name, do not bring an extension.

93, the use of Memmaker automatically optimize memory

By executing the MEMMAKER/BATCH command, MEMMAKER automatically sets the optimal settings for CONFIG.SYS and AUTOEXEC.BAT files, after which the MEM/C/P is executed to observe the allocation of memory, you will find that the main memory becomes erred.

94. What should I do if I'm not satisfied with MEMMAKER's optimization settings?

It's easy to restore your original configuration by simply executing MEMMAKER/UNDO.

95, disk high-speed buffer memory SMARTDRV use

To establish a disk cache with 256K (default), the command line can be .BAT the AUTOEXEC file:

C∶

Because SMARTDRV is built into extended memory, command lines must also be .SYS conFIG file:

DEVICE=C∶.SYS

96. When you shut down your computer or restart, and you want to make sure that all the cached information has been written to the hard disk, you should type the command at the system prompt:

SMARTDRV/C

97. Skip SCANDISK's magnetic media scan

When running SCANDISK, magnetic media scanning takes a long time, in fact, you can skip it using SCANDISK/CHECKONLY.

98, loadFIX command correct use

During the optimization process, a few programs do not run correctly within the low 64KB of normal memory of 640KB. At this point, the LOADFIX command allows executable programs such as ZMPROG.EXE to run in memory above 64KB by adding LOADFIX:before the application you want to run

LOADFIX ZMPROG

99. When do I use a virtual disk (also known as a RAM disk)?

The RAM disk significantly increases access to disk files, but it loses data when power is lost or re-started. T herefore, use the RAM disk with special care. Ram drives are worth using on systems without hard drives, can also be used when larger temporary files or replicators are needed, and when your system is equipped with CD-ROMs, the files and data on the CD-ROM disk can be copied into the RAM disk before starting work, which can significantly improve efficiency.

100, the installation of virtual disk

The RAMDRIVE .SYS provided by DOS is a virtual disk driver that you can install into memory and let it use extended memory or expanded memory to generate a specified size RAM disk. For example, by .SYS the following command in the CONFIG module, you can generate a 1MB RAM disk in extended memory:

DEVICE=C∶.SYS 1024/E