Maximum PC

WINDOWS 10 COMMAND-LINE TRICKS

Get savvy with the Command Prompt, with help from Nick Peers

-

The Windows Command Prompt is at once both powerful and often overlooked. It harks back to the days of DOS and the command-line, and continued to play a major role 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 an important role, particular­ly when troublesho­oting.

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 has continued to be nurtured by the Microsoft boffins, and Windows 10 introduced a number of handy improvemen­ts to the console window, making it more accessible and easy to use.

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 horizontal­ly scroll to read particular­ly 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 combinatio­ns, helping speed things up further, too.

But even without these handy new features, the Command Prompt remains a powerful and vital tool in any selfrespec­ting PC user’s armory. So why let Linux have all the fun with its Terminal, when you can give your computer some command-line love in Windows, too? Join us as we dissect the Command Prompt, and reveal how best to make use of it. You’ll never look at your mouse (or the Windows desktop) in quite the same way again.

Access to the Command Prompt is easy. If you don’t need administra­tor-level access, press Win-R, type cmd, and hit Enter, or search for “cmd” in the Cortana search box. Alternativ­ely, right-click the Start button, where you’ll find two options: “Command Prompt” and “Command Prompt (Admin).” The latter launches Command Prompt as an administra­tor, giving you access to the full gamut of options.

Once the window opens, you’ll find yourself staring at the Windows commandlin­e, which will be a familiar sight to those who remember DOS, or who have had experience with the Linux shell. In the past, the Command Prompt was strictly a keyboard-only affair, but with Windows 10, Microsoft has added some mouseselec­tion features, it has expanded the way you can select, too. For example, hold Shift and use the arrow keys to select characters to the left and right, or lines up and down. Use Shift-Home and End to extend selections to the margin, and Shift-PageDown or PageUp to select entire screens. Throw in Ctrl with each of these shortcuts (so Ctrl-Shift), and the selection goes further—words, paragraphs, and even the entire screen buffer.

Before going any further, check out the box on customizin­g the Command Prompt interface, on page 42. By default, text is rendered quite small, so you’ll be pleased to learn you can customize most aspects of the window—font, size, color, background, and so on.

What can you do with the Command Prompt? There are dozens of useful commands you can input, and we’re showcasing the best of them in this guide. Before continuing, though, it helps to understand how commands are broken down, known as the command syntax. There’s the command itself, of course, but it’s usually followed by a number of options, some compulsory (in that you must choose at least one), others optional. These options are context-sensitive—they might refer to a path or filename, as is the case with the recimg command for creating a recovery image, or they may refer to various “flags,” which instruct the command to work in a specified way—for example, adding -v to a command, such as driverquer­y, usually tells it to output the command’s results in “verbose” or detailed mode, rather than as a basic summary. Note: Unlike with Linux, flags aren’t case-sensitive, so typing -v or -V results in the same thing.

Find your way around

Let’s delve into the Command Prompt proper. First, you’ll notice that it opens in one of two locations—if you invoke it as a normal user, it opens inside your personal user folder; if you launch it as an administra­tor, it defaults to the Windows\ System32 directory. You’re not stuck in this folder—the Command Prompt has all the tools you need, not just for navigating through your file system, but also moving, copying, and deleting files, too. We’ll start

with the dir command—type this and it lists all the files and folders in the current folder. Hidden folders don’t show up—to make these appear, use dir /A:H. The /A flag instructs dir to show files containing whichever attributes are listed after it— H refers to hidden files, while other attributes you can use include R (read-only files), D (directorie­s), and S (system files). Type dir /A:HD, and hidden directorie­s are shown instead of hidden files.

There are lots of other useful flags you can apply to dir, too—but how can you find out about them? Simple, either type dir /? or help dir, and a handy cheatsheet appears, providing a descriptio­n of the command, what options it supports, and then giving a summary of each option, such as /q, which lists the owner of the file or folder, in addition to other stats.

Want to know how your folder is broken down into subfolders? Use the tree command, and you’ll see a tree-like hierarchy of all the subfolders inside the current folder—pair tree with a specific path, and it shows you the hierarchy for the selected folder.

Want to move to a different directory? Type cd, followed by the full path of the folder you wish to visit (enclose paths in double quotes if there’s a space in the name), and you’ll jump straight there— for example, cd “c:\program files”. You can also substitute the path with an environmen­t variable—use cd %appdata% to jump to the AppData\Roaming folder inside your personal user folder, for instance. You can also move up and down your folder hierarchy—use cd folder to enter a subfolder inside the current folder, or type cd .. to move up one level.

If you want to switch to a different drive, you’ll find the cd command has no effect— simply type the drive letter (such as d:), and hit Enter, then use the cd command to navigate to your desired folder.

Copy, move, delete

It’s possible to copy, move, rename, and delete files and directorie­s with the Command Prompt, too—use copy, rename, and move for individual files and folders, plus del to delete individual files. If you need to delete everything in a folder, use the * wildcard—for example, del *.* deletes every single file in the current folder. It goes without saying, you should proceed with caution—we suggest sticking with File Explorer when it comes to working with files and folders, unless there’s no alternativ­e, or you want to verify files you copy—in which case, use the verify on command to do so (and, yes, verify off switches this off again).

You can manage folders, too: md creates a folder, while rmdir removes it. If you plan to delete a folder that isn’t empty, use rmdir /s directory to delete it and its contents. Also, investigat­e the robocopy command, which is designed to copy multiple files and folders in one go—it’s very complicate­d to set up, but is incredibly powerful, too, giving you all kinds of filters and options, such as /nocopy (remove all file informatio­n from the copied files), and /b (backup mode, which allows administra­tors to copy files they would normally be denied access to). A number of GUI frontends have been developed, but only one is currently available, the commercial GS RichCopy 360 ( www.gurusquad.com).

Need to format a drive from the Command Prompt? Use the aptly titled format command. To quickly format the current drive using the same file system, use format vol /Q, where vol is the drive letter (such as d:) of the target drive. Other options include /FS (specify file system, including FAT, FAT32, exFAT and NTFS), /V: (assign a drive label), and /C (compress all files on this volume, this requires NTFS). Like file management, formatting drives is usually best done from within File Explorer itself. Other

Robocopy is designed to copy multiple files and folders in one go—it’s complicate­d to set up, but incredibly powerful.

 ??  ?? Youcanquic­klyandeasi­lyswitchfo­lders.
Youcanquic­klyandeasi­lyswitchfo­lders.
 ??  ??
 ??  ?? The“tree” commandpro­videsahier­archicalvi­ewofanyfol­der.
The“tree” commandpro­videsahier­archicalvi­ewofanyfol­der.
 ??  ?? Use“netstat”tofindoutw­hichprogra­msareopeni­ngports.
Use“netstat”tofindoutw­hichprogra­msareopeni­ngports.

Newspapers in English

Newspapers from United States