DOS self-brought batch command _dos/bat

Source: Internet
Author: User
Tags goto
The filename is combined with the file path and file name, such as C:\DOS\COMMAND.COM.

DIR Displays files and folders (directories).
Usage: DIR [filename] [options]

It has many options, such as A/A, that shows all files (that is, files that include hidden and system attributes),/s indicates that files from subfolders are also displayed,/p indicates a split-screen display,/b indicates only the file name, and so on.
such as DIR *. EXE/A/P
This command displays all files (clips) under the current folder with a suffix of a beginning with a.

The CD or chdir changes the current folder.
Usage: CD [folder name]
Displays the current path if no folder name is present.

The MD or mkdir establishes the folder.
Usage: MD folder name

Rd or RmDir deletes the folder.
Usage: RD folder name
Note: This folder must be empty.

Del or erase delete the file.
Usage: Del/erase file name

Copy copy files.
Usage: COPY filename 1 [filename 2] [options]
such as copy/b a+b C
This command will combine two binary files A and b into one file C.

TYPE Displays the contents of the file.
Usage: TYPE file name

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

Edit edits files, and you can edit binaries and multiple files in MS-DOS 7.x.
Usage: EDIT [filename] [options]
such as EDIT/70 C:\COMMAND.COM
This command edits the C:\COMMAND in binary mode. COM files.

Format the disk.
Usage: FORMAT Drive [Options]

It has many options, such as/q is a quick format,/u denotes an unconditional format (that is, you cannot recover with commands such as Unformat),/v Specifies the disk's label name, and so on. It also has many non-public parameters.

MEM shows memory status.
Usage: MEM [options]

It also has a number of options, such as/C to list the memory footprint of all programs,/d is the display of memory-resident programs and the status of the device driver details,/F shows the total amount of free memory,/m shows the module information in memory,/p is the split-screen display. There is also a hidden/a option to display HMA information.

Move moves the file or folder, and you can change the name of the file or folder.
Usage: Move file [folder] 1 files [clip]2
such as Move c:\*. EXE D:
This command moves all files in the C-root folder that have the extension EXE to the D disk.

XCOPY copies a file or folder.
Usage: XCOPY file [folder] name 1 [file [folder] Name 2] [options]

It has a lot of options, such as/s to copy files in the entire folder (including subfolders),/e Specifies to include an empty folder,/V indicates the correctness of the copied files after the copy is completed,/y confirms, and so on.

The CLS clears the screen.
Usage: CLS

SYS conduction system, which transmits the system files (such as Io.sys, etc.) from one place to the specified drive.
Usage: SYS folder name [drive]
such as SYS C:\DOS A:
This command transfers the system files located under the C:\DOS folder to disk A.

Date Displays or sets the dates.
Usage: date [Date]

Time is displayed or set.
Usage: times [TIME]

DOS also takes some other commands, such as sort (sort), find (looking for characters), and so on.




@: Put this symbol in front of the other commands in the batch file, the runtime will not display the command itself.
If the @echo off command is often used in the first batch of files.

Call: Invokes another batch file from one batch file, and continues executing the original batch file after the call is completed.
Usage: call [batch filename]
Note: You can also use the COMMAND/C command to complete the same operation.

CHOICE: Select command. This is a DOS external command, but it is mainly used in batch files.
When the choice command is executed, it prompts for a selectable item, which is selected by a key.
Usage: choice:[/c[:] key sheet] [/n] [/S] [/t[:] Select value, seconds] [show text]
Where the/C indicates an optional key,/n means not to display the prompt,/s for uppercase and lowercase character sensitivity,/t means that a selected value defined in/C is automatically executed if there is no selection within the time of the approval. The display text is the prompt message when the choice command executes. The selection results are represented by ERRORLEVEL values.

ECHO: Displays the specified information. Usually appears on the screen.
such as echo hello will display the word hello on the screen.
In addition, ECHO on| Off is used to set whether the command itself is displayed when a batch file is executed. echo off is the same as @, but it is a separate command and cannot be placed before other commands like @.

For: Runs the appropriate command for the specified file.
As you know, many commands in DOS support wildcard characters, such as? and *, you can specify a batch of files at a time, very convenient. However, not all DOS commands support wildcard characters, such as type (the file content Display command) is not supported. It's okay to have a for command, which makes it possible for the type command to display multiple files at once.
Usage: for% variable name in (file set) do command [command arguments]
Note: The above is a fixed form for the for command, the in and do positions must be correct, or a syntax error will be prompted.
such as the For%F in (*.*) do type%F command enables the type command to display multiple files at a time.
Note:%f is a variable name, can also be replaced with%g, but must be consistent. Replace with%%f in the batch file.

Goto: Go to a label within a batch file to execute.
As you know, in programming, you often need to repeat or jump to a place to continue, such as the Goto command in basic language. The goto command in the batch file can also perform similar functions.
Usage: GOTO [Label name]
Among them, the label name can be set arbitrarily, such as Hello. Set the label with the ":" Symbol, such as ": Hello", when the goto Hello command will go to ": Hello" where the batch file continues to execute.

IF: Conditional judgment command. This is a very useful batch command.
Usage 1:if [NOT] EXIST filename command [command parameters]
Meaning: If a file is not present it will execute a command.
Usage 2:if [NOT] ERRORLEVEL error return code command [command parameters]
Meaning: If the error returns a code [not] greater than or equal to the specified code name, a command is executed.
Among them, ERRORLEVEL represents the error return code, very useful. For many DOS commands, these commands return different code names to represent different results, depending on the results of the execution (such as execution success, execution failure, or interruption by the user). The IF ERRORLEVEL command performs different commands on different codes that are based on this different result, usually after a command. if errorlevel 1 ECHO ok! indicates that "ok!" is displayed on the screen if the current error returns a code greater than or equal to 1 o'clock The words.
Usage 3:if [NOT] string 1== string 2 command [command arguments]
Meaning: Executes a command when string 1 and string 2[are not equal.

PAUSE: Suspends execution of batch files and displays the words "Press any key to continue".

REM: adding annotations. Used to increase file readability and will not be executed. You can also use:: To replace.

Shift: Changes the position of replaceable parameters in the batch file.
A replaceable parameter is a special parameter that can only be used in a batch file. These parameters are entered by the consumer when the batch command is executed. For example, we execute the dir/s/w command, where dir is the command name,/S and/w are its execution parameters. In batch files, these command parameters are assigned to replaceable parameters, such as/s,%1,/w can be%2, and so on, and the command itself is assigned to%0. A batch file is an operation that uses replaceable parameters for the parameters entered at execution time. For example, there is a batch file called Myfile.bat, which executes Myfile.bat YES at the command line, and the value of%0 is the value of myfile.bat,%1 is "YES", which can be used to determine the values of parameters such as%1, in this batch of files. Then perform different operations based on the values, such as if "%1" = = "Yes" GOTO yes.
The shift command takes no arguments, and the result is that the value of%0 is replaced with the value of the original%1, and the value of the original%1 becomes the value of the original%2, and so on. Notice the irreversibility of it. Because a batch file may run with a lot of running parameters, possibly more than 10, and replaceable parameters can only be from%0 to%9, you can use the shift command only if you want to get the parameter values for%9. At this point, the entire parameter column is pushed forward.

The above is the DOS of the batch command, you can see that these commands are very few, to write more complex programs, the above command is obviously impossible to achieve. At this time, the need for other practical batch processing tools, well-known and practical, such as Testif,string,aset,batchman,wbat. Using the tools above in a batch file can be very powerful and can even accomplish the functions of many high-level 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.