Command Prompt Tricks

WHAT IS COMMAND PROMPT?

Command Prompt is a command line interpreter application available in most Windows operating systems. It’s used to execute entered commands. Most of those commands automate tasks via scripts and batch files perform advanced administrative functions, and troubleshoot or solve certain kinds of Windows issues.

Command Prompt is officially called Windows Command Processor, but it’s also sometimes referred to as ​the command shell orcmd prompt, or even by its filename, cmd.exe.

Cmd.exe is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows, and ReactOS operating systems. The name refers to its executable filename. It is also commonly referred to as cmd or the Command Prompt, referring to the default window title on Windows

How to Access Command Prompt

There are several ways to open command prompt, but the “normal” method is via the Command Prompt shortcut located in the Start menu or on the Apps screen, depending on your version of windows.

Screenshot showing how to open Command Prompt in Windows 10 from the Start menu
 Opening Command Prompt in Windows 10.​

The shortcut is faster for most people, but another way to access Command Prompt is via the cmd Run command. You can also open cmd.exe from its original location:https://0e0654a60b2c89ad4b1249c23e28af9f.safeframe.googlesyndication.com/safeframe/1-0-38/html/container.html

C:\Windows\system32\cmd.exe

Yet another method for opening Command Prompt in some versions of Windows is through the power user menu However, you might see power shell there instead of command prompt, depending on how your computer is set up.

How to Use Command Prompt

To use Command Prompt, you enter a valid command prompt command along with any optional parameters. Command Prompt then executes the command as entered and performs the task or function it’s designed to perform in Windows.

For example, executing the following Command Prompt command in your Downloads folder would remove all MP3s from that folder:

del *.mp3

Commands must be entered into Command Prompt exactly. The wrong syntax or a misspelling could cause the command to fail or worse; it could execute the wrong command or the right command in the wrong way. A comfort level with reading command syntax is recommended.

For example, executing the dir command will show a list of files and folders that exist at any specific location on the computer, but it doesn’t actually do anything. However, change just a couple letters and it turns into the del command, which is how you delete files from Command Prompt!

Syntax is so important that with some commands, especially the delete command, adding even a single space can mean deleting entirely different data.

Here’s an example where the space in the command breaks the line into two sections, essentially creating two commands where the files in the root folder (files) are deleted instead of the files in the subfolder (music):

del C:\files\ music

The proper way to execute that command so as to remove files from the music folder instead is to remove the space so that the whole command is strung together correctly.

Don’t let this scare you away from using Command Prompt commands, but definitely let it make you cautious.

Windows Command Prompt Commands

1. Assoc

Most files in Windows are associated with a specific program that is assigned to open the file by default. At times, remembering these associations can become confusing. You can remind yourself by entering the command assoc to display a full list of file name extensions and program associations.

You can also extend the command to change file associations. For example, assoc .txt= will change the file association for text files to whatever program you enter after the equal sign. The Assoc command itself will reveal both the extension names and program names, which will help you properly use this command.

In Windows 10, you can view a more user-friendly interface that also lets you change file type associations on the spot. Head to Settings (Windows + I) > Apps > Default apps > Choose default app by file type.

2. Cipher

Deleting files on a mechanical hard drive doesn’t really delete them at all. Instead, it marks the files as no longer accessible and the space they took up as free. The files remain recoverable until the system overwrites them with new data, which can take some time.

The cipher command, however, wipes a directory by writing random data to it. To wipe your C drive, for example, you’d use the cipher /w:d command, which will wipe free space on the drive. The command does not overwrite undeleted data, so you will not wipe out files you need by running this command.

You can use a host of other cipher commands, however, they are generally redundant with Bitlocker enabled versions of windows

3. Driverquery

Drivers remain among the most important software installed on a PC. Improperly configured or missing drivers can cause all sorts of trouble, so its good to have access to a list of what’s on your PC. That’s exactly what the driverquery command does. You can extend it to driverquery -v to obtain more information, including the directory in which the driver is installed.

4. Filecompare

You can use this command to identify differences in text between two files. It’s particularly useful for writers and programmers trying to find small changes between two versions of a file. Simply type fc and then the directory path and file name of the two files you want to compare.

You can also extend the command in several ways. Typing /b compares only binary output, /c disregards the case of text in the comparison, and /l only compares ASCII text.

