The Most Useful Windows Commands You Must Know

Command Prompt a command line interpreter application in your Windows computer used to execute commands and perform advanced administrative functions. Its official name is Windows Command Processor, and its also called by its file name ‘cmd.exe’.
Windows Commands Guide by TechForWorld

Command Prompt is Not DOS!

Most people think Command Prompt and MS-DOS (Microsoft Disk Operating System) are same. Command Prompt is only a program in Windows OSes which is used to run commands or batch of commands.
MS-DOS was an x86-based operating system used for personal computers. Your modern Windows PC doesn’t work on DOS– it is not even having DOS at all!

Twin Article:
The Ultimate Windows Run Commands List
Click Here to Download TechForWorld Windows Command Guide

If the PDF file opens in your browser, click Control+S to save the file to your computer.

Open Command Prompt

There are multiple ways you can access Command Prompt in Windows.
1. Press Windows+R to open Windows Run dialogue box, type CMD and hit enter.
2. Press Windows key in Windows 8, type CMD and press Enter. Press Control+Shift+Enter instead of Enter to open Command Prompt in Administrator mode. Some of the commands are allowed only in Administrator mode.
3. Right click on Start button at bottom left (Windows 8.1) and it will popup a menu with useful Windows options. You can select Command Prompt or Command Prompt (Admin) from that.

See Help on Any Command

One thing I love about Command Prompt is that it provides very useful in-built help.
1. Type HELP to see a list of all commands supported in current Windows version your computer is running.
2. Type HELP [Command Name] or [Command Name]/? to see help on specific command. For example HELP CLS or CLS/? will show you what cls command does.

 

Tips

1. Previously Used Commands:
Press up and down arrow keys to cycle through previously used commands. You can also edit the command any time using left and right arrow keys.

2. Abort a Command:
Use Control+C to abort any command any time.

3. Copy Text from Command Window:
You can copy text from command window. Right click on Command Prompt window and select ‘Mark’. Now select text using your mouse, and you can paste it to any other program or Command Prompt window itself by right click and ‘Paste’.

4. Auto-complete File Names:
Use Tab key to automatically show file or folder name in the current directory. For example, type CD C:\Windows\ and keep pressing tab key to see names of all directories and files within that folder.

5. Paste Text in Command Prompt:
Right click on the Command Prompt window and select ‘Paste’ to copy text or command from clipboard.
You can also drag and drop any file or folder inside the Command Prompt window to quickly copy it’s path.

6. Open cmd Directly in a Directory:
Press Shift key and right click on any folder and you can use ‘open command window here‘ to directly open the Command Prompt within that directory.

7. Select Command from History:
Press F7 key to see a list of previously executed commands and select from them.

Useful Windows Commands

You can easily find list of all Windows commands on internet, but the purpose of this post is to list out very useful Windows commands which can do great work for you.

ASSOC – Display or Change file extension association
ASSOC .txt (View file associatoin)
ASSOC .log=txtfile (Add a file association)
ASSOC .html= (Delete an association)
ASSOC .EXE=exefile (Repair .EXE file associations)
ASSOC .REG=regfile (Repair .REG file associations)
ATTRIB – Display or Change file attributes
ATTRIB +R -H (Set all files in current directory read-only and not hidden)
ATTRIB +R Z:\*.txt (Process particular file or files in given path)
/S (Process files in all sub-folders too)
/D (Process folders too)
BCDEDIT – Sets properties in boot database to control boot loading
BOOTCFG – Edit Windows boot settings
BREAK – Sets or clears extended CTRL+C checking
CALL – Call one batch program from another
CD – Displays the name of or changes the current directory
CD D:\Software (Change to particular directory)
CD /D D:\Software (Change current drive also)
CD “D:\My Software” (Directory name with space)
CD .. (Change to parent directory)
CD ..\.. (Change to grand parent directory)
CD \ (Change to root directory)
CD D:\My [Press Tab key] (Auto complte/suggest directory name)
ECHO “%CD%” (Display the current drive and directory)
CHDIR – Displays the name of or changes the current directory
See its synonym CD
CHKDSK – Check and repair disk problems
CHKNTFS – Displays or modifies the checking of disk at boot time
CHOICE – Accept keyboard input to a batch file
CIPHER – Encrypt or Decrypt files/folders
CLEANMGR – Open Windows Disk cleanup tool
CLIP – Copy command output or content of a file to the Windows clipboard
DIR | CLIP
DATE /T | CLIP
CLIP < filename.txt (Copy a file content to clipboard)
CLS – Clear the screen
CMD – Start a new CMD shell
CMDKEY – Manage stored usernames/passwords
COLOR – Change text and background color of screen
COLOR A (Change text color to light green (A))
COLOR 8A (Change background color to gray (8) and text color to light green (A))
COLOR (Reset to default colors – black background and white text)
COMP – Compare contents of files
COMP “file1.txt” “file2.txt” (Works when size of both files are same)
COMP “file1.txt” “file2.txt” /N=50 (Compare first 50 lines. Use this if both file sizes are different)
/C (Do a case insensitive string comparison)
COMPACT – Displays or modify the compression of files on NTFS disk
CONVERT – Convert a FAT drive to NTFS
CONVERT X: /FS:NTFS /V (Convert drive X to NTFS and show all messages during the process)
COPY – Copy file(s) to another location
COPY “file.txt” “file_copy.txt”
COPY “D:\*.txt” “D:\combined.txt” (Combile all text files into one)
COPY *.* “D:\Backup” (Copy all files to a location)
COPY “file.txt” “file_copy.txt” >nul (Copy silently, no messages on screen)
/Y Supress confirmation prompt to overwrite existing files
/-Y Enable confirmation prompt to overwrite existing files
DATE – Display or change current system date.
DATE /T (Only output the current date, without asking to change)
DEFRAG – Optimize/defragment hard drive
DEL – Delete file(s) or directories.
DEL “filename.txt”
DEL A* (Delete all files starting with letter A)
DEL *.tmp (Delete all files with extension .tmp)
DEL /F * (Delete all files including any that are read only)
TYPE nul > file.txt (Use this command before DEL to clear all contents before deleting the file for safety purpose, since third-party utilities can undelete your files)
DIR – List files and folders in current directory
DIR /P or DIR | MORE (Pause after each screen of data)
DIR/A:H (Show all hidden files)
/O:S (Sort ascending by file size)
/O:-D (Sort descending by date)
/S Include all sub-folders
DISKPART – Manage disk partitions
DOSKEY – Edit command line, recall commands, and create macros
DRIVERQUERY – List installed device drivers

