Home » General » Windows 10 command line tricks

Windows 10 command line tricks

Windows 10 command line tricks

How to use the command line

The Windows Command Prompt is powerful yet often overlooked. It harks back to the days of DOS and the command-line, and continued to feature in early versions of Windows.

Over time, it’s been forced into the background, as Microsoft has pushed bells and whistles, but the Command Prompt has never been ignored, and continues to play a big role, particularly when troubleshooting.

The big headlines may have gone to the new Windows 10 user interface, or some of its more crowd-pleasing features, but the Command Prompt is still nurtured by the Microsoft boffins, and Windows 10 introduced a number of handy improvements to the console window, making it more accessible and easy to use.

New tricks

You can now resize the console window more easily, simply through drag-and-drop – no more messing about with console buffer size settings (although you still can, if you prefer).

Word wrap means text doesn’t get lost off-screen, forcing you to horizontally scroll to read particularly long lines of text. You can now easily select parts of the console output with your mouse, and copy them to the clipboard with just one click (or, more precisely, one right-click).

There are even useful new text-selection key combinations, which helps speed things up further, too. But even without these features, the Command Prompt remains a powerful and vital tool in any self-respecting PC user’s armoury. So why let Linux have all the fun with its Terminal, when you can give your computer some command-line attention in Windows, too?

Join us as we dissect the Command Prompt, and reveal how to best use it.

Windows 10 command line tricks

System File Checker

One of the best-known Command Prompt tools is System File Checker (SFC), and most know that typing sfc / scannow should, in theory, detect corrupt system files and replace them with working backups. But, it’s not always successful – if you get a message telling you Windows Resource Protection was unable to fix the files it found, try the following.

First, generate a text file with the information required to track down the files SFC couldn’t fix:

findstr /c:"[SR]" %windir%LogsCBSCBS.log "%userprofi le%Desktopsfcdetails.txt"

Now open the sfcdetails.txt file – this is a filtered view of the CBS.log, containing only the files SFC couldn’t fix. Identify the corrupt files, and source working versions from another PC running the same version of Windows. Now issue the following commands for each corrupt file, replacing path with the file’s path (such as C:WindowsSystem32), and corruptfile with its full filename (jscript.dll):

takeown /f path corruptfile icacls path corruptfile /

GRANT ADMINISTRATORS:F

Copy the file you took from the other PC into the same folder, overwriting when prompted:

copy sourcepath sourcefile

path corruptfile

Run SFC again, which should now verify there are no corrupt files. For more, see Microsoft’s Support page on the subject.

Windows 10 command line tricks

Customise the Command Prompt

Before delving too deep into the Command Prompt utility, make sure you take the time to customise its appearance to your personal comfort.

To do this, right-click the Command Prompt icon on its menu bar, and choose ‘Properties’. You’ll see options spread out over four tabs: ‘Font’ controls the text type, size and style, while ‘Colors’ lets you change the background and text colours, plus make the window semi-transparent.

The ‘Layout’ tab enables you to set the window size in lines (height) and text characters (width), while the Screen Buffer Size height reveals how many lines you can scroll through. The default size should be suffi cient – make sure you leave the ‘Wrap text output on resize’ option ticked.

The main tab – ‘Options’ – enables you to tweak the command buffer (this is basically your command ‘history’, and you can cycle through previous commands using the up cursor key). You can also change the mouse cursor size, plus enable or disable various features, many of which are new to Windows 10, such as the ability to copy and paste selected text using the keyboard (‘Enable Ctrl key shortcuts’).

If you’re resolutely old-school and like things as they are, you can tick ‘Use legacy console’, and do without these feature improvements, but in the majority of cases, we suggest leaving well alone.

Command Prompt Tips and Tricks

Windows 10 introduces some handy time-saving features to the Command Prompt, including QuickEdit mode (actually introduced in Windows 8, but let’s not split hairs).

This enables you to select and copy text from the console quickly, using the mouse – click and drag to select, then right-click to copy it to the clipboard. Place your cursor where you wish to paste it in the console, and right-click again.

Many commands generate pages and pages of data – to save you the onerous task of scrolling back up to review them, add the | more option onto the end of offending commands, to force them to show the first page, then pause.

Windows 10 command line tricks

From here, press Enter to move down a line at a time, or Space to scroll through the next page.

Alternatively, redirect the information to a text file with the switch – for example, drivequery -v drivers.txt creates the file in your current directory. Some commands can appear to get stuck or keep on looping – break out of them without closing the Command Prompt window by simply pressing Ctrl + C.

Want to clear the screen buffer and start with a fresh new ‘page’? Type cls and hit Enter. The Command Prompt also keeps a handy history of previous commands – how many is configured via the ‘Options’ tab under Command Prompt Properties, which you can cycle through using the up and down cursor keys, speeding up text entry.

Working with Batch Files

Batch files are specially created text files that contain a list of Command Prompt commands, which are executed in the order they’re written. They can also be used to call executable programs (use the start command), and are a great way to make repetitive commands easy to process.

Windows 10 command line tricks

You can create and edit batch files in Notepad – place each command with its options on a separate line. When you come to save the file, set ‘Save as type:’ to ‘All Files (*.*)’, before giving the file a .cmd extension.

There’s a number of commands designed for use in batch files. One of the easiest to use is the pause command. Place this in your batch file, and when it’s reached, the Command Prompt throws up a ‘Press any key to continue’ message, and waits for a key to be pressed.

You can also make use of the echo command to display text on-screen, and insert an @echo off command at the top of your batch file to prevent the commands themselves from appearing in the Command Prompt window as they’re run.

Other useful commands include call, which enables you to call a second batch file from within the first, plus choice and set for introducing interactivity through the form of choices for the end user (you can also introduce conditions through the if and goto commands).

Batch files can be run from within the Command Prompt window (you can drag them from File Explorer into the window), or simply by double-clicking them in File Explorer – you’ll see the Command Prompt window appear, and it disappears when the script completes.


Source: Techradar

Facebook Comments