So, for example, you could use the following:

fc /l "C:\Program Files (x86)\example1.doc" "C:\Program Files (x86)\example2.doc"

The above command compares ASCII text in two word documents.

5. Ipconfig

This command relays the IP address that your computer is currently using. However, if you’re behind a router (like most computers today), you’ll instead receive the local network address of the router.

Still, ipconfig is useful because of its extensions. ipconfig /release followed by ipconfig /renew can force your Windows PC into asking for a new IP address, which is useful if your computer claims one isn’t available. You can also use ipconfig /flushdns to refresh your DNS address. These commands are great if the Windows troubleshooter chokes, which does happen on occasion.

6. Netstat

Entering the command netstat -an will provide you with a list of currently open ports and related IP addresses. This command will also tell you what state the port is in; listening, established, or closed.

This is a great command for when you’re trying to troubleshoot devices connected to your PC or when you fear a Trojan infected your system and you’re trying to locate a malicious connection.

7. Ping

Sometimes, you need to know whether or not packets are making it to a specific networked device. That’s where ping comes in handy.

Typing ping followed by an IP address or web domain will send a series of test packets to the specified address. If they arrive and are returned, you know the device is capable of communicating with your PC; if it fails, you know that there’s something blocking communication between the device and your computer. This can help you decide if the root of the issue is an improper configuration or a failure of network hardware.

8. Patping

This is a more advanced version of ping that’s useful if there are multiple routers between your PC and the device you’re testing. Like ping, you use this command by typing pathping followed by the IP address, but unlike ping, pathping also relays some information about the route the test packets take.

9. Tracert

The tracert command is similar to pathping. Once again, type tracert followed by the IP address or domain you’d like to trace. You’ll receive information about each step in the route between your PC and the target. Unlike pathping, however, tracert also tracks how much time (in milliseconds) each hop between servers or devices takes.

10. Powercfg

Powercfg is a very powerful command for managing and tracking how your computer uses energy. You can use the command powercfg hibernate on and powercfg hibernate off to manage hibernation, and you can also use the command powercfg /a to view the power-saving states currently available on your PC.

Another useful command is powercfg /devicequery s1_supported, which displays a list of devices on your computer that support connected standby. When enabled, you can use these devices to bring your computer out of standby, even remotely. You can enable this by selecting the device in Device Manager, opening its properties, going to the Power Management tab, and then checking the Allow this device to wake the computer box.

Powercfg /lastwake will show you what device last woke your PC from a sleep state. You can use this command to troubleshoot your PC if it seems to wake from sleep at random.

You can use the powercfg /energy command to build a detailed power consumption report for your PC. The report saves to the directory indicated after the command finishes. This report will let you know of any system faults that might increase power consumption, like devices blocking certain sleep modes, or poorly configured to respond to your power management settings.

Windows 8 added powercfg /batteryreport, which provides a detailed analysis of battery use, if applicable. Normally output to your Windows user directory, the report provides details about the time and length of charge and discharge cycles, lifetime average battery life, and estimated battery capacity.

11. Shutdown

Windows 8 introduced the shutdown command that, you guessed it, shuts down your computer.

This is, of course, redundant with the already easily accessed shutdown button, but what’s not redundant is the shutdown /r /o command, which restarts your PC and launches the Advanced Start Options menu, which is where you can access Safe Mode and Windows recovery utilities. This is useful if you want to restart your computer for troubleshooting purposes.

12. Systeminfo

This command will give you a detailed configuration overview of your computer. The list covers your operating system and hardware. For example, you can look up the original Windows installation date, the last boot time, your BIOS version, total and available memory, installed hotfixes, network card configurations, and more.

Use systeminfo /s followed by the host name of a computer on your local network, to remotely grab the information for that system. This may require additional syntax elements for the domain, user name, and password, like this:

systeminfo /s [host_name] /u [domain]\[user_name] /p [user_password]

13. System file checker

System File Checker is an automatic scan repair toolthat focuses on Windows system files.

You will need to run the command prompt with administrator privileges and enter the command sfc /scannow. If SFC finds any corrupt or missing files, it will automatically replace them using cached copies kept by Windows for this purpose alone. The command can require a half-hour to run on older notebooks.

14. Tasklist

