15.6 C
New York
Sunday, May 19, 2024

6 Clever Ways to Use the Windows Command Prompt

The command line may seem like an esoteric tool for developers and uber-hackers, but it has plenty of useful tricks up its sleeve. Here are a few easy things you can do from a terminal window that aren't necessarily available in your computer's traditional menus.

To open the command prompt in Windows, open the Start menu and search for "cmd." Press Enter or click on the result to open a command window—or right-click the option to run it as an administrator, when necessary. Even if your user is an administrator on the PC, you'll need to run command prompt as an administrator to run certain high-level commands.

Start a Shutdown Timer

Let's start with an easy one. Sometimes you have a process running—maybe you're downloading a big file or exporting a video or some other job that involves waiting—and you want to shut down your computer when it's done. Some programs have a built-in option to do so, but if it doesn't, you can turn to the command prompt. A simple command can tell your system to turn itself off after a predetermined length of time.

Say you want to shut down the computer in one hour. Open a command prompt and run:

shutdown -s -t 3600

You can adjust this command to fit your needs:

  • Shutdown is the main command—this doesn't change.
  • The -s flag tells the computer to shut down, though you could use -r to restart or -l to log off after the timer instead. (Sleep is a bit more complicated and would require a completely different command.)
  • The -t flag indicates the timer, and 3600 is the amount of time, in seconds, before you want to shut down. 3600 seconds is one hour, though you can adjust this value to whatever you want (7200 for two hours, etc.).

If you want to cancel the timer, just run shutdown -a in a Command Prompt.

Rename a Bunch of Files at Once

Let's say you have a large folder of files—like photos or videos in sequence—with cryptic, hard-to-understand names (like IMG_001.jpg). Your first instinct is probably to go through and rename every file, but you don't have to do that—you can batch-rename a group of files at once with Windows' built-in tools.

If you select all the files (by clicking on the first one, holding Shift, and clicking the last one), you can actually right-click the selection and choose Rename to rename the whole batch. You'll end up with a list of files that have the same name with a number appended to the end in parentheses, like "Christmas 2020 (1).jpg."

But maybe you want to do the opposite—keep the existing file name but append a word to the end. For this, you can turn to the command line. Open a command prompt and use the cd command to navigate to the folder where those files are stored, like so:

cd "C:\Users\Whitson\Photos\Christmas 2020"

You'll need those quotes if your file path has any spaces in it, so don't forget them.

From there, you can run something like the below to rename all the files in the folder:

rename *.* ??????-original.*

Leaving you with files named IMG_001-original.jpg, and so on.

Here's a breakdown of that command:

  • rename tells the system to rename the files you're about to narrow down.
  • *.* means "any file in this folder." You could adjust this to say IMG*.* to limit it to any files that start with IMG, or *.jpg for any JPEG files. The asterisk acts as a wild card.
  • ?????? tells the command to keep the first six characters of the original file name (because there are six question marks). You can use more or fewer question marks to keep more or less of the original file name.
  • -original appends the word original to the end of every file—perfect if you plan on copying the photos somewhere else for editing but want to note which ones were the original pictures. You can replace this with any text you want.

There's a lot you can do with this command once you get familiar, but a little knowledge can take you pretty far.

View a Saved Wi-Fi Password

Ever been somewhere with password-protected Wi-Fi that you know you've used before, but you can't remember the password for your other devices? If the network is saved on your Windows laptop, you can retrieve the saved password for use on your phone or tablet with a simple command.

If you're currently connected to the network on your laptop, you can reveal this information from the Network Status menu, but if you aren't, you can run the following command to see the password of a given saved network:

netsh wlan show profile SmithHouse key=clear

Replace SmithHouse with the name of the network in question. If Windows has the password saved, it should show it to you in plain text under "Key Content." You can also run netsh wlan show profile to see a list of saved networks.

Erase a Drive Cleanly

Most users should rarely have to deal with drive tables and partition formatting. But if you've migrated your PC to a new drive, or are trying to erase an SD card used in a Raspberry Pi project, Windows' built-in partition manager may not be flexible enough to remove all that data cleanly. As a result, Diskpart's clean command has become one of my most oft-used tools. If you're ever having a problem with a hard drive, flash drive, or SD card, this is probably the ideal way to erase it and start from scratch.

Instead of opening a command prompt window, you can open the Diskpart tool by clicking the Start menu and searching for "diskpart." This will open up a separate command line from which you can run the following to see the disks connected to your computer:

list disk

Find the disk you want to erase in the table—make absolutely sure it's the right one, lest you erase any important data on another drive—and run:

select disk 3

… where, obviously, you replace the number 3 with whatever number corresponds to the disk in question. Finally, run:


Your system will wipe the drive clean, with no hidden partitions or tables confusing your PC. Then you can click the Start menu, search for Disk Management, and right-click the drive to initialize and format it. Note that this merely wipes the partition tables, it doesn't securely erase all your data—some of it may still be accessible with file recovery tools. To securely erase all traces (like if you're going to recycle the drive or sell the PC), you'll want to right-click the drive in Windows Explorer, choose Format, and uncheck the Quick Format box. Or use a third-party tool like DBAN, which has a number of other secure-erase options.

Get a List of Every Program Installed on Your PC

When you get a new laptop or do a clean reinstall of Windows, you're likely to forget some of the tools you use every day and take for granted. Before wiping your drive, you can grab a list of every program installed on your PC with one command.

Unlike the others on this list, however, this command must be run from PowerShell, a newer, more powerful tool built into Windows. Open the Start menu, search for PowerShell, and launch a new window. Then run the following command—it's long, but it's just one copy-and-paste command, which'll grab the contents of three different registry keys and output them to a text file on your desktop:

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*, HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, Size, InstallDate | Format-Table -AutoSize > C:\Users\Whitson\Desktop\ProgramsList.txt

Replace Whitson with the name of your user folder at the end of that command to get the file on your desktop. Note that this won't include Windows Store apps, though, which you can list by running:

Get-AppxPackage > C:\Users\Whitson\Desktop\StoreProgramsList.txt

Again, replacing Whitson with the name of your user folder. There'll be a lot of junk in that list, but you can manually grab the few programs you want to remember and paste them into your original list, if it's easier.

Watch Star Wars (No, Seriously)

OK, this isn't exactly a "useful" trick, but it certainly is neat. If you enable Telnet in Windows (search for "turn windows features on or off" in the Start menu, then check the Telnet box), you can run:

telnet towel.blinkenlights.nl

To watch an ASCII version of Star Wars in your command prompt window. This has been around for years, and it still impresses me.

Related Articles

Latest Articles