60+ Essential Windows CMD Commands | Command Prompt Commands

Using commands in Command Prompt may seem old-fashioned compared to modern GUI (Graphical User Interface). However, system administrators, developers, and some power users still rely on the Windows Command Line to execute commands and scripts that directly interact with the operating system. There are several advantages of using Windows CMD Commands but the main one is automation using batch scripts. You can write a small script containing a series of commands that execute in sequence. The script allows you to automate routine tasks such as file backups, system updates, or network diagnostics.

If you are a beginner and new to the world of IT Administration (especially working on Windows Servers) or a developer working on a project, having the basic knowledge of Windows Command Line and Command Prompt (CMD) Commands is very important (and useful). Apart from automating using scripts, you can improve the efficiency and speed of certain tasks (copying large volumes of files, searching for specific files by name, or running batch operations).

In this “back to basics” guide on Windows, we would like to take you through some essential Windows Command Prompt commands. Do take a look at the commands below. But before that let’s understand what Windows Command Prompts mean, and how to access them.

Basic Overview Of Windows Command Prompt (CMD)

The Windows Command Prompt, commonly referred to as CMD, is a text-based interface that allows users to perform system-level functions. Unlike the graphical user interface (GUI), which relies on mouse clicks and visual navigation, CMD accepts textual commands.

Using these commands, you can execute tasks associated with managing files, controlling processes, or configuring system settings. CMD uses a command-line interpreter to process these instructions which interact directly with the underlying operating system.

IT professionals use CMD for its better problem-solving capabilities and operational efficiency. Developers use Command Prompt to run development environments, manage code repositories, and deploy applications.

Here are some of the ways a Command Prompt or CMD can help a user.

  • Automate Repetitive Tasks: You can write simple scripts that include multiple commands to automatically execute several tasks.
  • Troubleshooting Issues: With tools like ‘ping’ or ‘ipconfig’, you can diagnose network problems. For repairing file systems, there are tools as well (‘sfc’ or ‘chkdsk’).
  • Have Precise Control Over The System: Administrators can manipulate configurations or processes without relying on the graphical interface (sometimes even remotely).

How To Access Command Prompt?

Accessing the Windows Command Prompt is very simple.

  • The most common way is using the Start menu. To do this, click the Start button (or press the Windows key) and type “cmd” or “Command Prompt” into the search bar. The system will display the Command Prompt option. You can click on it to open the terminal window.
  • Alternatively, you can open CMD via the Run dialog. To do this, press the Windows key + R, and a small window labeled “Run” will appear. In the text box, type “cmd” and hit Enter. The Command Prompt window will instantly open.

Sometimes, when a task requires elevated permissions (such as modifying core files or installing programs), you need to run Command Prompt with administrator privileges. To open CMD as an administrator, follow the same steps that we mentioned above (the first method), but instead of directly opening the Command Prompt app, select “Run as administrator” instead.

If you are already running a command prompt window, type the following command and hit enter. A new Command Prompt window will open but in administrator mode.

powershell Start-Process cmd -Verb RunAs

60+ Key Windows Command Prompt (CMD) Commands

Depending on the version of Windows you are using, there are roughly 280 to 300 built-in Windows Command Prompt commands in modern versions of Windows (Windows 10 and Windows 11). These include simple/basic commands for file management and advanced commands for system configuration or network settings. Let us understand some useful CMD Commands.

Basic Navigation And File Management Windows CMD Commands

1. dir

The dir command lists files and directories within the Command Prompt. By typing dir and pressing Enter, you can view the contents of the current directory, including files and subdirectories.

Basic Syntax: dir [path] [options]

  • path: The directory you want to list (optional). If you don’t specify a path, it lists the contents of the current directory.
  • options: Flags that modify the behavior of the command (optional).

Common Options:

  • /A: Displays files with specific attributes (like hidden, system files, etc.).
  • /P: Pauses after each screen of information.
  • /W: Uses wide listing format.
  • /O: Sorts the output based on various options like name, size, date, etc.
  • /S: Displays files in specified directory and all subdirectories.
  • /T: Controls which time field to display or use for sorting (creation, last access, or write time).
  • /Q: Displays file ownership information.
  • /L: Displays names of files and directories in lowercase.

dir

Useful Examples

Command Action
dir Displays the contents of the current directory (files and folders).
dir C:\Users\Reyan\Documents Displays all files and directories in C:\Users\Reyan\Documents.
dir /A:H Shows only the hidden files in the current directory.
dir /O:N /Q /T:C Lists files sorted by name (/O:N), showing the file owner (/Q) and sorting them by creation date (/T:C).

2. cd

The cd (change directory) command can help you navigate through the file system in CMD (Command Prompt). You can move from the current directory to another by typing cd followed by the desired directory’s name.

Basic Syntax: cd [directory path]

  • Directory Path: The path of the directory you want to navigate to. If you don’t specify a path, cd will display the current directory.

cd

Useful Examples

Command Action
cd Shows the current working directory.
cd C:\Users\Reyan\Documents Changes the current working directory to C:\Users\Reyan\Documents.
cd .. Navigates up one level from the current directory.
cd ..\.. Goes up two levels in the directory hierarchy.
cd “C:\Program Files” Change to a directory with spaces in the name.
D: Changes the working directory to the last directory accessed on that drive.

3. md / mkdir

The md or mkdir (short for Make Directory) commands in Command Prompt are useful for creating new directories (folders) in the file system. These two commands are identical.

Basic Syntax: md [directory path] or mkdir [directory path]

  • Directory Path: The path where you want to create the new directory. You can specify either an absolute path (e.g., C:\Users\Reyan\NewFolder) or a relative path (e.g., NewFolder if you want to create it in the current directory).

md/mkdir

Useful Examples

Command Action
md MyFolder Create a directory in the current location.
mkdir C:\Users\Reyan\Documents\NewFolder Creates a folder named NewFolder in the C:\Users\Reyan\Documents directory.
md Folder1 Folder2 Folder3 Creates three directories.
md ParentFolder\ChildFolder This creates a directory named ParentFolder, and within it, a subdirectory named ChildFolder. If ParentFolder doesn’t exist, it will be created first.

4. rd / rmdir

The rd or rmdir command helps in removing directories from the file system. By typing rmdir followed by the folder name, you can delete empty directories. rd is a shorthand version of the rmdir command. Both can delete directories, but neither can remove non-empty directories by default.

