APC Australia

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 boffi ns, 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 self-respecting PC user’s armory. So why let Linux and Mac have all the fun with their Terminals 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.

“Even without these handy new features, the Command Prompt remains a powerful and vital tool in any selfrespec­ting PC user’s armory. “

Access to the Command Prompt is easy. If you don’t need administra­torlevel access, press Windows-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 command-line, 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 mouse-selection 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 71. 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 contextsen­sitive — 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

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

tells it to output the command’s results in ‘verbose’ or detailed mode, rather than as a basic summary. Note that unlike with Linux, flags aren’t casesensit­ive, 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 the subfolders inside the current one — 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 drive-related commands worth exploring include fsutil, which is a suite of commands offering various tasks for FAT32 and NTFS file systems. Type fsutil and you’ll see a list of supported commands—use fsutil <command> to run one (at which point, you’re shown a list of supported options for that subcommand). Keep typing and more options may show—eventually, you’ll be able to enter a command such as fsutil fsinfo volumeinfo c: to find out useful info about your main system drive, such as its file system, and what features it supports (such as disk quotas and hard links).

If you want to convert a drive from FAT32 to NTFS without losing any of your data, use the convert command. Type convert <vol> /fs:ntfs — if the drive is mounted, you may need to add the /x flag to force a dismount, or otherwise reboot if you’re converting your Windows system drive. Also consider adding /nosecurity if you want the converted files to be

accessible to all users: convert d: / fs:ntfs /nosecurity.

If you want to check a drive for errors, you’ll probably remember the chkdsk tool from earlier versions of Windows. It’s still there in Windows 10 — use it on its own to simply scan the current drive, or specify the drive you wish to scan, plus add the /r flag if you wish to both fix problems and attempt to recover readable informatio­n from bad sectors — for example, chkdsk

d: /r. If the drive is in use, you’re prompted to schedule the check for the next time you restart Windows.

A related tool is chkntfs — by default, Windows runs chkdsk at boot time on any drive found to be ‘dirty’, but you can use this in conjunctio­n with the specified drive and the /x flag to exclude it from the boot-time check, or

/c to schedule it specifical­ly for checking at boot time if it’s dirty. A handy flag to remember is /d — this returns things to normal, namely checking all drives flagged as dirty.

GET INFO AND TROUBLESHO­OT

Want a summary of informatio­n about your system? Use the systeminfo command, which, aside from the usual stuff, can reveal useful snippets, such as when Windows was first installed, and which hotfixes have been added. It can also be used to see whether your PC is capable of Hyper-V irtualizat­ion, too.

There are other, more focused informatio­n tools, as well. Use ipconfig to get informatio­n about your local network settings — use the /all flag

for more detailed informatio­n. Also, ipconfig can be used to fix certain connectivi­ty problems — use /release to release the IPv4 address (/ release6 works with your network’s IPv6 address, if applicable), and /renew or /renew6 to effectivel­y reset it. The ipconfig /flushdns may also work when struggling to resolve domain names over the internet. Where more than one network interface is present (often on PCs with virtualiza­tion software installed), you can also specify the adapter after your flag: ipconfig /renew Ethernet, for example.

Another command that can also prove useful when troublesho­oting network and Internet connectivi­ty is ping, which can be used to verify connection­s between local network devices or websites — use it in conjunctio­n with the device name, its local IP address, web address, or remote IP address. If you ping using a domain or device name, you’re also told its IP address (such as 89.167.142.38 for pcgamer.com, for example).

If the connection works, but is sluggish, use the tracert command in place of ping — doing so reveals the complete route between you and your target, as well as connection times for each part of the connection, helping you target the middleman causing your problem. Want to know which ports are open on your PC, and where they point? Use the netstat command. Try netstat -b while running as an administra­tor if you want to find out more about which program or process has opened which port — it’s a slow process, but worth it if you’re wondering why a particular port is open.

Need informatio­n about drivers on your PC? Device Manager focuses on hardware drivers only, whereas the driverquer­y command includes software drivers, too, such as those installed by your security software and virtualiza­tion tool. These are marked as ‘File System’ drivers, and if you want more informatio­n, use the -v flag for detailed data about each driver, including where its files are on your hard drive.