Tip: If the file or folder name contains a space, you must use it within inverted commas, like “D:\My Pictures”

ECHO – Display message on screen. Or turn command echoing on or off
ECHO (Show current echo setting)
ECHO ON or OFF (Turn echoing on or off)
ECHO How are you? (Display a text message)
ENDLOCAL – End localisation of environment changes in a batch file
ERASE – Deletes one or more files
See DEL)
EVENTCREATE – Add a message to the Windows event log
EXIT – Close Command Prompt or quite current script or routine
EXPAND – Uncompress one or more specified files
FC – Compare two or more files and show difference between them
FC /B “file1.txt” “file2.txt” (Perform a binary comparison)
/C (Case sensitive string comparison)
/A (Displays only first and last line of each set of differences)
/U (Compare as UNICODE text files)
/L (Compare as ASCII text – this is default)
/N (Display line numbers – for ASCII only)
/LB50: (Show maximum first 50 differences only)
FINDSearch for a text string in a files or files
FIND “text to find”
/V (Display all lines NOT containing the specified string)
/C (Count the number of lines containing the string)
/N (Display Line numbers)
/I (Ignore the case of characters)
TYPE myfile.txt | FIND “” /v /c (Count number of lines in a file)
FINDSTR – Search for strings in files.
FOR /F – Loops specified command for each file in a set of files.
FORFILES – Batch process multiple files
FORMAT – Format a disk
FORMAT X: /Q (Quick format drive X)
/FS:NTFS or /FS:FAT (Specify the file system)
/V:MyBackup (Specify volume label)
FSUTIL – File and Volume utilities
FTP – File Transfer Protocol
FTYPE – File extension file type associations
FTYPE MyFiletype=”E:\Projects\MyApp.exe”
ASSOC .xxx=MyFiletype (The FileType should always be created before making a File Association)
GOTO – Direct a batch program to jump to a labelled line
GPRESULT – Displays Group Policy information for machine or user
HELP – See help on Windows Command(s)
HELP
HELP DIR (See help on specific command)
HOSTNAME – Display the name of the computer
ICACLS – Change file permissions
IF – Perform conditional processing in a batch program
IF EXIST “file.txt” START “file.txt”
IF NOT EXIST “file.txt” ECHO The file doesn’t exist.
IPCONFIG – Configure IP
IPCONFIG /FLUSHDNS (Purge the DNS Resolver cache)
LABEL – Display or change label of disk.
LOGMAN – Manage Performance Monitor
LOGOFF – Log off Windows user — Be careful!
MAKECAB – Create .CAB files
MD – Create a new directory
MD “Alpha” “Beta” “Gamma” (Make multiple folders at once)
MD “Alpha\Beta\Gamma” (Make an entire path)
MKDIR – Create a new directory
See MD
MODE – Configure system devices
MORE – Display output one screen at a time.
DIR | MORE (Can be used with any command or batch program)
MORE < “file.txt” (Display a file)
/E /C (Clear screen before displaying page)
MOVE – Move or rename files and directories.
MOVE “oldfile.txt” “newfile.txt” >nul (Move quietly without feedback on screen)
MOVE “D:\filename.txt” (Move the file to current folder)
/Y (Suppress confirmation prompt)
MSG – Send message to a user
MSG JIGNESH “Hi!” (Send message to a user of current domain/server)
MSG * “Hi!” (Send message to all!)
/SERVER:ServerName (The server to contact (default is current))
/V (Verbose, display extra information)
/W (Wait for response from user, useful with /V)
MSG JIGNESH (If no message text to send is specified, MSG will prompt for it)
MSIEXEC – Start Windows installer/setup
MSINFO32 – Display system information (opens a new dialogue)
MSTSC – Start terminal server connection (remote desktop)
NET – Manage network resources
NETSH – Configure Network Interfaces, Windows Firewall & Remote access
NETSTAT – Display networking statistics, connection details (TCP/IP)
NSLOOKUP – Verify DNS name resolution for a host
PATH – Display or set a search path for executable files
PATH D:\MyApps; E:\MyApps;
PATH ; (Clear all paths)
PAUSE – Suspend processing of a batch file and display a message
PAUSE >nul (To suppress the message ‘Press any key to continue…’)
Echo Press any key to exit
PAUSE >nul (Display a different message)
PERFMON – Start performance monitor
PING – Test a network connection
PING techforworld.com
POPD – Return to a previous directory saved using PUSHD command
POWERCFG – Configure power settings
PRINT – Print a text file using a printer device
PRINT “file.txt”
PRINT /D:LPT1 or /D:COM1 (Specify printer device)
PROMPT – Change the cmd.exe command prompt text
PUSHD – Stores the current directory for use by the POPD command
QUERY PROCESS – Display processes
QUERY SESSION – Display all sessions
QUERY TERMSERVER – List all servers
QUERY USER – Display user sessions
RASDIAL – Manage remote access service (dial-up) connections
RASPHONE – Manage remote access service (dial-up) connections
RD – Delete folder(s)
RD “D:\Temp files” (Will delete only if the folder is empty)
/S (Delete all files, tree of subfolders and folder itself)
/Q (Delete silently – don’t display Y/N confirmation)
RD D:\Temp1 D:\Temp2 “D:\Temp 3” (Delete multiple folders)
RECOVER – Recover a damaged file from a defective disk
REG – View, add, delete, change or export Registry key or key values
REGSVR32 – Register or unregister a DLL file
REM – Add comments/remarks in a batch file. This can also be done using double colons (::)
REM This is a comment.
:: This is another comment.
REN – Renames a file or files
REN:
REN old.txt new.txt
REN * *.txt (Rename extension of all files)
REN * *?.bak (Append extra extension to every file, E.g. file.txt.bak)
RENAME – Renames a file or files
See REN
REPLACE – Replace files
REPLACE D:\backup\file.txt E:\documents
/R (Replace read-only files as well)
/U (Updates files that are only older than source files.)
/S (Replace all subfolders of the destination)
/P (Prompt for confirmation for each file)
RMDIR – Removes a directory
See RD
ROBOCOPY – Advanced utility to copy files and folder trees
ROBOCOPY \\Server1\reports \\Server2\backup
/E (Include subfolders)
/COPYALL (Copy all file info like attributes, timestamps, security info, owner info)
/NOCOPY (Don’t copy file info)
/MOVE (Delete files and folders from source after copying)
/Z (Restrtable mode, survive network gliltch)
/PURGE (Delete destination files that no longer exist in source)
/MIR (Mirror a directory tree – equivalent to /PURGE and /E
/LOG:report.txt (Output progress to a log file)
ROUTE – Manipulate network routing tables
RUNAS – Execute a program under a different user name
RUNAS /user:TechForWorld\Jignesh “program.exe” (Run a program as a specified domain user)
SC – Displays or configures services (background processes)
SCHTASKS – Schedule a command or task to run at a specific time
SCHTASKS /Query (See all scheduled tasks)
SCHTASKS /Create /SC weekly /D MON,TUE,WED,THU,FRI /TN MyDailyBackup /ST 23:00 /TR c:\backup.cmd /RU MyDomain\MyLogin /RP MyPassword (Create a task to run at 11 pm every weekday)
SCHTASKS /Delete /TN “MyDailyBackup” /F (Delete a task)
SCHTASKS /create /TN “My Script” /TR “\”c:\my folder\script.cmd\” arguments” /sc daily /sd 12/29/2014 /st 17:00 (Create a daily task to run a script at 5 pm)
SCHTASKS /Run [Connect_Options] /TN taskname (Run a task on demand)
Please note that task scheduler options are stored in Windows Registry at HKLM\SOFTWARE\Microsoft\SchedulingAgent\
SET – Display, set, or remove Command Prompt environment variables
SET X=Some Value (Set a value to X)
SET X (Display value of X)
SETLOCAL – Begins localization of environment changes in a batch file
SETX – Set environment variables
SFC – System file checker
SFC /SCANNOW (Scan and repair all protected system files immediately)
/SCANONCE (Scan all system files once you restart the computer. The SfcScan DWORD value is set to 2 in the following registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon)
/SCANBOOT (Scan all protected system files every time you start your computer. The SfcScan DWORD value is set to 1 in the following registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon)
/REVERT (Return scan to default setting)
Note: SFC may require Windows installation files
SHIFT – Shift the position of batch file parameters
SHUTDOWN – Shutdown the computer
SHUTDOWN (Show help about command)
/I (Display graphical user interface)
/S (Shutdown)
/R (Shutdown and restart)
/A (Abort shutdown)
/P (Turn off without any warning or timeout. Use with /D)
/H (Hibernate. Use with /F)
/F (Force to close all applications. You may lose unsaved data!)
SLMGR – Software Licensing Management
SORT – Sort input text
START – Start a program, command or a batch program
START C:\MyApp\App.exe
START “” “C:\Program Files\MyApp\App.exe” “Parameter 1” (For long file name formats. First parameter is Window title!)
“C:\Program Files\MyApp\App.exe” “Parameter 1” (This also works!)
START CALC (Start can be used with various Windows functions)
/MIN (Start window minimized. Default is normal window)
/MAX (Start window maximized)
/WAIT (Start the application and wait for it to terminate)
SUBST – Associate a network or local path with a (virtual) drive letter
SUBST (List all virtual drivers)
SUBST X: \\Server1\Share\Folder1 (Set a path as virtual drive X:)
SUBST X: /D (Delete the substituted (virtual) drive)
SYSTEMINFO – List system configuration
TAKEOWN – Take ownership of a file
TASKLIST – List running applications and services in Windows
TASKKILL – Terminate a running process/task
TIME – Display or set the system time
TIME 13:54 (Set the new time)
TIME /T (Only output the current time without asking new time)
TIMEOUT – Wait for specified seconds or until any key is pressed. For use within a batch program.
TITLE – Set the window title for a CMD.EXE session
TRACERT – Trace route (find IP address) to a remote host
TRACERT TechForWorld.com
TREE – Graphical display of directory structure of a folder or a drive
TREE | MORE (Show tree for current directory. Pause after each screen)
TREE “D:\Games” | MORE (Show tree for specified path)
TREE > “D:\Tree.txt” (Save a tree structure to file)
TSDISCON – Disconnect a Remote Desktop Session
TYPE – Display the contents of a text file
TYPE “D:\file.txt” | MORE (Display output on screen, pause after each screen)
TYPE “D:\file.txt” > NewFile.txt (Copy content to a new file)
TYPE “D:\file.txt” >> ExistingFile.txt (Overwrite content to an existing file)
TYPE nul > file.txt (Create a zero byte (empty) file)
TYPEPERF – Write performance data to a log file or window
VER – Display operating system version information
VERIFY – Verify that your files are written correctly to the disk
VERIFY (Display current verify status)
VERIFY ON or VERIFY OFF (Turn file verification on or off)
By default the Command Prompt has verify OFF. Windows Explorer will always copy with verify ON.
VOL – Display the disk volume label and its serial number
WAITFOR – Wait for or send a signal
WEVTUTIL – Clear event logs, enable/disable/query logs
WHERE – Search for files in a directory tree
WHERE /R D:\ Tech (Find all files named tech in drive D: and all sub-folders)
WHERE /R D:\ *.txt (Find all txt files)
/R (Search recusrively in sub-folders too)
/F (Display files in quotation marks)
/T (Display size and timestamp info of files)
WHOAMI – Display current user-name with domain name
WINRM – Windows Remote Management
WINRS – Windows Remote Shell
WMIC – WMI Commands
WUAUCLT – Windows Update
XCOPY – Copy files and directory trees
XCOPY “D:\file.txt” “E:\Backup” (Copy a file to a location)
XCOPY “D:\My Files\*” “E:\Backup” /S /I (Copy a folder including all subfolders)
Please note that in many cases the functionality of XCOPY is superseded by ROBOCOPY.
> – Save a command’s output to a file.
SYSTEMINFO > D:\MyPCinfo.txt.
HELP > D:\CmdList.txt

Also see this post for a good example of a batch program.

Comments

  1. says

    Woah! I’m really digging the template/theme of this website.

    It’s simple, yet effective. A lot of times it’s hard to get that
    “perfect balance” between user friendliness and appearance.
    I must say you’ve done a excellent job with this. Also, the blog loads very fast for me on Opera.
    Exceptional Blog!

Leave a Reply

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