To delete a directory that contains files, you must add the /s switch (rmdir /s FolderName). This will remove the folder and all its contents.

Basic Syntax: rd [directory path] [/S] [/Q] or rmdir [directory path] [/S] [/Q]

  • Directory Path: The path to the directory you want to delete.
  • /S: Removes the specified directory and all its contents, including subdirectories and files.
  • /Q: Quiet mode. It suppresses confirmation prompts when used with /S.

rd / rmdir

Useful Examples

Command Action
rd MyFolder Removes an empty directory.
rd /S MyFolder Deletes a directory and all its contents.
rd /S /Q MyFolder Removes a directory and all its contents without confirmation.
rmdir C:\Users\Reyan\Documents\OldFolder Removes a directory from a specific path.

5. tree

The tree command visually represents the structure of the directories within the current folder. By typing tree, you can generate a hierarchical view of all subdirectories and files.

Basic Syntax: tree [drive:][path] [/F] [/A]

  • [drive:][path]: Specifies the drive and/or directory to display the directory structure. If you don’t specify a path, tree displays the structure of the current directory.
  • /F: Displays the names of the files in each folder, in addition to showing directories.
  • /A: Uses ASCII characters to display the tree instead of the extended character set.

tree

Useful Examples

Command Action
tree Displays the directory tree for the current folder.
tree C:\Users\Reyan\Documents Shows the folder structure and all its subdirectories.
tree /F Includes both the directory structure and the files within each directory.
tree C:\Users\Reyan\Documents /F /A It shows both files and directories, using ASCII characters.

File Management Commands

1. copy

The copy command is one of the most fundamental file management tools in the Command Prompt. Using copy command, you can copy files from one location to another (duplicating data) without leaving the command-line environment. You can employ this command by typing copy followed by the source file and destination folder.

Basic Syntax: copy [source] [destination] [/options]

  • Source: The path to the file or files you want to copy.
  • Destination: The path where you want to copy the file(s).
  • /options: Optional parameters that modify the behavior of the copy command (e.g., copy hidden files, suppress confirmation prompts, etc.).

Common Options:

  • /Y: No prompt asking for confirmation to overwrite existing files.
  • /N: Copies files using the short filename.
  • /V: Verifies that the new files are written correctly after copying.

copy

Useful Examples

Command Action
copy C:\Users\Reyan\Documents\file.txt D:\Backup This command copies file.txt from C:\Users\Reyan\Documents to D:\Backup. If D:\Backup is not a directory, it will rename the file to Backup.
copy C:\Users\Reyan\Documents\*.txt D:\Backup Copies all .txt files from C:\Users\Reyan\Documents to the D:\Backup directory.
copy /Y C:\Users\Reyan\Documents\file.txt D:\Backup This copies file.txt from C:\Users\Reyan\Documents to D:\Backup and overwrites any existing file with the same name without asking for confirmation.

 

copy C:\Users\Reyan\Documents\file.txt D:\Backup\newfile.txt Copy a file and rename it.

2. xcopy

If you want a more robust copying tool, the xcopy command comes into play. This command extends the functionality of copy by allowing users to transfer entire directories, not just individual files.

For example, entering xcopy C:\Projects D:\Backup /s will copy the Projects directory, including its subdirectories and files, to the Backup folder on the D drive.

Basic Syntax: xcopy [source] [destination] [/options]

  • Source: The file(s) or directory you want to copy.
  • Destination: The location where you want the files or directories copied.
  • /options: Parameters that modify the behavior of xcopy.

Common Options:

  • /S: Copies directories and subdirectories, but skips empty ones.
  • /E: Copies all subdirectories, including empty ones.
  • /H: Copies hidden and system files as well.
  • /I: Assumes the destination is a directory if it doesn’t exist.
  • /Y: Suppresses the confirmation prompt when overwriting files.
  • /C: Continues copying even if errors occur (e.g., if a file cannot be copied).
  • /D:mm-dd-yyyy: Copies files that have been modified after the specified date.
  • /T: Copies only the directory structure (no files).
  • /K: Copies file attributes (retains read-only, archive, and system attributes).
  • /R: Overwrites read-only files in the destination.

xcopy

Useful Examples

Command Action
xcopy C:\SourceFolder D:\BackupFolder /S This copies all files and subdirectories from C:\SourceFolder to D:\BackupFolder, excluding empty directories.
xcopy C:\SourceFolder D:\BackupFolder /E Copies an entire directory including empty subdirectories.
xcopy C:\SourceFolder D:\BackupFolder /E /Y Copies all files and subdirectories, including empty ones, without prompting to confirm overwriting of existing files.
xcopy C:\SourceFolder D:\BackupFolder /D:01-01-2023 /S Copies only newer files (modified after a specific date).

3. robocopy

The robocopy (Robust File Copy) command is a more advanced solution for managing large-scale file transfers. Unlike copy and xcopy, robocopy can handle interruptions during the copying process. If a network connection drops or a file becomes unavailable, robocopy can resume the operation without starting over.

Some other capabilities of robocopy are mirroring directories, resuming interrupted transfers, and copying file attributes, timestamps, and permissions.

Basic Syntax: robocopy [source] [destination] [file(s)] [options]

  • Source: The path of the directory you want to copy from.
  • Destination: The path of the directory you want to copy to.
  • File(s): The specific file(s) you want to copy. You can use wildcards like * (default is *.*, which means all files).
  • [options]: Various parameters that control how robocopy operates (e.g., recursive copy, mirroring, retries on failure).

Common Options:

  • /S: Copies subdirectories, but skips empty ones.
  • /E: Copies all subdirectories, including empty ones.
  • /Z: Copies files in restartable mode, which allows you to resume copying if the operation is interrupted.
  • /MIR: Mirrors a directory tree (deletes files in the destination if they no longer exist in the source).
  • /MT[:N]: Enables multi-threaded copying, where N specifies the number of threads (default is 8).
  • /R:N: Specifies the number of retries if the copy fails (default is 1 million).
  • /W:N: Specifies the wait time between retries (default is 30 seconds).
  • /COPY:flags: Specifies the attributes to copy (e.g., /COPY:DATS copies data, attributes, timestamps, and security permissions).
  • /LOG:file: Writes the copy results to a log file.

robocopy

Useful Examples

