What can you do with the command line? All Windows command line commands in one place

If your computer has the Windows operating system installed, then you can manage your system through the command line.

This is an indispensable tool that every experienced PC user uses. Thanks to the command line, you can even solve complex problems that you never thought of before.

Command line functions are a huge list of different commands that you don’t have to learn at all. In this article, we will introduce you to basic commands that may come in handy while using your computer.

We will also tell you how to launch the command line with a clear example on Windows 7.

How to use the command line?

To run this tool, you can go to Start, select the “Run” function:

After that, enter cmd in it:

That's it, the command line opens, where you can start entering various functions:

Now let's look at what commands you can enter in this window:

  • calс – to launch the calculator.
  • chkdsk is a function that checks disks for errors, to which you can add /f to automatically correct errors. Example: chkdsk e: /f.
  • convert - if you need to change the file system on some storage medium without formatting it, use this function. Example: convert F: /fs:ntfs(fat32).
  • compmgmt – required to open the computer management folder, through which you can access device manager, scheduler, disk management, and so on.
  • control – to launch the control panel.
  • control admintools – to launch the Administration tool.
  • diskpart – to obtain data about the properties of a partition.
  • explorer – if icons on the desktop are no longer displayed, enter this function, it will launch Explorer.
  • fsmgmt – to launch the folder control panel.
  • format – to completely format the computer.
  • iexplore – to launch the Internet Explorer browser
  • ipconfig – for IP protocol settings.
  • msconfig – to display many of your system settings.
  • mstsc – for connecting to remote desktops.
  • netstat – to scan active connections.
  • notepad – to launch notepad.
  • osk – to launch the virtual keyboard.
  • ping – to check network response time. You can check the access of any site.
  • powercfg – for power management and energy saving.
  • regedit – to launch the registry editor.
  • sfc – to check system files. To recover damaged files, use the sfc /scannow add-on. Useful for troubleshooting virus problems.
  • shutdown – to restart the computer, use shutdown /r , you can also shut down the system using the shutdown /s add-on.

When it is not possible to use the standard interface, the command line can help out. And if a virus has infected your system and you cannot open Start, press the Win+R key combination to open the Run program from which you can open the command line.

I recently grew from a fierce nerd in a very large company to a modest system administrator overseeing a network of 10 PCs. And, like a very lazy system administrator, I was faced with the task of automating my activities. Six months ago, I didn’t yet know that there were pipelines in the Windows command line. This was the first shocking discovery. And I went further, and it turned out that where I had previously written utilities in C#, Delphi or cumbersome scripts with nested loops, I could get by with a couple of forfiles or robocopy commands.
I won’t talk about banalities, such as listing files and folders using the Tab key. Under the hack I’ll tell you about what can be useful for novice admins and enikeys.

Hotkeys
Let's start with hotkeys, because first we need to explore what the work environment can give us.

F1- In the console, this key works exactly like the right arrow, i.e. displays one character at a time from the last command entered (or selected in the history).
F2+<символ> - Prints the last command entered up to the specified character. For example, if the last command you entered looked like this:
ping 192.168.25.1
then after pressing the key combination F2+5 You'll get:
ping 192.168.2
F3- Displays the last, and only the last, command in its entirety.
F5- Displays the last commands entered in order, just like the up arrow.
F6- Inserts the EOF character at the current command line position, which is the same as pressing Ctrl + Z.
F7- A dialog box containing the command history.

Alt+F7- Clears command history.
<символ(ы)>+ F8- Iterates through commands that begin with characters already entered into the command line.
If before pressing F8 do not enter anything, then this key will work like the up arrow, but with a slight difference - the lines will be cycled through, i.e. after the first command from the list the last one will be displayed.
F9+<число> - Inserts a command from history under the corresponding number. For example, in the situation shown in the screenshot above, when you press the combination F9+4 the following will appear in the console:
ipconfig

Command Line Operators
A long time ago, when I was little, I couldn’t even imagine how you could 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 page-by-page output will not save you. But one day I installed FreeBSD on my old computer, opened the handbook and was simply dizzy with the possibilities that opened up. There you can redirect the output of a command to the input of another command and this is called a pipeline.