You can use the tasklist command to provide a current list of all tasks running on your PC. Though somewhat redundant with Task Manager, the command may sometimes find tasks hidden from view in that utility.

There’s also a wide range of modifiers. Tasklist -svc shows services related to each task, use tasklist -v to obtain more detail on each task, and tasklist -m will locate DLL files associated with active tasks. These commands are useful for advanced troubleshooting.

Our reader Eric noted that you can “get the name of the executable associated with the particular process ID you’re interested in.” The command for that operation is tasklist | find [process id].

15. Task kill

Tasks that appear in the tasklist command will have an executable and process ID (a four- or five-digit number) associated with them. You can force stop a program using taskkill -im followed by the executable’s name, or taskkill -pid followed by the process ID. Again, this is a bit redundant with Task Manager, but you can use it to kill oth

Windows automatically marks your drive for a diagnostic chkdsk scan when symptoms indicate that a local drive has bad sectors, lost clusters, or other logical or physical errors.

If you suspect your hard drive is failing, you can manually initiate a scan. The most basic command is chkdsk c:, which will immediately scan the C: drive, without a need to restart the computer. If you add parameters like /f, /r, /x, or /b, such as in chkdsk /f /r /x /b c:chkdsk will also fix errors, recover data, dismount the drive, or clear the list of bad sectors, respectively. These actions require a reboot, as they can only run with Windows powered down.

17. Schtasks

Schtasks is your command prompt access to the Task Scheduler, one of many underrated Windows administrative tools. While you can use the GUI to manage your scheduled tasks, the command prompt lets you copy&paste complex commands to set up multiple similar tasks without having to click through various options. Ultimately, it’s much easier to use, once you’ve committed key parameters to memory.

COMMAND PROMPT TRICKS

Encrypt Files Using Command Prompt

One of the most useful things that you can do using the Command Prompt, is encrypting your sensitive data Encryption is a way to prevent others from taking a peek at your data, and it’s a really important part of ensuring (to some extent, at least), that your files are only yours. With this simple Command Prompt trick, you can easily encrypt files on your Windows PC.

  • Simply launch the Command Prompt, and change your working directory to the folder where your files are. This can be done by using the “cd” command.
  • Once you’re done, type “Cipher /E“, and hit Enter. This will encrypt all the files that were inside the folder.
Command Prompt Tricks

Note: If you try and open these encrypted files, they will open normally for you, however, any other user will not be able to view the files, unless they log in using your account. So make sure that you have a password set.

2. Change the Color of the Command Prompt Window