Command Action
robocopy C:\SourceFolder D:\DestinationFolder /S Basic directory copy (including subdirectories).
robocopy C:\SourceFolder D:\DestinationFolder /MIR Mirror directories (including deleting files no longer in the source).
robocopy C:\SourceFolder D:\DestinationFolder /Z Enables resume mode. If the operation is interrupted, it can resume copying from where it left off.
robocopy C:\SourceFolder D:\DestinationFolder /MT:16 Copy files with multi-threading (for speed). 16 threads in this case.

4. del

The del command in Command Prompt is used to delete one or more files from a directory. It is a straightforward command, but you should be cautious when using it. Files deleted with del are permanently removed and do not go to the Recycle Bin.

Typing del file.txt will delete the file named file.txt from the current directory.

Basic Syntax: del [drive:][path]filename [/options]

  • [drive:][path]filename: Specifies the file or files you want to delete.
  • /options: Parameters that control the functionality of del command.

Common Options:

  • /P: Prompts for confirmation before deleting each file.
  • /F: Forces deletion of read-only files.
  • /S: Deletes specified files from all subdirectories (recursive delete).
  • /Q: Quiet mode, does not ask for confirmation before deleting files.
  • /A:[attributes]: Deletes files based on attributes like read-only, hidden, system, or archive.

del

Useful Examples

Command Action
del C:\Users\Reyan\Documents\file.txt Delete a single file.
del *.txt This deletes all .txt files in the current directory.
del C:\Users\Reyan\Documents\*.txt /S Deletes all .txt files in C:\Users\Reyan\Documents and all its subdirectories.
del C:\Users\Reyan\Documents\*.log /A:H This deletes hidden .log files.

5. ren (or rename)

Renaming files or directories is a common need, and the ren (short for rename) command simplifies this task. By entering ren oldname.txt newname.txt, you can change the name of the specified file quickly.

Basic Syntax: ren [drive:][path]filename1 filename2

  • Filename1: The current name of the file or directory.
  • Filename2: The new name for the file or directory.

ren

Useful Examples

Command Action
ren report.txt summary.txt Renames the file report.txt to summary.txt in the current directory.
ren C:\Users\Reyann\OldFolder NewFolder This renames the folder OldFolder to NewFolder in the C:\Users\Reyan directory.
ren *.txt *.bak Rename multiple files using wildcards.
ren “old report.txt” “new report.txt” When renaming files or directories that contain spaces, you must enclose the old and new names in quotes.

6. subst

The subst command maps a directory to a virtual drive letter. For example, typing subst X: C:\Users\Reyan\Projects assigns the Projects folder to the drive letter X. You can quickly access this folder by typing X: instead of navigating through the full path.

Basic Syntax: subst [drive:] [path]

  • [drive:]: Specifies the drive letter you want to assign to the folder.
  • [path]: Specifies the path of the folder you want to map to the drive letter.

subst

Useful Examples

Command Action
subst Z: C:\Users\Reyan\Documents\Work This maps the folder C:\Users\Reyan\Documents\Work to the virtual drive Z:. You can now access the contents of Work by navigating to Z:.
subst Z: /d Remove a Virtual Drive Mapping.
subst X: \\NetworkShare\SharedFolder Map a Network Folder to a Drive Letter.

7. attrib

You can use the attrib command in Command Prompt to display or change file attributes. File attributes are metadata associated with files and directories that define certain properties and behaviors. Using attrib, you can view or modify attributes like read-only, hidden, system, and archive.

Basic Syntax: attrib [+attribute | -attribute] [drive:][path]filename [/S [/D]]

  • +attribute: Adds the specified attribute to the file(s).
  • -attribute: Removes the specified attribute from the file(s).
  • [drive:][path]Filename: Specifies the file or directory for which you want to modify or view attributes.
  • /S: Applies the operation to all matching files in the specified directory and all its subdirectories.
  • /D: Applies the operation to directories as well.

Common Attributes:

  • R: Read-only attribute. The file cannot be modified or deleted.
  • A: Archive attribute. Indicates that the file has been changed since the last backup.
  • S: System attribute. Marks the file as a system file that is critical for operating system operation.
  • H: Hidden attribute. The file is not visible in normal directory listings.

attrib

Useful Examples

Command Action
attrib C:\Users\Reyan\Documents\file.txt Displays the current attributes of file.txt in the specified path.
attrib +R C:\Users\Reyan\Documents\file.txt Sets the read-only attribute on file.txt (prevents any modification).
attrib -H C:\Users\Reyan\Documents\file.txt Removes the hidden attribute from file.txt.

8. ftype

The ftype command in Command Prompt displays or modifies file types and their associated programs.

Basic Syntax: ftype [FileType[=[OpenCommandString]]]

  • FileType: Specifies the file type for which you want to display or modify the associated program.
  • OpenCommandString: Specifies the program/command that should be used to open files of the specified type. This is typically the path to the application executable along with any arguments required.

Useful Examples

Command Action
ftype Lists all registered file types and their associated commands/programs.
ftype htmlfile This command displays the current application associated with opening .html files.
ftype jpegfile= Removes the file type association for .jpg files.

Disk Management Commands

1. diskpart

The diskpart command is a powerful tool for managing disk partitions. You can perform various operations like creating, deleting, resizing, and formatting partitions, as well as managing disk properties and drive letters.

Basic Syntax: diskpart

Once you type diskpart and hit enter, a new DiskPart command-line environment will open where you can execute further commands to manage disks.

Common DiskPart Commands:

  • List Disk: Displays a list of all disks on the system.
  • Select Disk <n>: Selects a specific disk to perform operations on (where <n> is the disk number).
  • List Partition: Lists all partitions on the selected disk.
  • Select Partition <n>: Selects a specific partition to perform operations on.
  • Create Partition Primary: Creates a new primary partition on the selected disk.
  • Delete Partition: Deletes the selected partition.
  • Extend: Extends the size of the selected partition.
  • Shrink: Reduces the size of the selected partition.
  • Format: Formats the selected partition.
  • Assign: Assigns a drive letter to the selected volume.
  • Clean: Remove all partition and volume information from a disk.
  • Remove: Removes the drive letter or mount point from the selected volume.
  • List Volume: Lists all volumes on the system.
  • Select Volume <n>: Selects a specific volume to perform operations on.

diskpart

Useful Examples

