Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the dos commands?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "what are the dos commands". In the daily operation, I believe many people have doubts about the dos commands. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what are the dos commands?" Next, please follow the editor to study!

There are three types of executable files under DOS, EXE,COM and BAT (the current page supports the cmd extension). Among them, EXE and COM files are in binary form, and only BAT files are in text form and can be read directly. Therefore, the content of BAT files is much simpler than the above binary executable files. These files contain collections of DOS commands, often called batch files.

Although the composition of batch file is relatively simple, it is very useful and widely used. For example, you must find it troublesome to execute some of the same commands every time, but it's much easier to execute them in a batch file. AUTOEXEC.BAT is a special batch file, which runs automatically when DOS starts, and plays a very important role in the configuration of the system. Therefore, if you want to learn DOS well, you must learn batch files well. The commands for batch files and their use are described below.

Batch commands included with DOS:

@: put this symbol before other commands in the batch file, and the command itself will not be displayed at run time.

For example, the @ ECHO OFF command is often used at the beginning of the batch file.

CALL: invokes another batch file from one batch file, and continues to execute the original batch file after the call.

Usage: CALL [approval document name]

Note: you can also use the COMMAND / C command to do the same.

CHOICE: select the command. This is an external DOS command, but it is mainly used in batch files.

The optional items will be prompted after the CHOICE command is executed, and the option will be selected by pressing a key.

Usage: CHOICE: [/ C [:] keystroke table] [/ N] [/ S] [/ T [:] Select value, seconds] [display text]

Among them, / C represents the optional key, / N indicates that the prompt message is not displayed, / S indicates the case-sensitive mode, and / T indicates that a selection value defined in / C is automatically executed if there is no selection within the approved time. The display text is a prompt when the CHOICE command is executed. The selection result will be represented by the ERRORLEVELL value.

ECHO: displays the specified information. It is usually displayed on the screen.

For example, ECHO Hello will display the words Hello on the screen.

In addition, ECHO ON | OFF is used to set whether the command itself is displayed when the batch file is executed. ECHO OFF means 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 under DOS support wildcard characters, such as? And *, you can specify one batch of files at a time, which is very convenient. However, not all DOS commands support wildcards, such as TYPE (file content display command). It doesn't matter with the FOR command, which allows the TYPE command to display more than one file at a time.

Usage: FOR% variable name IN (fileset) DO command [command parameters]

Note: the above is the fixed form of the FOR command, the position of IN and DO must be correct, otherwise syntax errors will be prompted.

For example, the FOR% F IN (*. *) DO TYPE% F command can realize the TYPE command to display multiple files at a time.

Note:% F is a variable name, which can also be replaced by% G, etc., but it must be consistent. Replace with% F in the batch file.

GOTO: go to a label inside the batch file to execute.

As we all know, in programming, you often need to repeat or jump somewhere to continue execution, such as the GOTO command in the BASIC language. The GOTO command in the batch file can perform a similar function.

Usage: GOTO [label name]

Among them, the label name can be set at will, such as Hello, etc. Set the label with a ":" symbol, such as ": Hello", and use the GOTO Hello command to go to the location where ": Hello" is located to continue executing the batch file.

IF: conditional judgment command. This is a very useful batch command.

Use 1:IF [NOT] EXIST file name command [command parameters]

Meaning: if a file does not exist, a command will be executed.

Use 2:IF [NOT] ERRORLEVEL error to return code command [command parameters]

Meaning: if the error return code [not] is greater than or equal to the specified code, a command will be executed.

Where ERRORLEVEL represents an error return code, which is very useful. For many DOS commands, due to different results of execution (such as successful execution, failed execution, or interrupted by the user, etc.), these commands return different codes to represent different results. The IF ERRORLEVEL command executes different commands according to the different codes produced by this different result, usually after a command. Such as IF ERRORLEVEL 1 ECHO OK! Indicates that "OK!" will be displayed on the screen if the current error return code is greater than or equal to 1. The words.

Use 3:IF [NOT] string 1 "= string 2 command [command parameters]

Meaning: execute a command when string 1 and string 2 are [not] equal.

PAUSE: pauses the execution of the batch file and displays the words "press any key to continue".

REM: add comments. Used to increase the readability of files and will not be executed. You can also use:: instead.

Dos command

DOS

In DOS, the program is executed by entering English commands and enter keys. DOS is called a single-task operating system.

Any file with the suffix exe, com, or bat can be executed directly. These files with the suffix exe are called executable files; files with the suffix com are called command files; and files with the suffix bat are called batch files. If we want to execute these files, just type the basic name of the file at the prompt and enter the enter. There is no need to enter the file suffix.

The so-called batch processing means that many commands can be executed at once. When we want the computer to complete a series of tasks, we can execute them one by one, or we can load all these commands into a file. As long as we type 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 at the prompt. Now the prompt is C:\, so the current directory is the root directory of disk C, and this\ (backslash) represents the root directory.

When we enter the executable file name, DOS looks for the file in the current directory, and if it doesn't exist, DOS prompts an error message.

To fully express a subdirectory should be a drive letter plus a directory, such as C:\ DOS\ TEMP, what about the complete expression of the file? It means the drive letter plus the directory and the file name. For example, C:\ DOS\ TEMP\ ME.TXT,C:\ DOS\ TEMP\ is called the path of ME.TXT. Note: if there are spaces in the path, the entire path should be surrounded by "path" double quotes.

As we said just now, when entering an executable file name, DOS will look for the file in the current directory. If it cannot be found, it will prompt for the wrong file name. But we don't have to change the current directory to the same directory as the file to run it. We can add the full path before the file name. For example, our current directory is C:\ DOS, and we need to run D:\ TEST\ PCT.EXE. Then we can enter D:\ TEST\ PCT.EXE directly so that we can execute files in other directories without changing the current directory.

DOS commands are divided into internal commands and external commands, which are loaded into memory with command.com, while external commands are a separate executable file.

Internal commands are concentrated in the command.com file in the root directory, and the computer will read this file into memory every time it starts, that is to say, when the computer is running, these internal commands reside in memory, and these internal commands cannot be seen with dir. External commands are stored on disk as separate files, which are suffixed with com and exe. They are not resident in memory and are called into memory only when the computer needs them.

? What is the difference between wildcards and *? * can replace multiple characters in the file name, and? Can only replace one character in the file name.

When using wildcards, there can be at most one * in the file base name and one in the extension, and? Multiple can occur without exceeding the length of the file name and extension.

1. shows the current time

2. # dir # View the files and directory information in the current directory

# dir / p # turn the page and display

3. # mem # View the memory of the current system

4. # cd # change the current directory

Cd.. # in DOS, these two dots represent the directory above the current directory, and a dot represents the current directory

Cd\ #\ represents the root directory.

5. # drive letter: # replace other partitions from the current directory to the hard drive

6. # md (make directory-- create directory)

7.# rd (remove directory-- deletes a directory)

8.#exit # exit the dos terminal

9.#copy source file name destination file name # copy

10.#del filename # Delete a file in the current directory

11.#ren source file name destination file name # change file name

12.#type file name # View the contents of the file

# del *. * or del. # Delete all files in the current directory

13.#format A: # format disk

At this point, the study of "what are the dos commands" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report