The Command Prompt window can be unexciting with the default black background and light gray text color. But Windows does allow you to change these colors to suit yourself and make things a bit more intriguing.

  • Launch CMD and Right-click on the title bar
  • Click on “Properties” and in the separate window that opens, click on “Colors”`
  • Here you can choose the colors for the screen text or background as well as for the popup text and background, and also change the transparency of the CMD window
  • After you’re done choosing the most fitting colors for your personality, Click OK
Command Prompt Tricks

Note: There are a lot of other colors available, and you can check out the entire list by typing help color.

Command Prompt Tricks

3. Change the Prompt Text in Command Prompt

When you first open Command Prompt, the default text of the prompt is very boring. It does reflect the current working directory that the user is in, but it sure could use some customization. If you would like the prompt in your cmd window to say something other than the default, you can use the following trick.

  • Launch Command Prompt, and type “prompt” followed by the text that you want. Make sure you add “$G” to the end, to ensure that there is always the “>” sign at the end of the prompt, and you know where your command begins at.
Command Prompt Tricks
  • Hit Enter, and you will see the prompt in the cmd window change to your custom text.
Command Prompt Tricks

Note: There are some more options like “$G” available, and you check out the entire list by typing “help prompt“. Also, you can reset the prompt back to its original state by typing “prompt” and hitting Enter.

4. Change the Title of the Command Prompt Window

When you launch Command Prompt, you must have seen that the title bar reads “Command Prompt”, or maybe “Administrator Command Prompt”, if you launch it with Administrator privileges. While that is okay, but if you have a lot of cmd windows open, and each of them are working on a different task, then this “Command Prompt” title is not helpful at all. Fortunately, you can change that too.

  • Open Command Prompt, and type “title”, followed by the text that you want the Title bar to read.

  • Hit Enter, and you will see the Title of the cmd window change to the text that you entered.

Note: The title changes back to “Command Prompt” once you quit cmd and relaunch it. 

5. List Every Driver Installed on Your Windows 10 PC

If you’re trying to troubleshoot an issue or merely looking for a list of all the drivers on Windows 10, there’s a command prompt trick you can use. Follow the steps below to see the list of drivers:

  • Type in driverquery /FO list /v in CMD, and you will see a list of drivers on your screen.
cmd tricks driver list
  • If you want, you can also copy this output into a text file for easy viewing later. Use this command to save the drivers list to a document:
driverquery > C:\Users\YourUsername\Desktop\driver.txt

6. F1 to F9 Keys are Shortcuts in CMD

All the function keys on your keyboard are also shortcuts for various Command Prompt functions. Here’s what each function key on your keyboard does in CMD

  • F1: Tap or hold this key to retype your last command letter by letter.
  • F2: Copies the current command up to a specified character.
  • F3: Retypes the entire previous line
  • F4: Auto-deletes the current command up to a specified character.
  • F5: Similar to F3, but lets you cycle through previous commands.
  • F6: Enters the EOF indicator into CMD.
  • F7: Opens a list of previously entered commands.
  • F8: Similar to F5, but doesn’t stop at the end of your command history in the session. Instead, it goes all the way to the start.
  • F9: Enters a previous command by entering a number associated with that line.

7. Hide Folders using Command Prompt

While there is an easy way to hide folders on Windows by using the properties pane of the folder and checking the checkbox that says “Hidden”, the method is not very useful as the folders hidden using this method can easily be viewed if the view options are changed to “Show hidden files and folders”, making it a pretty useless feature. However, just like you can hide folders using terminal on Mac using this cmd trick, you can hide your folders in such a way that they will be completely hidden, and Explorer won’t be able to display them at all. Simply follow the steps outlined below:

  • Launch Command Prompt, and navigate to the directory where your target folder resides.
  • Type “Attrib +h +s +r folder_name“, replacing the “folder_name” with the name of the folder that you want to hide, and press Enter.
Command Prompt Tricks
  • You can now check that the folder is indeed hidden inside Windows Explorer and can not be seen by anyone.
  • To unhide the folder, you can use the command “Attrib -h -s -r folder_name“.
Command Prompt Tricks

Note: Hidden folders can be viewed using the cmd command “dir /AH”.

8. Copy Command Output to Clipboard

If you have ever tried to copy stuff off the Command Prompt, you must have realized that it is exceedingly difficult, not to mention un-intuitive. However, with this simple trick you can copy the output of any command that you want, directly to your computer’s clipboard, and you can then paste it into any text editor that you want

  • Launch Command Prompt and type the command that you want to copy the output for, followed by “| clip“. For example, I’m using the command “ipconfig | clip“. Hit Enter, and you will see that the cmd window shows no output.
Command Prompt Tricks
  • Open a text editor, such as Notepad, and press Control + V, and you can simply paste the output of the command directly inside Notepad.
Command Prompt Tricks

9. List all Installed Programs

Another cool trick on the Command Prompt involves listing out all of the Windows 10 apps and programs that are installed on your PC. This is particularly helpful if you need to uninstall a program using the Command Prompt. To list out all the installed programs, simply follow the steps outlined below:

  • Launch Command Prompt, and type “wmic product get name“.
  • Hit Enter, and you will see a list of all the programs that are installed on your PC.
Command Prompt Tricks

You can also use wmic to uninstall programs, directly from the cmd window. Simply type “wmic product where “name like ‘%NAMEOFAPP%’” call uninstall /nointeractive” and hit Enter. Obviously, replace “NAMEOFAPP” with the name of the app that you want to uninstall from your PC.

10. Open CMD Window Inside a Directory

Let’s face it, the way Windows handles changing directories using the “cd” command is rather weird. Fortunately, there is a simple way to open Command Prompt windows inside a directory so you don’t have to change directories. This is a really handy trick, especially if the folders you want to access are buried deep inside the filesystem. To open a cmd window inside a directory, just follow the steps below:

  • Open the directory in Windows Explorer. In the address bar, type “cmd”, and hit Enter.
Command Prompt Tricks directory
  • A command window will open inside the directory you had opened in Windows Explorer.
command prompt tricks

Drop your comment

0Shares

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top