Command Action
diskpart Launches the DiskPart utility.
list disk Displays all disks available on the system with details such as disk number, size, and status.
select disk 1 Selects disk number 1 for further operations.
select partition 2 Selects partition number 2 for further operations.
create partition primary size=50000 Creates a new primary partition with a size of 50,000 MB (approximately 50 GB) on the selected disk.

2. chkdsk

The chkdsk command scans and repairs file system errors on a disk (needs administrator privileges). It can also fix logical file system errors and verify the integrity of the file system and metadata. By typing chkdsk C:, you can initiate a scan of the C drive to check for issues.

Basic Syntax: chkdsk [volume:] [parameters]

  • [volume:]: Specifies the drive letter or volume to be checked (e.g., C: for the C drive).
  • [parameters]: Specifies additional options and parameters to control the behavior of chkdsk.

Common Parameters:

  • /f: Fixes errors on the disk. If errors are found, chkdsk will attempt to repair them.
  • /r: Locates bad sectors on the disk and recovers readable information. This implies /f as well.
  • /x: Forces the volume to dismount first if necessary. This implies /f and is used when the disk is in use.
  • /v: Displays the name of each file as it is checked. This provides a more detailed output.
  • /scan: Runs an online scan on the volume, which is useful for checking disk issues without unmounting the volume.
  • /spotfix: Performs spot fixes on the volume (available in Windows 8 and later).
  • /b: Clears the list of bad clusters on the volume (available in Windows 8 and later).

chkdsk

Useful Examples

Command Action
chkdsk C: Checks the C: drive for errors without making any changes. It reports any issues but does not fix them.
chkdsk C: /f This checks the C: drive for errors and attempts to fix them.
chkdsk C: /r Checks and repair bad sectors.
chkdsk C: /x Forces the C: drive to be dismounted if necessary before running the check.

3. format

Formatting a disk is often necessary when setting up a new drive or preparing a drive for a different file system. The format command prepares a disk for use by erasing its contents and setting up a file system. For instance, the command format D: starts the process of formatting the D drive.

Basic Syntax: format [drive:] [/FS:file_system] [/V:label] [/Q] [/X] [/R:rate] [/P:passes] [/A:size] [/C] [/I]

  • [drive:]: Specifies the drive letter or volume to be formatted (e.g., C:).
  • /FS:file_system: Specifies the file system to use (e.g., NTFS, FAT32, exFAT).
  • /V:label: Assigns a volume label or name to the disk.
  • /Q: Performs a quick format, which does not scan for bad sectors.
  • /X: Forces the volume to dismount if necessary. This implies /Q.
  • /R:rate: Specifies the rate of the read and write operations for the format (used with certain file systems).
  • /P:passes: Specifies the number of times to overwrite the entire volume (used for secure formatting).
  • /A:size: Specifies the allocation unit size (e.g., 4096).
  • /C: Compresses the contents of the volume (available in NTFS).
  • /I: Performs a more thorough formatting operation, which may take longer.

Useful Examples

Command Action
format D: /FS:NTFS Formats the D: drive using the NTFS file system. The command will prompt you to confirm that you want to erase all data on the drive.
format E: /Q Performs a quick format of the E: drive.
format F: /FS:FAT32 /V:BackupDrive Formats the F: drive with the FAT32 file system and assigns the volume label BackupDrive.
format H: /FS:NTFS /A:4096 This formats the H: drive with the NTFS file system and sets the allocation unit size to 4096 bytes.

4. fsutil

The fsutil command provides a wide range of functionalities related to disk and file system management. It is a powerful utility that allows advanced users and administrators to manage and configure file systems, disks, and volumes. You can use it for creating hard links, managing quotas, setting the dirty bit, working with sparse files, and more.

Basic Syntax: fsutil [command] [parameters]

Common fsutil Subcommands:

  • fsutil behavior: Configures file system behavior.
  • fsutil dirty: Manages the dirty bit on volumes, which is used to indicate that a volume needs checking.
  • fsutil file: Performs tasks related to files, such as querying or setting hard links and sparse files.
  • fsutil fsinfo: Provides information about drives, volumes, and file systems.
  • fsutil hardlink: Creates hard links between files.
  • fsutil reparsepoint: Manages reparse points, which are used by NTFS for symbolic links and junctions.
  • fsutil quota: Manages disk quotas on NTFS volumes.
  • fsutil sparse: Manages sparse files, which efficiently store large amounts of data.
  • fsutil volume: Manages tasks related to volumes, such as dismounting or querying volume information.

fsutil

Useful Examples

Command Action
fsutil behavior set disable8dot3 1 This command disables the creation of 8.3 filenames on all volumes.
fsutil dirty query C: Checks if the C: volume is marked as “dirty,” meaning it needs to be checked with chkdsk during the next boot.
fsutil fsinfo volumeinfo C: Query File System Information.
fsutil volume diskfree D: Displays the amount of total, free, and available disk space on the D: volume.

5. defrag

The defrag command optimizes disk performance by defragmenting files and consolidating (reorganizing) fragmented data. Enter defrag C: to initiate the defragmentation process for the C drive.

Basic Syntax: defrag [volume] [parameters]

  • [volume]: Specifies the drive or partition to defragment (e.g., C:).
  • [parameters]: Options to control the behavior of the defrag command.

Common Parameters:

  • /A: Performs an analysis of the drive without actually defragmenting it. This gives a report on the current fragmentation level.
  • /C: Defragments all volumes on the system.
  • /E: Defragments all volumes except the specified ones.
  • /X: Performs free space consolidation to reduce fragmentation of future files.
  • /H: Runs the defragmentation process at a higher priority.
  • /M: Runs the defragmentation in parallel on multiple volumes.
  • /O: Optimizes SSDs by running a Trim operation (specifically for SSDs).
  • /T: Tracks the operation and reports progress over time.
  • /V: Provides verbose output with detailed information about the defragmentation process.
  • /U: Displays the progress of the operation on the screen.

defrag

Useful Examples

Command Action
defrag C: /A Analyze the fragmentation of a drive.
defrag D: Defragment a specific drive.
defrag E: /V Defragment with detailed (verbose) output.

6. cipher

The cipher command manages encryption on NTFS volumes. It provides options for encrypting or decrypting files and directories using the Encrypting File System (EFS). You can encrypt files to protect sensitive data from unauthorized access.

