12 Useful Command Prompt Commands

Where we used to use the Command Prompt regularly, many users will also be able to do without it in Windows 10. Nevertheless, there are still very useful Command Prompt commands that you should definitely give a shot. They can come in very handy.

Windows (and many modern Linux distributions for that matter) owes its success mainly to the user-friendliness of the graphical interface (gui). Nevertheless, the so-called cli (command line interface) certainly has a right to exist. Some functions are difficult or impossible to find in the graphical interface. Command-line commands can usually also be precisely controlled with the help of parameters. Moreover, such commands can be easily included in batch files and can be run automatically from a user's logon script or via the task scheduler.

There are multiple ways to get to the Command Prompt. From task manager for example, or via the context menu (right mouse button on a file and Open in Command Prompt) or by pressing Start / Run (or press Windows key + R) and in the window that appears cmd enter followed by Enter.

Here you will find an overview of the available cmd commands in Windows (click on a command for corresponding parameters and examples). In this article, we first provide some examples that illustrate how powerful (and useful) such commands can be. Then we show you how you can use it in automation scenarios.

cmd window

When you go through the cmdcommand goes to the command prompt, you will by default end up in your own profile folder (c:\Users\). Now you can CDcommand (change directory) can navigate to a different folder, but you can also do it differently. Open File Explorer and navigate to the desired folder. Click on an empty spot in the right panel while holding down the Shift key and choose Open command window here: you will now immediately end up in the correct folder.

In Windows 10 it is finally also possible to copy a piece of text from the gui to the clipboard (with Ctrl+C) and paste it into a command line window (with Ctrl+V).

And for those who like to customize the appearance of this window: right click on the title bar, choose Characteristics and set all options to your liking in the tabs Options, Font style, Layout and Colors. By the way, it's not a bad idea to make the administrator's command window look different from that of other users.

01 Folder contents

To find out the contents of a folder, consult the Explorer. Logical, but from the command line you often get to know specific information faster. To get an idea of ​​the possibilities, run the command dir /? From. The parameter /? you can use almost all commands to get more explanation. To clear a window, use the cls command (clear screen). It is now a matter of cleverly combining the available parameters. Suppose you want an overview of all files, with the most recent at the top. Then you do that with dir /O-D.

Also notice, for example, the difference between dir *, dir /A * and dir /B *. Dir /A also shows you hidden (system) files and dir /B restricts the output to the file names with no further data.

By the way, you can print the folder contents by adding something like > folder contents.txt at the end of your command, after which you can open the txt file with Notepad and print it.

02 ADS

