COMMAND PROMPT
COMMANDS
Dir Command Syntax
• dir [drive:][path][filename] [/a[[:]attributes]] [/b] [/c] [/d] [/l] [/n]
[/o[[:]sortorder]] [/p] [/q] [/r] [/s] [/t[[:]timefield]] [/w] [/x] [/4]
How to Read Command Syntax
• The syntax of a command is basically the rules for running the
command. You need to know how to read syntax notation when
learning how to use a command so you can execute it properly.
Command Syntax Key
Notation Meaning
Bold Bold items must typed exactly as they are shown, this includes any bold words, slashes,
colons, etc.
Italic Italic items are items that you must supply. Do not take an italic item literally and use it in
the command as shown.
Spaces All spaces should be taken literally. If a command's syntax has space, use that space when
executing the command.
[Text inside brackets] Any items inside a bracket are optional. Brackets are not to be taken literally so don't use
them when executing a command.
Text outside brackets Any text not contained in a bracket is required. In the syntax of many commands, the only
text not surrounded by one or more brackets is the command name itself.
{Text inside braces} The items within a brace are options, of which you must choose only one. Braces are not to
be taken literally so don't use them when executing a command.
Vertical | bar Vertical bars are used to separate items within brackets and braces. Do not take vertical bars
literally - do not use them when executing commands.
Ellipsis ... An ellipsis means that an item can be repeated indefinitely. Do not type ellipsis literally
when executing a command and take care to use spaces and other required items as shown
when repeating items.
Search for files and folders from Command
Prompt
• Command Prompt can search a particular drive, or a specific folder for files
and folders. By default, assuming you’re running it with ordinary user rights, it
opens to your user folder and you may, or may not want to search that
particular folder. This is why you need to know how to move Command
Prompt to a different location.
• If you want to search other non-window drives, you will need to switch to it
first with the following command;
Syntax;
Drive letter:
Example;
C:\Users\Benjamin\D:
• You will now find out the device drive name will be changed from drive C to D.
MOVING TO A DIFFERENT FOLDER
• To move to a different folder, use the command below. The quote marks
are only necessary if you have folders that have a space in their names
in the path that you’re entering but it’s best to make a habit out of
adding them;
cd “path to folder”
Example;
cd C:\images>
The command will change to C:\images>
You have now entered the images folder and can only search for files or
other subfolders in only the images folder.
SEARCHING FOR FILES BY TYPE
• The following command allows you to search the current folder for all
files of a particular type;
dir /b/s *.file_extension
Example;
dir /b/s *.docx
The above command will search for all files with the extension .docx
only in the current directory and in its sub directories. The /s switch
tells the command to include sub folders and the /b switch displays files
without including metadata making the list easy to read.
Search for files by name
• To search for files by name, use the following command;
Syntax
dir *file_name*.* /s
Example;
dir *mech157*.* /s
The above command will look for all files that match the file name you
entered regardless of the file type. If you want to narrow the search down by
file type, enter the file extension after the period.
Example;
dir *me157*.docx /s
SEARCH FOR FOLDERS
• To search a folder for sub-folders, use the following command;
SYNTAX
dir “name of folder to search” /AD /b /s
Example;
dir lecture-notes /AD /b /s
Remember that the above command will search the folder you enter
for sub-directories. If you want to search a different folder, use the cd
command to move to where the folder is located and then run the
command.
SEARCH FOR FOLDER WITH
UNKNOWN NAME
• If you’re not sure what the name of a folder is, you can use the
following command.
Syntax
dir /s/b /A:D “C:*partial name of folder*”
Example;
dir /s/b /A:D “C:*ME15*”
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. You can probably do this more easily in the
GUI, but the command line interface is a perfectly functional alternative.
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 command
“cipher /w:c”, 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.
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.
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 network
troubleshooter chokes, which does happen on occasion.
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.
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 inDevice Manager, opening its properties,
going to thePower Managementtab and then checking theAllow this device to wake
the computerbox.
• “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.
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.
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]”
SYSTEM FILE CHECKER
• System File Checker is anautomatic scan and 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.
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.
CHDIR
• The chdir command is used to display the drive letter and folder that
you are currently in. Chdir can also be used to change the drive
and/or directory that you want to work in. The chdir command is
available in all versions of Windows, as well as in MS-DOS.
CHKDSK
• The chkdsk command, often referred to as check disk, is used to
identify and correct certain hard drive errors. The chkdsk command is
available in all versions of Windows, as well as in MS-DOS.
CLS
• The cls command clears the screen of all previously entered
commands and other text. The cls command is available in all versions
of Windows, as well as in MS-DOS.
CMDKEY
• The cmdkey command is used to show, create, and remove stored
user names and passwords. The cmdkey command is available in
Windows 10, Windows 8, Windows 7, and Windows Vista.
COLOR
• The color command is used to change the colors of the text and
background within the Command Prompt window. The color
command is available in Windows 10, Windows 8, Windows 7,
Windows Vista, and Windows XP.
COMP
• The comp command is used to compare the contents of two files or
sets of files. The comp command is available in Windows 10,
Windows 8, Windows 7, Windows Vista, and Windows XP.