Basic Syntax: cipher [options] [file or folder]

Common Options:

  • /E: Encrypts the specified files or folders.
  • /D: Decrypts the specified files or folders.
  • /S:directory: Performs the operation on all subdirectories within the specified directory.
  • /W:directory: Wipes free space on the disk to prevent data recovery of deleted files.
  • /I: Ignores errors during the encryption or decryption process.
  • /H: Displays hidden or system files when encrypting or decrypting.
  • /K: Creates a new encryption key.

Useful Examples

Command Action
cipher /E C:\SensitiveData\report.txt Encrypt a file.
cipher /E C:\SensitiveData Encrypt a folder.
cipher /D C:\SensitiveData\report.txt Decrypt a file.
cipher /K Create a new encryption key.

System Information And Diagnostics Commands

1. systeminfo

The systeminfo command provides detailed information about a computer’s configuration and operating system. Using systeminfo in the Command Prompt, you can retrieve essential data such as the operating system version, system manufacturer, BIOS version, memory information, and network settings.

Basic Syntax: systeminfo

systeminfo

2. tasklist

The tasklist command displays a list of running processes on the system, including their process IDs (PIDs) and memory usage. Typing tasklist in the Command Prompt outputs a detailed list of all active tasks, providing real-time information about CPU and memory usage.

Basic Syntax: tasklist [options]

Common Options:

  • /S [system]: Specifies the remote system to connect to.
  • /U [username]: Specifies the user context under which the command should run.
  • /P [password]: Specifies the password for the provided user context.
  • /FI [filter]: Displays a set of tasks that match the specified filter.
  • /FO [format]: Specifies the output format (TABLE, LIST, or CSV).
  • /M [module]: Lists tasks that contain the specified DLL module.
  • /SVC: Displays the services associated with each process.
  • /V: Displays detailed task information.
  • /NH: Removes the column header from the output (for use with CSV format).

tasklist

Useful Examples

Command Action
tasklist Display all running processes.
tasklist /S remote_computer_name /U username /P password Display tasks on a remote system.
tasklist /FI “PID eq 1234” Filter processes by PID
tasklist /V Display detailed task information.

3. taskkill

The taskkill command can terminate running processes by either their Process ID (PID) or Image Name (process executable). It is a powerful tool for forcefully ending tasks, especially those that are unresponsive or consuming excessive resources.

Basic Syntax: taskkill [options]

Common Options:

  • /PID [process ID]: Specifies the PID of the process to terminate.
  • /IM [image name]: Specifies the image name (process executable) to terminate.
  • /T: Terminates the specified process and all child processes started by it.
  • /F: Forces the termination of the process. Useful for unresponsive processes.
  • /S [system]: Specifies a remote system where the process is to be terminated.
  • /U [username]: Specifies the username for authentication on a remote system.
  • /P [password]: Specifies the password for authentication on a remote system.
  • /FI [filter]: Applies a filter to select processes based on specific criteria.

 

Useful Examples

Command Action
taskkill /PID 1234 Terminate a process by PID.
taskkill /IM chrome.exe Terminate a process by image name.
taskkill /PID 1234 /F Force termination of a process.
taskkill /IM notepad.exe /T Terminate a process and its child processes.

4. ver

The ver command displays the current version of the Windows operating system. It will display the exact version and build number of their operating system.

Basic Syntax: ver

ver

5. winver

The winver command provides detailed information about the Windows version. It opens a graphical window showing the version of Windows, build number, and service pack details.

Basic Syntax: winver

winver

6. cls

The cls command clears the Command Prompt screen, removing all previous commands and output.

Basic Syntax: cls

7. color

You can change the text and background colors of the Command Prompt window using the color command.

Basic Syntax: color [attr]

  • attr: A two-digit hexadecimal code where the first digit represents the background color and the second digit represents the text (foreground) color.

color

8. date

The date command displays or changes the system date. Typing date shows the current system date and prompts users to enter a new one if desired.

Basic Syntax: date [/T | date]

Use /T switch to just output the current date without prompting for a new date.

date

9. doskey

The doskey utility improves the command line input with features like command history, command-line editing, and the ability to create and manage macros.

Basic Syntax: doskey [macroName=commandText]

doskey

10. exit

The exit command closes the Command Prompt window. Typing exit immediately terminates the current command-line session and returns the user to the desktop or previous application.

Basic Syntax: exit

11. whoami

The whoami command in Command Prompt is a straightforward yet powerful tool for identifying the current user account. When you type whoami and press Enter, it displays the username and domain of the account currently logged into the system.

Basic Syntax: whoami

whoami

Network And Internet Commands

1. ipconfig

The ipconfig command displays the current IP configuration of a Windows computer. By typing ipconfig, you can receive information about IP address, subnet mask, and default gateway.

Basic Syntax: ipconfig [options]

Common Options And Parameters:

  • /all: Displays detailed information about all network interfaces.
  • /release: Releases the current DHCP-assigned IP address for all network adapters.
  • /renew: Renews the DHCP-assigned IP address for all network adapters.
  • /flushdns: Flushes the DNS resolver cache.
  • /registerdns: Refreshes all DHCP leases and re-registers DNS names.
  • /displaydns: Displays the contents of the DNS resolver cache.
  • /showclassid: Displays the DHCP class ID for a specified adapter.
  • /setclassid: Configures the DHCP class ID for a specified adapter.

ipconfig

2. ping

Ping is a very useful diagnostic tool to test the reachability of a host on a network and measure the round-trip time for messages sent from the originating host to a destination computer. By typing ping google.com, you can send packets to Google’s servers to verify network connectivity by measuring response time and packet loss.

Basic Syntax: ping [hostname or IP address] [options]

Useful Options:

  • -t: Pings the specified host until interrupted. Useful for continuous monitoring.
  • -n count: Specifies the number of echo requests to send. For example, -n 10 sends 10 requests.
  • -l size: Specifies the size of the payload in bytes. For example, -l 1024 sends a 1024-byte packet.
  • -a: Resolves and displays the hostname of the IP address.
  • -r count: Records the route for count hops. For example, -r 9 traces the route of up to 9 hops.
  • -s count: Specifies the number of seconds to wait between each ping. For example, -s 5 waits 5 seconds between pings.
  • -4: Forces the use of IPv4.
  • -6: Forces the use of IPv6.

ping