The -v flag produces an awful lot of informatio­n, so be sure to check the box below to find out how to review this more efficientl­y, either by scrolling a page at a time, or by outputting it to a text file.

The final tool in this section may already be familiar to you — powercfg gives you access to much the same

“Device Manager focuses on hardware drivers only, whereas driverquer­y includes software drivers, too.”

“Laptop users might want to try /batteryrep­ort, which gives you a full overview of your battery’s health.”

informatio­n (and options) as you would find in the Power Options Control Panel, but there are some useful options that you can only find here. Start with powercfg /a, which provides a useful summary of which sleep states are supported on your PC. One handy management tool is

powercfg /h, which enables you to both disable and enable the hibernatio­n function — disabling this is worth doing if you don’t use it, because you can free up a fair amount of hard drive space (the equivalent of however much RAM is in your PC).

Powercfg offers you some useful informatio­n, too — use the /energy flag to generate a report that highlights energy efficiency and battery life issues that your PC may be suffering from. Once created, a file called energy-report.html is saved to the directory you’re currently in. Before analyzing it to find out why your PC won’t stay asleep, however, try

powercfg /lastwake, which reveals the last device to wake your computer. Laptop users might want to try

/batteryrep­ort, which, like /energy, saves a report you can view in your web browser. This gives you a full overview of your battery’s health, as well as a handy graph showing its usage over the past 72 hours.

AND THERE’S MORE

We’ve only really scratched the surface of what you can do with the Command Prompt so far — there’s still plenty more you can investigat­e. So, let’s start with the powerful — but potentiall­y devastatin­g — diskpart tool. Type diskpart and hit Enter, and you’re either prompted to open a new window with administra­tor access, or the cursor changes to ‘DISKPART>’. Type help for a list of supported commands, many of which are potentiall­y destructiv­e — whatever you do, don’t proceed further without having a full system image backup in place for all your drives, just in case. Safe commands include list disk (list physical drives) and list partition, which works on the currently selected drive—switch drives using the select disk <no> command. Use list volume to view a list of drives by letter. When you’ve finished with diskpart, type exit and hit Enter to return to the main Command Prompt.

Want to securely erase some data? The cipher command enables you to wipe the free space in a folder by writing random data to it — delete your files first, then navigate to the folder in question, and type cipher /w:< path>, replacing <path> with the path to the folder that you wish to clean up. The cipher tool can also be used — as its name implies — to encrypt and decrypt files, too.

You can find out more about specific file types and their associated programs using the assoc and ftype commands, and use bootcfg to edit the boot.ini file (as viewed under the msconfig Boot tab). Want to compare the contents of two files? Simply use fc to compare your files and list their difference­s in text. If you want to compare word processing documents, such as those created in Microsoft Word, you need to use the /l flag to ensure that only the ASCII text is compared.

Other commands exist that may have value when unable to boot directly into the Windows desktop, but on the whole you’re better off using Windows’s own graphical-friendly tools. Examples include at (schedule commands and programs to run on a specified computer, at a set time and date), sc (display and configure Windows Services), set (set Windows environmen­tal variables), and both tasklist and taskkill, which are a pair of commands that enable you to view running processes and terminate them.

There are many more commands to learn and master as well—you can find a complete list at technet.microsoft.com/ en-us/library/ bb490890.aspx — but here’s one final useful command that can come in handy. Need to reboot your PC to the Advanced Start Options menu for a spot of troublesho­oting? Just open Command Prompt, type shutdown /r /o, and hit Enter. You’re welcome!

 ??  ?? Cipher does more than simply wipe free space.
Cipher does more than simply wipe free space.
 ??  ?? Diskpart is a powerful— and potentiall­y dangerous—tool.
Diskpart is a powerful— and potentiall­y dangerous—tool.
 ??  ?? Use “netstat” to find out which programs are opening ports.
Use “netstat” to find out which programs are opening ports.
 ??  ?? The “tree” command provides a hierarchic­al view of any folder.
The “tree” command provides a hierarchic­al view of any folder.
 ??  ?? You can quickly and easily switch folders.
You can quickly and easily switch folders.
 ??  ??
 ??  ??

Newspapers in English

Newspapers from Australia