Windows Command Line Cheat Sheet PDF Hackr - Io
Windows Command Line Cheat Sheet PDF Hackr - Io
Scroll through this cheat sheet to see Windows command line commands by category.
Net Users
Net user allows you to add, remove, and alter the user accounts via command prompt. You can
simply execute the command on various systems, such as Windows, including Windows 10,
Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server Operating Systems, and
some older versions of Windows.
Syntax:
Where:
● net user: You can run “net user” alone without the option to check the list of every active
or inactive user for that specific computer.
● username: A username can be 20 characters long, and you can add or remove the
username.
● password: You can use this option to change an existing password or assign a new one
while creating a new username. This command will also tell you the minimum characters
required for a password.
● *: You can use this instead of a password that forces you to enter the password in the
Command Prompt window once you hit the net user command.
● /add: This command adds a new username on the system.
● options: These are the additional Net User Command Options that you can use while
executing net user. The next table displays the list of several options available.
● /domain: You can run the command on the current domain controller rather than on the
local computer.
● /delete: This command will remove the specified username.
● /help: You will get detailed information about the net user command.
● /?: This is the standard help command for displaying the command options, mentioned
in the below table.
Options Description
/active:{yes | no} Activates or deactivates the specified user account; default value is yes
date (with /expires Sets or displays the current date in mm/dd/yy or mm/dd/yyyy format
only)
/fullname:"name" Mentions the real name of the person using the account
/homedir:pathname Sets a pathname if you want a home directory other than the default
/passwordchg:{yes | Specifies whether the user can change their password (default is yes)
no}
/passwordreq:{yes | Specifies whether this user is required to have a password at all (default is
no} yes)
Syntax
dir [drive:][path][filename] [/a[[:]attributes]] [/b] [/c] [/d] [/l] [/n] [/o[[:]sortorder]] [/p] [/q] [/r] [/s]
[/t[[:]timefield]] [/w] [/x] [/4]
a = archive files
d = directories
h = hidden files
i = not content indexed files
l = reparse points
r = read-only files
s = system files
v = integrity files
x = no scrub files
You must use (-) as a prefix to the above attributes for excluding some items
with those file attributes from the results.
/b Shows directory information in the "bare" format (only directory name or file
name and extension)
/c Displays file sizes(to disable, use /-c)
/d Displays the folders and file names with their extensions.
/l Displays all folder and file names in lowercase
/n Provides you a result with columns in the date > time > directory > file size >
file or folder name column structure. Being the default behavior, you need to
use /-n to create columns in the file or folder name > directory > file size > date
> time order.
/o Specifies the sort order for the results. Without any option, /o will list the
directories first, followed by files, in alphabetical order. You can use this option
with one or more of the following values:
/w Shows the results in "wide format" that are limited to just folders and file
names with their extensions
/x Shows the "short name" equivalent for files whose long names don't comply
with non-8dot3 rules
/4 Changes format to 4-digit years
Below are some more commands that will let you move through the directories and perform
actions.
Command Description
cd\ Takes you to the top of the directory tree
cd.. Takes you one folder up
dir Lists all the files and content, including folders contained
along with some details about each of them
mkdir [folder_name] Creates a new folder in the current directory
File management
Command Description
These commands list file attributes:
replace
syntax- REPLACE Path/files– Indicates the source files, accepts wildcards.
[Drive:][path]Source path2– Provides the destination folder, default current drive, and
Files [Drive:][path2] directory as the destination
[/A] [/P] [/R] [/W] /A– Includes all the missing files
/P– Provides the prompt for confirmation for each file
REPLACE /R– Replaces even “read-only: file
[Drive:][path]Source /S– Includes all subfolders of the destination
Files [Drive:][path2] /W– Waits/pauses, or Inserts a floppy disk
[/S] [/P] [/R] [/W] [/U] /U– Updates only files that are older than the source
rmdir / rd deletes a directory
rmdir / rd
syntax- RMDIR [/S] /S Removes all directories and files in the specified directory in
[/Q] [drive:]path addition to the directory itself
RD [/S] [/Q] /Q Specifies the quiet mode. There is not need to ask whether to
[drive:]path delete a specific directory tree with /S
tree
syntax- TREE
[d:][path] [/A][/F] Shows the folder structure graphically (tree-like)
type file_name
more file_name Shows the content of text files
robocopy Mirrors a directory tree
SOURCE_FOLDER
DESTINATION_FO
LDER /mir
robocopy "C:\data"
"\\192.168.0.10\C$\
data" /mir
robocopy d: g: /mir
robocopy more
edit Prompts file editing
FC These commands compare two or more files:
syntax- FC [/A] [/C]
[/L] [/LBn] [/N]
[/OFF[LINE]] [/T] /A Displays only the first and last lines for each set of differences.
[/U] [/W] [/nnnn] /B Perform a binary comparison
[drive1:][path1]filena /C Disregards the case of letters
me1 /L Compares the files as ASCII text
[drive2:][path2]filena /LBn Sets the maximum consecutive mismatches to the specified
me2 number of lines
FC /B /N Displays the line numbers (ASCII comparison)
[drive1:][path1]filena /OFF[LINE] Does not skip files with an offline attribute set
me1 /T Doesn’t expand tabs to spaces
[drive2:][path2]filena /U Compares files as UNICODE text files
me2 /W Compresses the white space for comparison
/nnnn Mentions the number of consecutive lines that must match after a
mismatch
Network
Command Description
ipconfig /all Shows the complete information about the network configuration
syntax- ipconfig
[/(all/release/renew/flushd /release [adapter] Releases the IP address for the mentioned adapter
ns/registerdns/displaydns/ /renew [adapter] Renews the IP address for the mentioned adapter
showclassid/setclassid] /flushdns Purges the DNS Resolver cache
/registerdns Refreshes all DHCP leases and re-register DNS names.
/displaydns Shows contents of the DNS Resolver Cache
/showclassid adapter Shows all the DHCP class IDs allowed for the
adapter
/setclassid adapter [classid] Modifies the DHCP class id.
ping The ping command allow you to test the ability of the source computer if it is
syntax- ping [-t] [-a] [-n reachable to the specified destination computer.
count] [-l size] [-f] [-i TTL]
[-v TOS] [-r count] [-s t Pings the target
count] [-w timeout] [-R] [-S a Resolves the hostname of an IP address target
srcaddr] [-p] [-4] [-6] target n Sets ICMP Echo Requests number to send, from 1 to 4294967295
[/?] -l Sets the size of the echo request, in bytes from 32 to 65,527
-f Prevents ICMP Echo Requests from being fragmented by routers before
reaching the target
-w timeout Specifies the timeout value while executing the ping command
and adjusts the amount of time, in milliseconds
-R Tells the ping command to trace the round trip path.
-S srcaddr Specifies the source address
-p Pings a Hyper-V Network Virtualization provider address.
-4 Forces the ping command to use IPv4 only
-6 Forces the ping command to use IPv6 only
target specifies the destination to ping, either an IP address or a hostname
tracert The tracert command show the complete information about a packet’s path
syntax- tracert [-d] [-h from the computer or device:
MaxHops] [-w TimeOut]
[-4] [-6] target [/?] -d Prevents the tracert from resolving IP addresses to hostnames,
-h maxhops Mentions the maximum number of hops in the search for the
target
-w timeout Specifies the time, in milliseconds, before each reply timeouts
nslookup root Changes the default server to the server for the
root of the DNS domain namespace
nslookup server Changes the default server to the mentioned DNS
domain.
nslookup set Changes the configuration settings that affect how
lookups function.
nslookup set all Displays the current values of the configuration
settings.
nslookup set class Changes the query class that specifies the protocol
group of the information
nslookup set querytype Changes the resource record type for the
query
nslookup set recurse Specifies the DNS name server to query other
servers if it doesn't have the information
nslookup set retry Specifies the number of retries
nslookup set root Changes the name of the root server used for queries
nslookup set search Appends the DNS domain names in the DNS domain
search list to the request until an answer is received
nslookup set srchlist Changes the default DNS domain name and search
list
nslookup set timeout Changes the initial number of seconds to wait for a
reply to a request
nslookup set type Changes the resource record type for the query
nslookup set vc Prompts you to use or not use a virtual circuit when
sending requests to the server
GETMAC
GETMAC /s
computername – Get
MAC Address remotely by
Computer Name
GETMAC /s 192.168.1.1 –
Get MAC Address by IP
Address
GETMAC /s localhost – These commands provide the MAC Address of your local computer along
Get local MAC Address with the query remotely by computer name or IP Address.
The TFTP command will transfer the files to and from a remote computer,
typically a computer running UNIX, that is running the Trivial File Transfer
Protocol (tftp) service or daemon.
-i Mentions the binary image transfer mode, where the file is transferred in
one-byte units. Without using the -i option, the file is transferred in ASCII
mode.
System-Related Information
Command Description
date
syntax- DATE
DATE mm-dd-yy Shows current date settings and allows you to reset the date
time time lets you show or edit the system time. Without any parameters, time
syntax- time [/t | displays the current system time and prompts you to enter a new time.
[<HH>[:<MM>[:<S
S>]] [am|pm]]] <HH>[:<MM>[:<SS>[.<NN>]]] [am | pm] allows you to set the system
time to the new time specified, where HH hours (required), MM minutes, and
SS seconds. NN specifies the hundredths of a second. Use (:) to separate
values for HH, MM, and SS. SS and NN must be separated with a period
(.).If am or pm isn't specified, time uses the 24-hour format by default.
/t Displays the current time without prompting you for a new time
/? Displays help at the command prompt
DRIVERQUERY is used by an administrator to display a list of installed
device drivers.
[/x | /h] <filename> Saves the report in either XML (/x) or HTML (/h)
format at the location with the name mentioned in the filename parameter.
You cannot use this option with /u, /p, /r, /v, or /z
/logoff Logs off once the Group Policy settings are updated
boot Restarts a computer after the Group Policy settings are applied
/sync Synchronizes the next foreground policy application
GPUPDATE /? Shows the Help at the command prompt
Disk Management
Command Description
CHKDISK gets details of a specified disk and repairs or recovers data on
the drive if required.
volume: This is the drive letter of the partition for which you want to
check for errors.
/L:size Changes the size (in KB) of the log file. The default log file size for
chkdsk is 65536 KB.
/perf Runs faster by using more system resources. It must be used with
/scan
convert mbr command Converts an empty basic disk with the GUID
Partition Table (GPT) partition style into a basic disk with the master boot
record (MBR) partition style
DISKPART The DISKPART command help you manage your computer's drives. It
syntax- diskpart comes with the following parameters:
<parameter>
active Marks the disk's partition with focus, as active
add Lets you mirror the simple volume with focus to the specified disk.
assign Lets you assign a drive letter or mount point to the volume with
focus
attach vdisk Lets you attach a virtual hard disk (VHD) so that it appears on
the host computer as a local hard disk drive
attributes Lets you display, set, or clear the attributes of a disk or
volume
automount Allows you to enable or disable the automount feature
break Breaks the mirrored volume with focus into two simple volumes.
clean Removes any and all partition or volume formatting from the disk
with focus
compact vdisk Compacts the physical size of a dynamically
expanding virtual hard disk (VHD) file
convert Converts the file allocation table (FAT) and FAT32 volumes to
the NTFS file system, leaving existing files and directories intact
create you can create a partition on a disk, a volume on one or more disks,
or a virtual hard disk (VHD)
Delete Lets you delete a partition or a volume
detach vdisk Lets you stop the selected virtual hard disk (VHD) from
appearing as a local hard disk drive on the host computer
detail Shows you the information about the selected disk, partition,
volume, or virtual hard disk (VHD)
exit Exits the diskpart command interpreter
expand vdisk Lets you expand a virtual hard disk (VHD) to the size that you
specify
extend- Lets you expand the volume or partition with focus, along with
its file system, into free (unallocated) space on a disk
filesystems Shows the information about the current file system of the
volume with focus and lists the file systems that are supported for formatting
the volume
Format Lets you format a disk to accept Windows files
gpt Lets you assign the gpt attribute(s) to the partition with focus
on basic GUID partition table (gpt) disks
help Shows a list of the available commands or detailed help
information on a specified command
import Imports a foreign disk group into the disk group of the local
computer
inactive Lets you mark the system partition or boot partition with focus
as inactive on basic master boot record (MBR) disks
list Shows a list of disks, of partitions in a disk, of volumes in a
disk, or of virtual hard disks (VHDs)
merge vdisk Merges a differencing virtual hard disk (VHD) with its
corresponding parent VHD
offline Takes an online disk or volume to the offline state
online Takes an offline disk or volume to the online state
recover Lets you refresh the state of all disks in a disk group, attempt
to recover disks in an invalid disk group, and resynchronize mirrored
volumes and RAID-5 volumes that have stale data
/LogSize::<size> NTFS only. Specifies the size for NTFS log file in
kilobytes. The minimum supported size is 2MB, so specifying a size smaller
than 2MB will result in a 2MB log file. Zero indicates the default value, which
generally depends on the volume size.
/NoRepairLogs NTFS only. Disables the NTFS repair logs. If the
spotfix flag for chkdsk is specified (i.e. chkdsk /spotfix), this will not work.
FSUTIL Lets you perform tasks that are related to file allocation table (FAT) and
NTFS file systems, such as managing reparse points, managing sparse files,
or dismounting a volume.
LABEL You can create, change, or delete the volume label (that is, the name) of a
syntax- label [/mp] disk. Without parameters, the label command changes the current volume
[<volume>] [<label>] label or deletes the existing label.
Command Description
SCHTASKS
syntax- SCHTASKS
/parameter [arguments]
parameter- create,
delete, query, change, Enables an administrator to create, delete, query, change, run, and end
run, end, showid scheduled tasks on a local or remote system
SHUTDOWN
synatx- shutdown [/i | /l |
/s | /r | /g | /a | /p | /h | /e |
/o] [/hybrid] [/f] [/m
\\computername] [/t xxx]
[/d [p:|u:]xx:yy] [/c
"comment"] [/?] Lets you power off, restart, log off, or hibernate your computer
TASKLIST
syntax- TASKLIST [/S
system [/U username [/P
[password]]]] [/M Shows a list of currently running processes on the local computer or on
[module] | /SVC | /V] [/FI a remote computer.
filter] [/FO format] [/NH]
TASKKILL
syntax- TASKKILL [/S Lets you end one or more tasks or processes. Processes can be ended
system [/U username [/P by process ID or image name.
[password]]]] { [/FI filter]
[/PID processid | /IM
imagename] } [/T] [/F]
It will let you enable a user to execute a program on another computer as a
specified user.
RUNAS
syntax- RUNAS [ /noprofile Specifies that the user's profile should not be loaded, which
[/noprofile | /profile] allows the application to load more quickly, but can cause some applications
[/env] [/savecred | to malfunction.
/netonly] ] /profile The default setting that specifies that the user's profile should
/user:<UserName> be loaded
program /env Uses the current environment instead of the user's
RUNAS [ [/noprofile | /netonly Use if the credentials specified are for remote access only
/profile] [/env] /savecred Use credentials previously saved by the user
[/savecred] ] /smartcard Use if the credentials are to be supplied from a smartcard
/smartcard /user <UserName> should be in form USER@DOMAIN or DOMAIN\USER
[/user:<UserName>] /showtrustlevels Displays the trust levels that can be used as
program arguments to /trustlevel.
RUNAS /trustlevel <Level> should be one of the levels enumerated in
/trustlevel:<TrustLevel> /showtrustlevels.
program program Command line for EXE.
FAQs
Right-click on the title bar -> Properties -> click on “Colors” -> choose the colors -> Click OK.