Useful Examples

Command Action
ping 8.8.8.8 Pings Google’s public DNS server and measures response times.
ping -t example.com Continuously pings a host until you manually stop (using Ctrl + C).
ping -l 1024 example.com Send ping requests with a payload size of 1024 bytes to example.com.

3. tracert

The tracert command traces the route packets take to reach a destination on a network. For example, tracert www.example.com lets you see a list of all intermediate routers and their response times.

Basic Syntax: tracert [options] [destination]

Useful Options:

  • -d: Displays IP addresses instead of resolving hostnames.
  • -h max_hops: Specifies the maximum number of hops to trace.
  • -w timeout: Sets the timeout (in milliseconds) for each reply.

tracert

Useful Examples

Command Action
tracert example.com Trace the route to a website.
tracert 8.8.8.8 Trace the route to a specific IP address.
tracert -d example.com Trace with IP Addresses Only
tracert -h 15 example.com Limits the number of hops
tracert -w 500 example.com Sets a timeout for replies.

4. netstat

The netstat command provides a snapshot of current network connections and listening ports. When you type netstat in the command prompt, it displays active connections, including the local and remote IP addresses and port numbers.

Basic Syntax: netstat [options]

Common Options:

  • -a: Displays all active connections and listening ports.
  • -n: Shows numerical addresses and port numbers instead of resolving hostnames and service names.
  • -o: Displays the process ID (PID) associated with each connection.
  • -p proto: Shows connections for the specified protocol (e.g., tcp, udp).
  • -r: Displays the routing table.
  • -s: Displays network statistics by protocol.
  • -e: Displays Ethernet statistics, including the number of bytes and packets sent and received.
  • -b: Displays the executable involved in creating each connection or listening port (requires administrative privileges).

netstat

Useful Examples

Command Action
netstat -a Display all active connections and listening ports.
netstat -p tcp

netstat -p udp

Show connections for a specific protocol.
netstat -r Display the routing table.

5. netsh

Using the netsh command, you can view and modify network configurations, troubleshoot network issues, and manage network adapters, firewall settings, IP addresses, and more.

Basic Syntax: netsh [context] [command] [parameters]

  • Context: Represents the area of networking that you want to work with, such as interface, firewall, wlan, or ipsec.
  • Command: Represents the specific action or operation you want to perform.
  • Parameters: Additional details needed to perform the command.

Common netsh Contexts:

  • netsh interface: Manage network interfaces and IP addresses.
  • netsh wlan: Manage wireless networks.
  • netsh firewall: Manage firewall settings (replaced by advfirewall in newer versions).
  • netsh advfirewall: Configure advanced firewall settings.
  • netsh ipsec: Configure IP security policies.
  • netsh winsock: Manage Winsock settings.

netsh

Useful Examples

Command Action
netsh interface ip show config Display the current IP configuration of all network interfaces.
netsh interface ip set address name=”Local Area Connection” static 192.168.1.100 255.255.255.0 192.168.1.1 Configures a network interface with a static IP address.
netsh interface ip set address name=”Wi-Fi” source=dhcp Enables DHCP on a network interface.
netsh wlan export profile key=clear folder=C:\wifi-backup Exports all saved wireless profiles to an XML file.

6. ftp

The ftp command starts a file transfer protocol session so that you can transfer files between your computer and a remote server. It provides an interactive interface for managing FTP sessions and you can easily upload, download, and manage files on an FTP server.

Basic Syntax: ftp [hostname or IP address]

Key FTP Commands:

Once you are connected to the FTP server, you can use various FTP subcommands to navigate directories and transfer files.

  • open [hostname]: Opens a connection to the specified FTP server.
  • ls or dir: Lists the files and directories in the current directory on the remote server.
  • cd [directory]: Changes the directory on the remote server.
  • lcd [directory]: Changes the local directory on your computer.
  • get [filename]: Downloads a file from the server to your local machine.
  • put [filename]: Uploads a file from your local machine to the remote server.
  • mget [file1 file2 …]: Downloads multiple files from the server.
  • mput [file1 file2 …]: Uploads multiple files to the server.
  • bye or quit: Closes the connection and exits the FTP session.
  • delete [filename]: Deletes a file on the remote server.
  • rmdir [directory]: Removes a directory on the remote server.
  • mkdir [directory]: Creates a directory on the remote server.
  • binary: Switches to binary mode for transferring files (used for non-text files, like images, executables).
  • ascii: Switches to ASCII mode for transferring text files (default mode).

7. arp

The arp command manages the Address Resolution Protocol (ARP) cache, which maps IP addresses to MAC addresses. By typing.

The arp (Address Resolution Protocol) command in Command Prompt is useful for viewing and modifying the ARP cache on a local computer. The ARP cache stores mappings of IP addresses to MAC (Media Access Control) addresses on a local network. Simply enter arp -a to view the current ARP table with the IP-to-MAC address mappings.

Basic Syntax: arp [-a] [-g] [-d] [-s] [IP address] [MAC address]

Parameters and Options:

  • -a or -g: Displays the ARP table entries for all interfaces.
  • -d [IP address]: Deletes a specific entry from the ARP table.
  • -s [IP address] [MAC address]: Adds a static entry in the ARP cache.
  • [Interface]: Specify the interface for which you want to see ARP entries.

arp

Useful Examples

Command Action
arp -a Displays the current ARP cache for all interfaces.
arp -a 192.168.1.10 View ARP cache for a specific interface.
arp -s 192.168.1.100 00-1a-2b-3c-4d-5e Sdds a static ARP entry that manually maps an IP address to a MAC address.

8. nslookup

The nslookup command queries DNS servers for information related to domain names, such as IP addresses, MX records, and other DNS records.

Basic Syntax: nslookup [domain name or IP address]

Useful Examples

Command Action
nslookup www.example.com Finds the IP address of a domain.
nslookup 93.184.216.34 Finds the domain name for an IP address (reverse lookup).
nslookup -type=mx example.com Finds Mail Exchange (MX) records for a domain.

9. route

Using the route command, you can view, modify, or configure the routing table on a Windows computer. The routing table contains rules that dictate how network traffic is directed across networks. It specifies routes (paths) for sending data to particular network destinations.

Basic Syntax: route [command] [parameters]

Common Commands:

  • Print: Displays the current routing table.
  • Add: Adds a new route to the routing table.
  • Delete: Deletes a route from the routing table.
  • Change: Modifies an existing route in the routing table.

