Batch Processing commands provided by DOS

Source: Internet
Author: User

The file name is composed of the file path and file name, for example, C: \ DOS \ COMMAND. COM.

DIR Displays files and folders (directories ).
Usage: DIR [file name] [Option]

It has many options, such as/A indicating that all files (including files with implicit and system attributes) are displayed,/S indicating that files in subfolders are also displayed, And/P indicates that all files are displayed on the split screen, /B indicates that only the file name is displayed, and so on.
For example, dir a *. EXE/A/P
This command displays all files (folders) starting with A and suffixed with EXE in the current folder on the screen ).

CD or CHDIR change the current folder.
Usage: CD [Folder name]
If no folder name exists, the current path is displayed.

Create a folder by using MD or MKDIR.
Usage: MD folder name

RD or RMDIR.
Usage: RD folder name
Note: The folder must be empty.

DEL or ERASE.
Usage: DEL/ERASE file name

COPY a file.
Usage: COPY file name 1 [file name 2] [Option]
For example, COPY/B a + B C
This command combines two binary files A and B into one file C.

TYPE: displays the file content.
Usage: TYPE file name

RENAME or RENAME change the file name and folder (directory) Name.
Usage: REN file (folder) Name 1 file (folder) name 2

EDIT file, you can also EDIT binary files and multiple files in MS-DOS 7.x.
Usage: EDIT [file name] [Option]
For example, EDIT/70 C: \ COMMAND. COM
This COMMAND is used to edit the C: \ COMMAND. COM file in binary mode.

FORMAT the disk.
Usage: FORMAT drive [Option]

There are many options, such as/Q is quick formatting,/utable shows unconditional formatting (that is, the UNFORMAT command cannot be used to restore),/V specifies the volume name of the disk, and so on. It also has many undisclosed parameters.

MEM displays the memory status.
Usage: MEM [Option]

There are also a lot of options, such as/C can list the memory usage of all programs,/D is to display the memory resident program and the device driver status and other details, /F shows the total amount of idle memory,/M shows the module information in the memory, and/P shows the sub-screen display. There are also hidden/A options to display HMA information.

You can also change the name of a file or folder by moving the file or folder.
Usage: MOVE a file [Folder] 1 file [Folder] 2
For example, move c: \ *. exe d:
This command can be used to move all files with the extension EXE under the C root folder to the D Drive.

Copy files or folders.
Usage: XCOPY file [Folder] Name 1 [file [Folder] Name 2] [Option]

It has many options, for example,/S can copy files in the entire folder (including subfolders),/E specifies to include empty folders, /V indicates the correctness of the copied file after copying,/Y indicates confirmation, and so on.

CLS clears the screen.
Usage: CLS

SYS transmits the system file (such as IO. SYS) from one place to the specified drive.
Usage: SYS folder name [Drive]
For example, sys c: \ dos:
This command transfers the system files in the C: \ DOS folder to drive.

DATE: displays or sets the DATE.
Usage: DATE [DATE]

TIME: displays or sets the TIME.
Usage: TIME [TIME]

DOS also comes with some other commands, such as SORT and FIND.

@: Place this symbol before other commands in the batch file. The command itself is not displayed during running.
For example, the @ echo off command is often used at the beginning of a batch of files.

CALL: CALL another batch file from one batch file. After the CALL, continue to execute the original batch file.
Usage: CALL [batch file name]
Note: You can also use the COMMAND/c command to perform the same operation.

CHOICE: select a command. This is a DOS external command, but it is mainly used in batch files.
After the CHOICE command is executed, a prompt is displayed for the project to be selected. Select the project by pressing a key.
Usage: CHOICE: [/C [:] key table] [/N] [/S] [/T [:] Select a value, in seconds] [display text]
/C indicates an optional button,/N indicates that the prompt information is not displayed, And/S indicates the case-sensitive mode, /T indicates that if no selection is made within the batch time, a selection value defined in/C is automatically executed. The displayed text is the prompt information when the CHOICE command is executed. The selection result is represented by the ERRORLEVEL value.