The pipeline operator in *nix and cmd is the vertical bar character.
For example, the command will display all text files in the current folder
dir | find ".txt"

Command concatenation operator
&
Example: Command1 & Command2 – Command1 will be executed first, and only then Command2
Operator AND
&&
Example: Command1 && Command2 - Command2 will only be executed if Command1 succeeded
OR operator
||
Example: Command1 || Command2 - Command2 will only be executed if Command1 failed to execute.

Parentheses are used to group commands, examples:

  • (Command1 & Command2) && Command3 – If Command1 and Command2 are executed successfully, Command3 will be executed.
  • (Team1 & Team2) || Command3 - If Command1 and Command2 are not executed, Command3 will be executed.

Thank you for your attention! I'm waiting for criticism and suggestions...

UPD1
For those who are not in the know, circumflex (that “^” sign) means pressing the Ctrl key (^C = Ctrl +C).

^C - Interrupts the command, well, everyone knows that.
^S - Pauses the command and then runs it.
^I - Analogous to Tab, iterates through folders and files.
^M - Analogous to Enter.
^H - Analogous to Backspace.
^G - By writing the command echo ^G in a batch file, you can beep the system speaker (speaker).
(The commands ^I and ^H were obtained by me using the “scientific poke” method; there is also ^J but I don’t know what it does)

P.S. Other subtleties of the Windows command line have already been repeatedly covered on Habré. And I don’t see the point in copy-pasting.
P.P.S. Links to interesting posts and articles on other Windows command line features.

So, the command line console is present in all versions of Windows operating systems. Early versions of the OS supported MS-DOS mode directly, which made it possible to execute simple commands directly from the console. Representatives of the NT family, such as Windows 2000 or Windows Server 2003, work on completely different principles, however, MS-DOS is also supported in them, but through a virtual machine (NT Virtual DOS Machine, NTVDM), which allows you to control and administer system resources directly from the command mode console. The command mode interpreter is the cmd.exe program, which is launched through the “Start -> Run” menu. In addition, to launch the console, you can use the menu item “Start -> All Programs -> Accessories -> Command Prompt”.

By launching a command-mode console, the user can manage resources of both the local system and the resources of a remote machine. There are commands that monitor the system and identify critical points in the server settings. The difference between working from the command line is the complete absence of large and cumbersome graphical utilities. Command line programs allow finer tuning in the form of key parameters listed to the right of the command itself.

Using special script files (sets of commands executed sequentially or in a programmed order), the administrator can minimize routine daily operations. Existing modern utilities can run such scripts at specified intervals without the presence of a system administrator.

The administrator himself can execute both single commands and a list of commands using special control characters (&, |). For example:

Command 1 & Command 2 - Command 1 will be executed first and only then Command 2; Command 1 && Command 2 - only after successful completion of Command 1 will Command 2 be launched.

It is possible to redirect the stream output by the program directly to a text file for further processing. To do this, you must use the control character “>” and the name of the text file. An example of outputting the contents of the current directory to the text file Report.txt using the dir command is given below:

Dir>Report.txt

An administrator can launch multiple copies of the console by calling cmd.exe from the command line. Using a nested console allows you to work with operating system environment variables without any consequences for the entire system as a whole, since changes to environment variables are not saved after closing the nested console. The setlocal, endlocal, and set commands are used to control this process.

There are many commands and utilities in modern operating systems. Remember so many different programs, and even more so their parameters
very difficult, so one of the most important parameters for each program is the combination of symbols /?. After executing a command with this parameter, the user will receive a comprehensive message about the use of the utility and the syntax of its parameters.

Note that the illustration in the upper left corner of the next page uses complex syntax. So, immediately after the shutdown /? after the special separator “|” the more command is used, which allows you to display information on the screen not entirely, but in certain portions, convenient for further reading.

To close the command line console, you must run the exit command.

Who's in charge here?

According to their capabilities, console programs are divided into:

  • operating system control commands are commands such as shutdown or taskkill;
  • network commands - net and ipconfig;
  • commands for system monitoring - tasklist and systeminfo;
  • commands for file system support - dir, mkdir, copy;
  • commands for maintaining hard drives - defrag and diskpart;
  • commands to support Active Directories - addrep and dsadd;
  • auxiliary commands, this section includes various utilities for creating scripts, setting up printers, working with environment variables, etc.

Let's look at typical representatives of each group and allow ourselves to give some recommendations for using the commands included in them.

Monitoring and diagnostic commands

Monitoring commands such as systeminfo and tasklist are used to identify hardware and software problems. These utilities were first introduced in the Windows Server 2003 operating environment, so administrators have not yet fully appreciated the functionality of these commands. So, for example, now you don’t need to go to the “Properties” tab of the “My Computer” icon - the systeminfo command will print basic information about all system components with a full decryption on the console screen. The /s parameter will display information about any remote computer. For example, to find out the configuration of the TESTSERVER computer, you would run the following command:

Systeminfo /s TESTSERVER

And the tasklist utility will show the processes running on your computer.

The tasklist utility allows you to query systems connected to a network. The /v parameter allows you to get detailed listings with useful information, including usernames, and the /t parameter shows the processes that loaded a specific dll file. Another useful utility - openfiles - allows you to obtain information about all open files of the local and remote operating system. In previous versions of Windows operating systems, you had to use the oh.exe command; in modern versions, it is enough to run a command in the console command line that sets the monitoring mode for all open files in the system:

Openfiles/local on

The user will receive information about all open files on the system using a command with a simple syntax:

Openfiles

The openfiles command with the /query /v options shows which users are running the processes that opened the files. Using other key parameters, you can set different information output modes.

Operating system commands

Windows Server 2003 provides administrators with new commands that help them not only diagnose the system, but also manage it. Such commands include the shutdown utility. The following can be used as key parameters for this utility:

  • /s - complete normal system shutdown;
  • /p - power off;
  • /f - shutdown active applications;
  • /d - transition to low power consumption mode;
  • /I - end the session without turning off the computer.

In the form of a tool that registers all regular shutdowns of the computer, the shutdown event handler (Shutdown Event Tracker) acts as a tool that collects and diagnoses all shutdowns performed by the administrator. It is also possible to shut down the system indicating the reason; for this you need to use the /d key.

The taskkill command, analogous to the kill command in operating systems of the *nix family, allows you to “kill” a frozen application. Together with the tasklist command, these utilities provide a powerful tool for quickly intervening in the execution of applications that pose a potential threat to server performance. Among the parameters of this command, you should note the /pid key, which allows you to terminate a process by its unique identifier, and the /im key - to terminate the application with the specified name. The following example terminates processes with IDs 1000 and 1240:

Taskkill /pid 1000 /pid 1240

Commands for Hard Drive Maintenance

The defrag command allows you to optimize your hard drive. The utility can defragment disks with the FAT, FAT32 and NTFS file systems. Defrag works equally well with both dynamic and basic disk types. The syntax for calling this command is as follows:

Defrag disk [ -a j [ -f ] [ -v ] [ -? ]

The -a parameter provides only analysis of information on the disk, the -f parameter - optimization of information, including in the absence of the necessary disk space to create temporary files, and the -v parameter - outputs a report on the optimization progress. Don't forget that for defragmentation to succeed, the disk must contain at least 15% free space.

The fdisk command is no longer supported by the kernel of the Windows Server 2003 operating system. It has been replaced by the diskpart command, also intended for servicing hard drives. Split a disk into partitions, create logical drives, delete them - these are just some of the tasks solved by this utility. Basically, the diskpart command is focused on working with special script files that describe hard drive maintenance procedures. This is what calling this command looks like for the script file Scriptl.txt:

Diskpart /s Scriptl.txt

Each line of such a file is an instruction for some operation. So, for example, gives a command to create a new partition with a certain size line

Create partition logical size=2048

Network commands

Among the network commands, I would like to highlight two utilities. The first is the ipconfig command, the second is netstat. System administrators use these commands not only to monitor the network, but also to protect against dangerous programs that try to take control of the system.

Using the ipconfig utility, the user can find out the network address of his computer, and by calling this command with the /all parameter, obtain complete information about the network configuration on the local computer. The /renew parameter allows you to change network settings without rebooting the entire system.

If you notice that something wrong is happening with your computer, then the netstat command will help in this case, which will not only indicate open network ports through which attackers could connect to your system, but also identify processes running on the server without your knowledgeable Thus, the /o switch displays information about the process identifier (PID) using a particular network connection. It is possible to see which computers on the network are communicating with your local operating system.

Commands for Directory Service Support

The entire network consists of components and is a complex hierarchical structure built in the form of a tree. The objects of such a system are sites, subnets, servers, computers, groups, users, contacts, shared network devices.

To monitor such a complex structure, the operating system provides the dsquery command, which is designed for an advanced search of directory service components. This command can also be used to display information about the properties of selected components (the -attr switch). The -scope, -subtree, -onelevel, -base parameters determine the search nesting level, and the -filter key allows you to enable the search filter.

The dsmod command can help if you need to modify one or more accounts for a selected directory service component. For example, you can remove a user from a group or assign a new password to them. An example of changing the account for the TestUser user is shown below:

Dsmod user "CN=TestUser,CN=Users,DC=bigtex,DC=net " -pwd Uf@tfmgerelt -mustchpwd yes

The dsmove command moves an object within the current domain. Using the -newname and -newparent keys, you can set a new object name and change its location.

File System Support Commands

A description of some frequently used commands for working with files and directories is presented in the table. The deltree command, which performed cascade deletion of folders and files in them, is now replaced by rmdir with the /s switch.

Little secrets of a big system

Changing the command line prompt

Find the key in the registry: Create a string parameter “PROMPT” with type (REG_EXPAND_SZ) in this key and assign one of the following values:

  • $B - vertical bar “I”;
  • $D - current date;
  • $G - greater sign ">";
  • $1_ - less sign "<»;
  • $N - current disk;
    $P - current drive and path;
  • $Q - = "=";
  • $T - current time;
  • $V - Windows version;
  • $$ - dollar sign "$".

After the reboot, you will see the invitation in the form you defined.

Automatic commands

To enable the ability to auto-type commands by pressing the “Tab” key, find the key in the registry:

Then set the CompletionChar value to 9, which is the ID of the Tab key, close the registry, and restart your computer. In a console window, while typing part of a command name, you can now press the Tab key and Windows will automatically substitute the required command.

Changing console color

Find the key in the registry:

Change the DefaultCoior parameter. The -F0 value will output black text on a white background, and the IE value will surprise you with a yellow and blue console color.

Quickly launch the command line console from the context menu

Find the key in the registry:

Add subsections “CommandPrompt -> Command” to it. Set the Default parameter of the Command key to the value “cmd.exe /k cd “%1″”.

Set the Default parameter of the Command Prompt key to “Open Command Prompt”.

By right-clicking on any folder in Explorer, you can select the Open Command Prompt command, which will launch a command line console in the desired directory.

Conclusion

OK it's all over Now. We talked about the basics of working with the console. Next, we give you the opportunity to explore the functionality and variety of console commands yourself. Just don’t forget the treasured key /?, and the rest will come with time and experience

So what is it command line? This is a component of Windows with which you can enter various computer commands. As a rule, only experienced users use the command line, but this is not a reason to remain silent about it, so I decided to devote this post to the capabilities and properties of the command line.

Why do you need the command line?

You may ask, why know about the command line capabilities if there is a Windows graphical interface? But now I will list the reasons why you should use the command line:

Memory consumption is less than when using a menu system;

Typing a command in any application is faster than using a graphical command interface;

The command line can execute a text file with all the commands sequentially, which is much faster than executing them sequentially.

Where is the command line used?

You can use the command line in operating systems, computer games and other programs. As a matter of fact, the command line was originally used in games if debugging was needed. But even now, even with a graphical interface, using the command line you can change the game settings faster.

What are the advantages of the command line?

Almost instantaneous access to commands for various files used;

To call any command, a small number of clicks is enough;

You can control programs that do not have a graphical interface;

You can remotely connect to a computer using minimal traffic;

There is more text on the page than in the graphical interface.

Are there any disadvantages to the command line?

Difficult to understand by users who are used to working with a graphical interface;

If there is no automatic addition, it will be difficult to enter long commands;

It has no analogues.

How to open the command line?

1. To open the command line in Windows7/XP, do the following:
Start => All Programs => Accessories => Command Prompt .

or press the keyboard shortcut "Win + R".

in field "Open" enter this command:

A black command prompt window will open with the following message:

C:\Users\Administrator>, where Administrator is the name of the current user.

To see a list of command line commands, type help

and press ENTER.

To see more information about each of these commands, enter the following command at the command prompt
help command_name and press ENTER.

For example:

List of command line commands:

ASSOC→ Display or change associations based on file name extensions.

ATTRIB→ Display and change file attributes.

BREAK→ Turn on and off the processing mode of the key combination CTRL+C.

BCDEDIT→ Sets properties in the boot database to control the initial boot.

CACLS→ Display and edit access control lists (ACLs) for files.

CALL→ Call one batch file from another.

CD

CHCP→ Display or set the active code page.

CHDIR→ Display the name or change the current folder.

CHKDSK→ Checking the disk and displaying statistics.

CHKNTFS→ Show or change whether disk check is performed during boot.

CLS→ Cleaning the screen.

CMD→ Launch another Windows command line interpreter.

COLOR→ Set the default foreground and background colors.

COMP→ Compare the contents of two files or two sets of files.

COMPACT→ Display and change file compression on NTFS partitions.

CONVERT→ Convert FAT disk volumes to NTFS. The currently active drive cannot be converted.

COPY→ Copy one or more files to another location.

DATE→ Display or set the current date.

DEL

DIR→ List files and subfolders from a specified folder.

DISKCOMP→ Compare the contents of two floppy disks.

DISKCOPY→ Copying the contents of one floppy disk to another.

DISKPART→ Display and configure disk partition properties.

DOSKEY→ Editing and re-calling command lines; creating macros.

DRIVERQUERY→ Displays the current status and properties of the device driver.

ECHO→ Display messages and switch the mode of displaying commands on the screen.

ENDLOCAL→ End of local environment changes for batch file.

ERASE→ Delete one or more files.

EXIT→ Exit the CMD.EXE program (command line interpreter).

F.C.→ Compare two files or two sets of files and display the differences between them.

FIND→ Search for a text string in one or more files.

FINDSTR→ Search for strings in files.

FOR→ Run the specified command for each of the files in the set.

FORMAT→ Formatting the disk to work with Windows.

FSUTIL→ Display and configure file system properties.

FTYPE→ Display or change the file types used when matching by file name extensions.

GOTO→ Transfer control to the marked line of the batch file.

GPRESULT→ Display Group Policy information for a computer or user.

GRAFTABL→ Allows Windows to display extended characters in graphics mode.

HELP→ Displays help information about Windows commands.

ICACLS→ Display, modify, archive, or restore ACLs for files and directories.

IF→ Operator for conditional execution of commands in a batch file.

LABEL→ Create, change and delete volume labels for disks.

M.D.→ Create a folder.

MKDIR→ Create a folder.

MKLINK→ Creating symbolic and hard links

MODE→ Configuring system devices.

MORE→ Sequential output of data in parts the size of one screen.

MOVE→ Move one or more files from one folder to another.

OPENFILES→ Display files opened on a shared folder by a remote user.

PATH→ Displays or sets the search path for executable files.

PAUSE→ Pauses the execution of the batch file and displays a message.

POPD→ Restores the previous active folder value saved using the PUSHD command.

PRINT→ Prints the contents of a text file.

PROMPT→ Changes the Windows command prompt.

PUSHD→ Saves the active folder value and moves to another folder.

R.D.→ Deletes a folder.

RECOVER→ Recovers readable data from a bad or damaged drive.

R.E.M.→ Places comments in batch files and the CONFIG.SYS file.

REN

RENAME→ Renames files or folders.

REPLACE→ Replaces files.

RMDIR→ Delete a folder.

ROBOCOPY→ Improved tool for copying files and directory trees

SET→ Shows, sets and removes Windows environment variables.

SETLOCAL→ Starts localizing environment changes into a batch file.

S.C.→ Displays and configures services (background processes).

SCHTASKS→ Executes commands and runs programs according to a schedule.

SHIFT→ Changing the position (shift) of substituted parameters for a batch file.

SHUTDOWN→ Local or remote shutdown of the computer.

SORT→ Sorting input.

START→ Execute a program or command in a separate window.

SUBST→ Assigns a drive name to the specified path.

SYSTEMINFO→ Display information about the system and computer configuration.

TASKLIST→ Displays all running tasks, including services.

TASKKILL→ Termination or stop of a process or application.

TIME → Displaying and setting the system time.

TITLE→ Assign a window title for the current session of the CMD.EXE command line interpreter.

TREE→ Graphical display of the directory structure of a disk or folder.

TYPE→ Displays the contents of text files.

VER→ Displays information about the Windows version.

VERIFY→ Setting the mode for checking whether files are written correctly to the disk.

VOL→ Displays the volume label and serial number for the disk.

XCOPY→ Copying files and directory trees.

WMIC→ Display WMI information in an interactive environment.

The command line, also known as the console, came to us from MS-DOS. It allows you to control the operating system (OS) by entering commands in text form.

Most users do not know or know very little about the Command Prompt, while experts often ask to open it for remote technical support. Knowing the basics of working with the command line will also be useful for independently fixing computer problems.

There are at least three ways to launch the command line in the Windows operating system. One of the fastest is to simultaneously press the Windows key (with the Windows icon) and R on the keyboard. This will open the Run menu. Just enter cmd and click OK. Please note that the command prompt will open with local user rights. If you need to open a command prompt with administrator rights, then use another method.

The second way is to open the search bar and enter cmd or “command prompt” into it, launch the command prompt by clicking on it with the mouse. If you want to run Command Prompt as an administrator, right-click on it and select "Run as administrator." This method will work if you have Windows 7 and later. For users of earlier versions of Windows, to run Command Prompt with administrator rights, you need to find it in Standard Programs, right-click Command Prompt, and select Run as Administrator.


Teams

For the command line, there is a set of valid commands that must be entered using the correct syntax. To view a list of valid commands, type help and press Enter.

Let's look at the commands that may be useful when setting up anonymization tools.

ping

This command allows you to determine the presence of a connection with a remote computer, as well as the data transfer rate and the percentage of losses.

The remote computer that we will ping (we will determine the connection parameters with it) can be specified by name (for example, yandex.ru) or ip (for example, 77.88.55.60)
ping yandex.ru
ping 77.88.55.60


tracert

This command is used to determine which servers are in the network path to a specified resource and the response time of each of them. For example, to determine the path to yandex.ru, enter tracert yandex.ru on the command line.


ipconfig /all

The command is intended to display details of the current connection and manage DHCP and DNS client services, and allows you to determine configuration values.


route

The command provides access to the contents of the IP routing table. To view functions, enter the command without parameters: route

To display on screen: route print

To add a route to a destination: route add

For example, the default route with the default gateway address 192.168.12.1: route add 0.0.0.0 mask 0.0.0.0 192.168.12.1

To add a permanent route, you need to add the -p parameter after route, for example: route -p add 10.41.0.0 mask 255.255.0.0 10.27.0.1


Bottom line

Now you know that the command line is not difficult at all. It allows you to access more information. Knowing just a few commands, you can answer almost any question from a technical support employee or apply recommendations from the instructions yourself. Share useful information with your loved ones.