Useful Parameters:

  • Destination: The destination IP address or network for which the route is defined.
  • Mask: The subnet mask associated with the destination network (required when adding a route).
  • Gateway: The IP address of the gateway or next-hop router.
  • Metric: A number that indicates the cost of the route; lower numbers have higher priority.

route

Useful Examples

Command Action
route add 192.168.2.0 mask 255.255.255.0 192.168.1.1 Adds a new route to a specific destination network via a specified gateway.
route delete 192.168.2.0 Deletes a specific route from the routing table.
route change 192.168.2.0 mask 255.255.255.0 192.168.1.254 Changes the gateway for an existing route.

10. hostname

The hostname command displays the name of the computer or device on the network. Simply type hostname and you can quickly identify the local machine’s network name.

Basic Syntax: hostname

hostname

11. pathping

The pathping command combines the functionality of ping and tracert to diagnose network issues. It helps identify packet loss, latency, and network issues by tracing the route between your computer and a destination host while also performing a detailed analysis of the path.

Basic Syntax: pathping [destination] [-n] [-h max_hops] [-g host-list] [-p period] [-q num_queries] [-w timeout] [-4] [-6]

  • destination: The target host (IP address or domain name) you want to test.
  • -n: Prevents the resolution of hostnames (displays IP addresses only).
  • -h [max_hops]: Specifies the maximum number of hops to search for the target (similar to tracert).
  • -g [host-list]: Specifies the loose source route along the host list.
  • -p [period]: Waits for a specified period (in milliseconds) between each ping.
  • -q [num_queries]: Defines the number of pings to send to each hop.
  • -w [timeout]: Specifies the wait time for each reply (in milliseconds).
  • -4: Forces the use of IPv4.
  • -6: Forces the use of IPv6.

pathping

12. getmac

You can retrieve the MAC (Media Access Control) addresses of network interfaces on a computer using the getmac command.

Basic Syntax: getmac [options]

Parameters:

  • /s [System]: Specifies the remote system to retrieve the MAC address from.
  • /u [Domain\User]: Runs the command with the account permissions of the specified user.
  • /p [Password]: Specifies the password for the specified user.
  • /v: Displays detailed output, including transport name.
  • /fo [Format]: Specifies the format of the output. Possible values are TABLE, LIST, or CSV.
  • /nh: Omits the column headers in the output (used with the TABLE or CSV formats).

getmac

13. nbtstat

If you have any issues with NetBIOS names, you can use the nbtstat command to display NetBIOS over TCP/IP statistics.

Basic Syntax: nbtstat [options]

Common Options:

  • -a [RemoteName]: Displays the NetBIOS name table of a remote computer, identified by its name.
  • -A [IP address]: Displays the NetBIOS name table of a remote computer, identified by its IP address.
  • -c: Displays the contents of the NetBIOS name cache, which maps NetBIOS names to IP addresses.
  • -n: Displays the NetBIOS name table for the local computer.
  • -r: Displays statistics of how many NetBIOS names have been resolved using broadcasts and how many through WINS (Windows Internet Name Service).
  • -R: Purges and reloads the NetBIOS name cache.
  • -S: Displays the NetBIOS sessions table, showing all the current connections (by IP address).
  • -s: Similar to -S, but resolves the IP addresses into hostnames for active sessions.
  • -RR: Sends a Name Release request to WINS and then refreshes the NetBIOS names.

nbtstat

14. telnet

The telnet command in Command Prompt is used to communicate with remote devices or servers using the Telnet protocol. Telnet is a text-based network protocol that allows a user to establish a connection with another computer over a TCP/IP network, usually to troubleshoot or remotely manage a device.

Basis Syntax: telnet [hostname or IP address] [port]

  • Hostname Or IP Address: The remote server you want to connect to.
  • Port: The port number of the service you want to access (optional, defaults to port 23 for Telnet).

System Management And Control Commands

1. sc

The sc command manages Windows services directly from the Command Prompt. It provides control over creating, configuring, starting, stopping, and deleting services. Very useful for system administrators.

Basic Syntax: sc [command] [service name] [options]

Common sc Commands:

  • query: Displays the status of services.
  • start: Starts a service.
  • stop: Stops a running service.
  • create: Creates a new service.
  • delete: Deletes an existing service.
  • config: Configures an existing service (e.g., setting startup type).
  • qc: Queries the configuration of a service.
  • failure: Configures the actions to take if a service fails.

sc

Useful Examples

Command Action
sc query wuauserv Checks the status of the Windows Update service (wuauserv).
sc start [service name] Start a service.
sc create [service name] binPath= [path to the service executable] Create a new service.

2. wmic

The Windows Management Instrumentation Command-line or wmic is a robust method for interacting with system components. For instance, the command wmic os get name retrieves the operating system name while wmic cpu get name returns information about the processor.

Basic Syntax: wmic [alias] [where clause] [verb]

  • Alias: Represents a WMI class that refers to a specific system object (e.g., process, os, diskdrive, cpu).
  • Where Clause: Optional. Used to filter queries (e.g., to limit results based on a specific condition).
  • Verb: Specifies an action to perform (e.g., get, call, list).

wmic

Useful Examples

Command Action
wmic os get caption,version,buildnumber Gets basic OS information.
wmic computersystem get model,manufacturer,name Displays the manufacturer, model, and system name.
wmic cpu get name,numberofcores,maxclockspeed Provides the name of the CPU, number of cores, and maximum clock speed.

3. schtasks

You can use the schtasks command to schedule, manage, and automate tasks in Windows. It allows you to create, delete, configure, and display tasks that can be run automatically at specified times or when certain conditions are met. It is similar to the GUI-based Task Scheduler but provides a command-line interface.

Basic Syntax: schtasks [command] [options]

  • Command: Specifies the action you want to perform (e.g., /create, /delete, /query).
  • Options: Defines the details of the task, such as the time, date, and conditions for execution.

Common schtasks Commands:

  • /create: Creates a new scheduled task.
  • /delete: Deletes a scheduled task.
  • /query: Displays information about scheduled tasks.
  • /change: Changes properties of an existing task.
  • /run: Runs a scheduled task immediately.
  • /end: Stops a running task.
  • /show: Displays details of a specific task.

schtasks

4. powercfg

