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 commonly used commands in batch processing

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

Share

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

This article is about what commands are commonly used in batch processing. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Echo command (echo graphic version)

1. Echo: displays the status of the current ECHO: ECHO ON or ECHO OFF.

2. ECHO ON: ECHO status is set to ON, which displays the command line (such as C:\ > and other similar flags before each line).

3. The ECHO OFF:CHO status is set to OFF and the command line will not be displayed (such as C:\ > and other similar flags before each line).

4. ECHO string: displays the entered string on the CMD screen.

5. ECHO string & ECHO string... : &, similar to the meaning of and, logical operation, used to display multiple lines of data.

6. ECHO string > file path and file name: write the string to the file. If the data is already available, it will be cleared first and then written.

7. ECHO string > > File path and file name: write the string to the file, and append the data to the end if it already exists.

Note every time: ECHO string > > file path and file name. After the command, ECHO automatically adds a newline character after the string, so if you want to add it directly to the end of the file, then the existing data in the file cannot be previously entered by the ECHO command (or delete the newline character manually).

8. (ECHO string & ECHO string...) > File path and file name:

Write multiple lines of data to the file (note that parentheses cannot be removed, if parentheses are removed, only the last one can be written, and the previous one will be output in the CMD window. If there is already data in the file, it will be automatically emptied before writing.

9. (ECHO string & ECHO string...) > > path and file name

Write multiple lines of data to the file (note that parentheses cannot be removed, if parentheses are removed, only the last one can be written, and the previous one will be output in the CMD window. If there is already data in the file, the string is appended to the end of the file.

10. (ECHO string) > > File path and file name: add a string to another line in the file. As shown in the figure:

11. ECHO.: outputs a blank line, which is equivalent to entering an enter

Note that the "." on the command line should be immediately followed by ECHO with no spaces, otherwise "." will be output to the screen as a prompt. In addition, "." can be replaced with any symbol such as,:; +.

12. ECHO reply | Command file name: automatically answers the questions in the command without human input

13. ECHO ^ G: "^ G" is typed into the conjoined symbol with Ctrl+G. Entering more than one ^ G can produce multiple tones.

2. Pause command: this sentence will be paused.

The @ command: echo off is similar, but it is added to the front of the other command line, indicating that the command line itself is not displayed at run time.

4. Call command

Call calls another batch file (if another batch file is called directly, subsequent commands of the current file cannot be executed after that file is executed)

5. Rem command

Rem indicates that the character after this command is an interpretation line, which is not executed, but is only used for future search. :: can also play the role of rem annotation, and more concise and effective

VI.% command

% represents a parameter, which is a string added to the file name when running a batch file. Variables can range from% 0 to% 9jue% 0 to represent the file name itself, and strings are represented in the order from% 1 to% 9.

(1) Application of% 0:

Under the dos command line, enter: aa (on behalf of executing the aa.bat batch program), and% 0 represents its own file, which creates an endless cycle of constantly executing aa.bat commands.

(2) applications from% 1 to% 9

7. Control command

(1) if "parameter" = = "string" command to be executed

= = equal to; EQU equal to; NEQ not equal to; LSS less than

EQ less than or equal to; GTR greater than; GEQ greater than or equal to

(2) if exist file name command to be executed (eg: edit aa1.txt file)

(3) if errorlevel digital orders to be executed

If the return code is equal to the specified number, the condition holds, run the command, otherwise run the next sentence. For example, when the if errorlevel 2 goto x2 DOS program runs, it will return a number to DOS, which is called error code errorlevel or return code.

(4) OR [% f] in (collection) DO [command]

For% c in (* .bat * .txt) do type% c

VIII. Directory switching

(1) CD [drive letter] [path]: switch between the same partition

(2) CD / d [drive letter] [path]: switch between different partitions

(3)% cd%: displays the current full path

9. Change the directory to dir (check it for yourself)

10. Attrib command to set file properties

11. Common commands (abbreviated)

Del: deleting fil

Copy: copying fil

Xcopy: copying folder

Md: create folder

Rd: deleting a folder

Ren: renaming files (folders)

Move: moving files (folders)

Find: string lookup

Findstr: string lookup enhancement for pattern matching search

XII. Common network commands and symbols

Pipe commands take precedence over redirect commands, and redirect commands take precedence over combined commands: |, >, & &

(1) Redirector >, > >

The redirector, which means to pass and overwrite, serves to pass the result of the run to the following scope (which can be a file or the default system console, that is, the command prompt).

The redirector appends the output of the command to the device that follows it. The function of this symbol is similar to >, but there is a difference between them.

Pass and append to the end of the file, and > is overwritten. The usage is the same as >.

Echo hello > 1.txt

Echo world > > 1.txt

(2) Command pipe character |

Echo Y | rd / s c:\ abc, through the pipe command | pass the result of echo y to the rd / s c:\ abc command, thus achieving the purpose of automatically entering y.

(3) combine commands &, & &, | |

The symbol allows multiple commands to be executed at the same time, and when the first command fails, it does not affect the execution of subsequent commands. Here & the commands on both sides are executed sequentially, from the back.

The & & symbol allows multiple commands to be executed at the same time. Subsequent commands will not be executed when an error is encountered, and all commands will be executed all the time if there has been no error.

Subsequent commands will not be executed after the correct command, and all commands will be executed all the time if the correct command does not appear.

(4) escape character ^

To output special characters, you need to use echo ^ >, echo ^ |, echo ^ | ^ |, echo ^ ^. And other formats to deal with

(5) variable leader%

① variable references: when the percent sign appears in pairs and contains non-special characters, such as% var%,% str%

A reference to a parameter in the form of ②.% 0 represents the batch file itself, including the full path and extension;% 1 to% 9 represent the first through ninth parameters.

A ③ set / a statement that represents the number of two numbers divided by the remainder. In the command line window, only a single% is required, and in a batch file, two consecutive% signs are required, written as%%.

Set / a num=4%%2, get a num of 0 instead of 2

④ escape symbol: if you want to display% itself, you need to escape with% in front of it.

Echo a% sign:%

Echo two percent signs:%

Three percent signs of echo:%

(6) delimiter ""

① often uses "" to enclose a path when it represents a path with spaces or special symbols.

Example 1:cd / d cd "d:\ program files\ ^% * abc"

Because there are spaces and special symbols in the path, use "" to enclose the path.

② indicates that the content is a complete string.

Example 2:set "var=abc 123"

Echo var%

Thank you for reading! This is the end of this article on "what commands are commonly used in batch processing". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!

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