ECHO: displays the specified information. Usually displayed on the screen.
For example, ECHO Hello will display the word "Hello" on the screen.
In addition, echo on | OFF is used to set whether to display the command itself when executing a batch file. Echo off means the same as @, but it is a separate command and cannot be placed before other commands like.

FOR: run the corresponding command FOR the specified file.
As you know, many DOS commands support wildcards, such? And *. You can specify a batch of files at a time, which is very convenient. However, not all DOS commands support wildcards, such as TYPE (file content display command. With the FOR command, it does not matter, so that the TYPE command can display multiple files at a time.
Usage: FOR % variable name IN (file set) DO command [command parameter]
Note: The above is a fixed form of the FOR command. The IN and DO locations must be correct; otherwise, a syntax error will be prompted.
FOR example, you can run the FOR % f in (*. *) do type % F command to display multiple files at a time.
Note: % F is the variable name and can also be replaced by % G, but must be consistent before and after. Replace % F with % F in the batch file.

GOTO: Go to a label inside the batch file for execution.
As you know, in programming, it is often necessary to repeat or jump to a certain place to continue to execute, such as The GOTO command in BASIC language. The GOTO command in the batch file can also perform similar functions.
Usage: GOTO [label name]
The label names can be set at will, such as Hello. Set the label with the ":" symbol, such as ": Hello". Then, use the GOTO Hello command to go to the location where ": Hello" to continue executing the batch file.

IF: Conditional judgment command. This is a very useful Batch Processing Command.
Usage 1: IF [NOT] EXIST file name command [command parameter]
Meaning: If [No] A file exists, a command is executed.
Usage 2: IF [NOT] ERRORLEVEL error return code Command [command parameter]
Meaning: If the return code [No] is greater than or equal to the specified code, a command is executed.
ERRORLEVEL indicates the return code of the error, which is useful. For many DOS commands, different codes are returned to indicate different results due to different execution results (such as successful execution, failed execution, or interrupted by users. The if errorlevel command runs different commands based on different codes generated by different results. It is usually used after a command. For example, if errorlevel 1 echo OK! If the return code of the current error is greater than or equal to 1, "OK!" is displayed on the screen !" .
Usage 3: IF [NOT] string 1 = string 2 Command [command parameter]
Meaning: execute a command when string 1 and string 2 [do not] are equal.

PAUSE: PAUSE the execution of batch files and display the words "press any key to continue.

REM: Add annotation. It is used to increase file readability and will not be executed. It can also be replaced.

SHIFT: Change the positions of replaceable parameters in a batch file.
Replaceable parameters are special parameters and can only be used in batch files. These parameters are input by the user when executing the batch processing command. For example, run the DIR/S/W command, where DIR is the command name, And/S and/W are the execution parameters. In the batch file, these command parameters are assigned to replaceable parameters, for example, % 1 in/S, % 2 in/W, and so on, the command itself is granted to % 0. A batch file uses replaceable parameters to operate on the Parameters entered during execution. For example, a batch file is called MYFILE. BAT: Execute MYFILE in the command line. bat yes, so the value of % 0 is MYFILE. BAT, the value of % 1 is "YES". In this batch of files, you can use commands such as IF to determine the value of parameters such as % 1, and then perform different operations based on these values, for example, IF "% 1" = "YES" goto yes.
The SHIFT command does not contain any parameters. The execution result is to replace the value of % 0 with the value of the original % 1, and the value of the original % 1 is the value of the original % 2, and so on. Pay attention to its irreversible nature. Because there may be many running parameters in the execution of batch files, there may be more than 10, and the replaceable parameters can only be changed from % 0 to % 9. To obtain the parameter values after % 9, only the SHIFT command can be used. The entire parameter column is pushed forward.

The above are the built-in batch processing commands of DOS. We can see that these commands are very few. To write more complex programs, it is obviously impossible to use the above commands. In this case, we need other practical batch processing tools, including TESTIF, STRING, ASET, BATCHMAN, and WBAT. The above tools can be used in batch files to implement very powerful functions, and can even complete the functions of many advanced language programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.