The powercfg is a powerful tool for managing and configuring power settings in Windows. It allows you to control power plans, configure hibernation, generate reports, and troubleshoot power-related issues on your system.

Basic Syntax: powercfg [options]

powercfg

Useful Examples

Command Action
powercfg /list Lists all power schemes.
powercfg /setactive SCHEME_MIN Sets the system to the High Performance plan.
powercfg /batteryreport This generates a report called battery-report.html in the current directory.

5. bcdedit

The bcdedit command edits the Boot Configuration Data (BCD) store, which controls how the system boots. Using this command, you can modify boot settings and troubleshoot issues related to startup.

Basic Syntax: bcdedit [options] [parameters]

bcdedit

6. driverquery

The driverquery command in Command Prompt displays a list of all the drivers currently installed on your Windows system. It provides detailed information about each driver, including the driver name, module name, display name, driver type, and date.

Basic Syntax: driverquery [options]

driverquery

Useful Examples

Command Action
driverquery Quick overview of drivers.
driverquery /v Lists all drivers with detailed information.
driverquery /v /fo csv > drivers.csv Exports driver information to a CSV file.

7. eventvwr

The eventvwr command opens the Event Viewer, which logs system, security, and application events.

Basic Syntax: eventvwr

eventvwr

8. shutdown

The shutdown command in Command Prompt allows you to shut down, restart, log off, or hibernate a local or remote computer. This command is useful, especially for administrators, for managing multiple computers in a networked environment and to perform remote shutdowns or restarts.

Basic Syntax: shutdown [options]

Common Switches:

  • /i: Opens the graphical user interface (GUI) for shutdown, where you can manage shutdowns for local and remote computers.
  • /c: Allows you to add a comment to the shutdown process (useful for documentation).
  • /p: Shuts down the local computer immediately, without warning or delay.
  • /h: Puts the computer into hibernation mode (if supported and enabled).

shutdown

Useful Examples

Command Action
shutdown /s /t 30 /c “Shutting down for scheduled maintenance.” This will shut down the computer after a 30-second delay, displaying the comment to the user.
shutdown /p Immediately shuts down the computer without any prompts or delay.
shutdown /i Opens the Shutdown GUI, where you can choose multiple remote computers for shutdown or restart.

Text And File Manipulation Commands

1. type

Using the type command, you can display the contents of a file directly in the Command Prompt window. By typing type filename.txt, you can quickly view the text within this file without opening it in a separate editor.

Basic Syntax: type [filename]

type

2. find

The find command searches for specific text within files. If you type find “searchtext” filename.txt, you can locate occurrences of “searchtext” in filename.txt.

Basic Syntax: find [options] “search_string” [file(s)]

find

3. findstr

For more advanced text searching capabilities, you can use the findstr command instead of find.

Basic Syntax: findstr [options] “search_string” [file(s)]

findstr

Command Action
findstr “example” file.txt Sear

ch for a string in a file.

findstr /i “example” file.txt Use the /i option to perform a case-insensitive search.
findstr /r “ex.*ple” file.txt Search using regular expressions.

4. more

The more command displays the contents of a file one screen at a time.

Basic Syntax: more [filename]

more

5. fc

The fc command compares two files and displays the differences between them. By typing fc file1.txt file2.txt, you can see which lines differ between file1.txt and file2.txt.

Basic Syntax: fc [options] file1 file2

fc

6. echo

The echo command displays messages or outputs text to the console. If you type echo Hello, World!, the Command Prompt will print “Hello, World!” to the screen. This command is commonly used in batch files to provide feedback or guide users through automated processes.

Basic Syntax: echo [message]

echo

Useful Examples:

Command Action
echo Hello, World! Displays the message “Hello, World!” on the screen.
echo This is a new line >> file.txt Appends the text “This is a new line” to file.txt.
echo The current date is %DATE% Display the current date using the DATE environment variable.

7. set

The set command manages (display, set, or remove) environment variables in the Command Prompt. For instance, set PATH=C:\Program Files\Java\jdk1.8.0_261\bin;%PATH% updates the PATH variable to include the Java Development Kit.

Basic Syntax: set [variable=[value]]

set

8. clip

The clip command in Command Prompt allows you to copy the output of commands directly to the Windows clipboard. This can be useful when you need to capture and reuse the output from the command line, such as saving it to a document or pasting it elsewhere.

Basic Syntax: [command] | clip

clip

Useful Examples

Command Action
dir | clip Copies directory listing to clipboard.
type file.txt | clip Copies the contents of file.txt to the clipboard.
find “ERROR” logfile.txt | clip Searches for the word “ERROR” in logfile.txt and copies all matching lines to the clipboard.

Advanced Commands (For Power Users)

1. assoc

The assoc command in Command Prompt allows you to display or change the file associations on a Windows system.

Basic Syntax: assoc [fileExtension=[fileType]]

assoc

Command Action
assoc Displays all file associations.
assoc .txt=mytextfile Associates .txt with a custom file type.
assoc .bak= Removes the association for .bak files.

2. comp

The comp command compares the contents of two files or sets of files byte-by-byte. This comparison method is ideal for verifying backups, code revisions, or configurations as comp command compares files down to the smallest detail.

Basic Syntax: comp [file1] [file2] [/d] [/a] [/l] [/n=number]

Parameters:

  • file1: The first file or set of files to compare.
  • file2: The second file or set of files.
  • /d: Compares files as binary data (byte by byte comparison).
  • /a: Compares files as text, displaying differences in ASCII characters.
  • /l: Displays the location (line number) of any differences.
  • /n=number: Compares only the first number lines of the files.

3. title

You can change the title of the Command Prompt window using the title command in CMD.

Basic Syntax: title [string]

title

4. compact

The compact command manages file and directory compression on NTFS file systems. It allows users to reduce disk space usage without creating compressed file formats like .zip or .rar.

Basic Syntax: compact [parameters] [file_name | directory_name]

Key Parameters:

  • /c: Compresses the specified file(s) or directory.
  • /u: Uncompresses the specified file(s) or directory.
  • /s: Performs the operation on all subdirectories within a directory.
  • /a: Displays hidden and system files.
  • /i: Ignores errors during the operation.
  • /f: Forces compression or decompression on all files, even if they are already in the desired state.
  • /q: Reports only the most essential information (quiet mode).

compact

Leave a Reply

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