Subtleties of work in the Windows command line

Recently I grew up from a fierce enikey in a very large company, to a modest system administrator supervising a network of 10 PCs. And, as a very lazy system administrator, he was faced with the tasks of automating his activities. Six months ago, I did not yet know that there are pipelines on the Windows command line. This was the first shocking discovery. And I went further, and it turned out that where I used to write utilities in C #, Delphi or bulky scripts with nested loops, I could do with a couple of commands forfiles or robocopy.
I will not talk about commonplace, such as listing files and folders with a key Tab. Under the habrakat, I’ll talk about what can be useful for beginning administrators and enikeys.


Let's start with the hot keys, because first you need to study what the working environment can give us.

F1 - In the console, this key works exactly like the right arrow, i.e. displays one character from the last entered (or selected in history) command.
F2 + <character> - Displays the last command entered before the specified character. For example, if the last command you entered looked like this:

then after pressing the key combination F2 + 5 you will get:
ping 192.168.2

F3 - Displays the last, and only the last, command in history.
F5 - Displays the last entered commands in order, as does the up arrow.
F6 - Inserts the EOF character at the current position of the command line, which is similar to pressing the combination Ctrl + Z.
F7 - Dialog box containing the history of commands.
Alt + F7 - Clears the history of teams.
<character (s)> + F8 - Iterates over commands that begin with characters already entered on the command line.
If you do not enter anything before pressing F8 , then this key will work like the up arrow, but with a slight difference - iterating over the lines will be performed cyclically, i.e. after the first command, the last one will be displayed from the list.
F9 + <number> - Inserts a command from the history under the corresponding number. For example, in the situation shown in the screenshot above, when you press the F9 + 4 combination, the following will appear in the console:

Command line operators

I, a long time ago, when I was little, did not even imagine how you can work in a console without a graphical interface. After all, the output of commands sometimes takes dozens of pages, and if you need to select some data from there, then paging will not save. But one day I put it on an old FreeBSD computer, opened a handbook, and my head just went round from the opportunities that had opened up. There you can redirect the output of the command to the input of another command and this is called a pipeline.

The pipeline operator in * nix and cmd, is a pipe character.

For example, the output of all text files in the current folder will be shown by the command
dir | find ".txt"

Team Aggregation Operator


Example: Team1 & Team2 - Team1 will be executed first, and then Team2

Operator AND


Example: Team1 && Team2 - Team2 will be executed only if the successful execution of Team1

Operator OR


Example: Command1 || Team2 - Team2 will be executed only if Team1 could not be executed.

Parentheses are used to group commands, examples:
  • (Team1 & Team2) && Team3 - If Teams1 and Teams2 are successful, the Team3 will execute.
  • (Team1 & Team2) || Team3 - If Teams1 and Teams2 are not executed, Team3 will execute.

Thanks for attention! Waiting for criticism and suggestions ...


For those who are not on the topic, circumflex (this “^” sign) means pressing c Ctrl(^C = Ctrl +C).

^C- Interrupts the team, well, everyone knows that.
^S- Pauses command execution, and then starts.
^I- Analog Tab, iterates over folders and files.
^M- Analogue Enter.
^H- Analog Backspace.
^G- Having written a command in a batch file, echo ^Gyou can pick it with a system speaker (speaker).
(The commands ^Iand ^H, received by me by the method of “scientific poking”, are still there ^Jbut I don’t know what she does)

PS Other subtleties of the Windows command line have already been repeatedly covered on Habré. And I don’t see the point of copy-paste.
PPS Links to interesting posts and articles on other features of the Windows command line:
Input-output, loops, variables
Working with arrays
Interesting topic topic

Also popular now: