DOS Command Introduction

Source: Internet
Author: User
Tags create directory goto

There are three executable files in DOS, respectively exe,com and bat (the current page supports the cmd extension). Among them, exe and COM file are binary form, only bat file is text form, can read directly. As a result, the bat file is much simpler than the binary executable file. These files contain a collection of DOS commands, usually called batch files.

Although the composition of batch files is relatively simple, but its use is very large, and more widely used. For example, every time you execute some of the same commands, you will be in a lot of trouble, but it's much easier to do it in a batch file. AUTOEXEC. BAT is a special batch file, which runs automatically when DOS is started, and plays a very important role in the configuration of the system. Therefore, to learn DOS, we must learn batch processing documents. The following describes the commands for batch files and their use.

DOS self-brought batch command:

@: 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 file name command [command arguments] 
Meaning: If a file is not present, a command is executed.  
Use 2:if [NOT] ERRORLEVEL error return code command [command parameter] 
Meaning: If the error returns a code [not] greater than or equal to the specified code name, a command is executed.  
where errorlevel indicates an error return code, it is 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.  
Use 3:if [not] string 1== string 2 command [command arguments] 
Meaning: Executes a command when string 1 is not equal to string 2[.  

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.

dos command

DOS
dos is executed by entering the English command plus the ENTER key, which DOS is called a single task operating system.

files that have a suffix of exe, COM, or bat can be executed directly. These exe-suffix files are called executable files, files with COM suffixes are called command files, and bat-suffix files are called batch files. If we want to execute these files, simply type the file base name at the prompt and then enter, without the need for a file suffix.

The so-called batch process, there are a few commands that can be executed, when we want the computer to complete a series of tasks, you can execute a single command, or you can load the commands into a file, just tap the file name, the computer will execute this batch of commands at once.
in DOS, there is a concept of the current directory, which is the directory displayed by the prompt, and now the prompt is C: The current directory is the root of the C disk, and this (backslash) represents the root directory.

When we enter an executable file name, DOS looks for the file in the current directory, and DOS prompts for the error message if there is no file.
to fully express a subdirectory should be a disk alphanumeric directory, such as c:dostemp, so complete the presentation of the file? is the disk alphanumeric directory plus filename, such as C:DOSTEMPME. Txt,c:dostemp is called ME. TXT path. Note: If there are spaces in the path, the entire path is surrounded by "path" double quotes.

Just now we said, when you enter an executable file name, DOS will look for the file in the current directory, if not found, will prompt the wrong file name, but we do not have to change the current directory to the directory where the file can run it, you can add the full path before the file name, For example, our current directory is C:dos, we want to run d:testpct. EXE, then we can enter d:testpct directly. EXE carriage return so that we can execute files in other directories without changing the current directory. The

DOS commands are divided into internal commands and external commands, and internal commands are loaded with Command.com, and the external command is a separate executable file.

Internal commands are concentrated in the Command.com file in the root directory, and each time the computer is startedThe file is read into memory, which means that when the computer is running, these internal commands reside in memory and the internal commands are not visible with Dir. The external commands are stored in a separate file on the disk, they are the COM and exe-suffix files, they are not resident memory, only when the computer needs, will be transferred into memory.

? What is the difference between wildcards and *? * Can replace more than one character in the filename, and? can only be substituted for a single character in the filename.
When using wildcards, a maximum of one * can be found in the file base name and extension, but not multiple if the file name and extension length are not exceeded.

1. # time #显示当前时间
2. #dir #查看当前目录下的文件和目录信息
# dir/p #翻页显示
3. #mem #查看当前系统的内存情况
4. #cd #改变当前目 Record the
CD.. # in DOS, this two o'clock represents the previous level of the current directory, a point representing the current directory
CD #就表示根目录.
5. #盘符: #更换当前目录到硬盘的其它分区
6. # MD (make directory--create directory)
7.# Rd (remove directory--Delete directory)
8. #exit #退出dos终端
9. #copy source file name destination file name #复制
#del file name #删除当前目录的某个文件
One. #ren source file name destination file name #改文件名
#type file name #查看文件里的内容
# Del *.* or Del. #删除当前目录中的所有文件
#format A: #格式化磁盘

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.