A fun experiment is adding ADS data (alternate data streams) to files, at least in an ntfs environment. Use Notepad to create a text file that you want to hide (we'll call it secret.txt). Then run the command type secret.txt > boring.txt:invisible.txt. This command causes the secret.txt file to be included as ADS data (named invisible.txt) in the boring.txt file. You may now delete secret.txt. When you run dir boring.txt, you notice that this file is empty (0 bytes). However, if you run dir /R boring.txt, the ADS data of boring.txt will still show up. You can see the contents of that ADS via the command "c:\system\32\notepad.exe" boring.txt:invisible.txt. This way you can hide files in other files.

03 Permissions Management

You can of course also control user permissions on folders and files from the gui, but that can be done faster from the cli. In addition, you have more options in Windows 10 Home via the cli. You control just about everything via the icacls command: in this you read 'acl', which stands for 'access control lists' or ntfs permissions.

To find out the current permissions on a folder or file, simply run the icacls command. You can also save all current permissions of all files in a certain folder and associated subfolders at once and quickly restore them after any experiments. You can save permissions as follows icacls \* /save aclfile /T. To quickly restore the permissions you saved in the aclfile file, run the command icacls /restore aclfile as administrator. To replace the permissions on a file with others, you can run a command like icacls /grant:r : F (F stands for Full access). Note that if you use the parameter :r (replace), then the new permissions are added to the existing ones instead of replacing them.

04 Connectivity

Even if you're barely familiar with the command prompt, you've probably run the command ipconfig or ipconfig /all before. And you probably won't be unfamiliar with the ping command either. For example, if you ping www.computertotaal.nl, you should receive a response from the web server with the corresponding IP address four times.

Much less known is the arp command (address resolution protocol). That allows you to connect to a host without knowing the MAC address of that device beforehand. Such an arp request is broadcast, which means that every device in the local network receives this request. If all goes well, the device with that IP address will respond by sending an arp-reply to the requesting party. Thus, an arp command can be useful to remotely learn the mac address but also to know if the device is active, even if it does not respond to ping requests. Feel free to do the test yourself (assuming you've set up device B's firewall to block ping echo requests). Now run the following commands as administrator:

arp -d * (empty current arp table)

arp -a (proof that the arp table has no entry for device B)

ping (no response: 4x timeouts)

arp -a (proof that device B with mac address has been added and is therefore active).

05 Symlinks

Many users are not familiar with so-called symbolic links (symlinks for short). Those are kind of advanced shortcuts to files or folders, where it appears that they are actually that file or folder instead of a shortcut. For example, it could be that some program requires data to be entered, but you'd rather see that happen.

You arrange that as follows. As administrator, go to the command prompt and run the following command: mklink /J (enclose the paths in double, straight quotes if they contain spaces). You will notice: all data that ends up in it automatically (also) ends up in it.

Related to this is the command mklink /D, which creates one or more links in a particular directory, each pointing to a different directory. All data from those folders can then be accessed at once by navigating to the folder with those link(s). This can be useful, for example, if you regularly have to access data for a project that is spread over various folders. You do this as follows from an (empty) folder: mklink /D financial , mklink /D logistics and so on.

Alternatives

The default console for the built-in command prompt in Windows is quite Spartan. There are free alternatives that offer more options and flexibility, such as ColorConsole, which supports tabs, export to HTML and RTF, quick folder switching from a taskbar, and so on.

You can also deploy a completely new command-line environment. For example, since Windows 7, Microsoft has increasingly focused on PowerShell. Although this true scripting environment is much more powerful than the traditional command prompt, it is also much more complex. You start this environment with the command power shell in a command window or run the PowerShell ISE (Integrated Scripting Environment) program if you need a graphical scripting environment.

Handy tool: Chocolatey

You can also automate the process of getting and installing software on your computer. By means of the tool Chocolatey you can download, install and update software with commands in the command prompt. At the time of writing, there are over 8,000 popular packs available for Chocolatey.

06 Shares

If you want a quick overview of all shared folders on your system, the command net share is sufficient. To get more information about the respective shares, run the net share command as administrator. You will then learn, among other things, the maximum number of users that may access this share at the same time, as well as the permissions on this share. Creating a new share is of course also possible. You do that with a command like net share fotos="c:\media files\my photos". If you want to remove the share again, net share photos /delete will take care of that. You can also link a shared network drive to a free drive letter, with net use x: \ (the computer name can be found, for example, via Windows key + Pause). If you want to make this link permanent so that it remains active during the next Windows session, add /persistent:yes at the end of the command.

07 Backups & Copies

You may perform standard copy operations via the Explorer. You can, but you are looking in vain for additional functions here. The command-line command robocopy offers much more advanced possibilities, as the parameter overview immediately makes clear to you. We limit ourselves here to a few simple examples.

With the command robocopy "c:\my documents" f:\ /MIR you make sure that the source folder (c:\my documents) is automatically mirrored to the destination folder (MIRrored). Note that unless you follow the command with the /XX parameter, pre-existing data in the destination folder will be deleted during this backup operation. Also useful to know: the /SEC parameter ensures that the original permissions are preserved in the target folder. And with /LOG: you keep a log of the operation.

Some robocopy commands can become quite complex due to the numerous parameters. Fortunately, there is an option to save those commands; it suffices to add /SAVE: at the end. To run the same command again afterwards, type robocopy /JOB:. Useful!

08 Batch

A big advantage of command-line commands is that you can easily include them in a batch file, so that those commands are usually executed chronologically one after the other as soon as you call the batch file (for example from the Windows task scheduler). You simply create such a file with Notepad and give it the extension .cmd.

For example, you could place a batch file on your desktop that contains the following command line: net use x: \ /persistent:no [/user: ]. This means that the network connection only becomes active as soon as you run this batch file with a mouse click, so that Windows does not lose time on startup by looking for, for example, a connection to an external drive that is no longer mounted.

09 Batch: Examples

In its simplest form, a batch file is therefore nothing but a chronological sequence of individual command-line commands. For example, something like this, where the source folder is emptied after the copy operation:

cls

xcopy c:\mydata d:\backups /M/E/H/R/I/Y

del c:\mydata\*.* /Q

But more complex constructions are also possible, as in the following example, in which you delete all files with specific extensions from your disk:

@echo off

rem This batch file erases specific files

title Selective file deletion

echo Clearing…

for %%t in (tmp bak log) do del c:\*.%%t /s

echo Files deleted!

pause

We do not have the space here to go into this in more detail. However, if you want to delve further into the possibilities and syntax of batch files: this ten-part course is a good starting point.

10 Login script

It is also possible to have a batch file (or other script) run automatically when a specific user logs on to Windows. This can be done in Windows Professional or higher by pressing Windows key + R and then the command lusrmgr.msc after which you click on the desired user and the tab Profile opens. Here you enter the name of the batch file. However, you can also control it from the command line, even in the Home versions of Windows. This is done via the command net user /scriptpath:. The condition is that you place this batch file in a shared folder with the share name 'netlogon', whereby you also ensure that that user is granted at least read rights on that folder.

11 Task Scheduler

Setting a batch file as a login script is one way to have it run automatically during login, but there's another way: using the built-in Task Scheduler. It's much more flexible, by the way, because you can also have a batch file (or any other script or program) run at startup, at a specific time, when you lock the system, and so on.

For example, we want to run a batch file every Friday afternoon that starts a disk cleanup with specific options. In this batch file we then (among other things) include the command cleanmgr /sagerun:1 (at least after we had previously run cleanmgr /sageset:1 once from the command line and set the desired options there).

12 Task Scheduler: Output

Click the magnifying glass icon in the Windows taskbar and search for task. Start Task Scheduler and click in the right panel on Create task (Create basic task can also, but gives you fewer options). Give your task a suitable name and, if desired, tick it Run regardless of whether user is logged in or not. Open the tab Triggers, Press on the button New and choose (for example) Scheduled at Start this task, after which you set the desired time and frequency (for example Every 1 Friday, om 16:00). Confirm with OK and open the Actions tab. Click here New and refer via To leaf through to your batch file. Confirm with OK (2x) and enter your password if requested. You should now find the task in the left panel, at Taskscheduler-library. You don't have to think about that anymore!

Recent Posts

$config[zx-auto] not found$config[zx-overlay] not found