The Hackr

Windows Command Prompt /cmd Cheat Sheet

Command Prompt, also known as cmd.exe or cmd (after its executable file name), is the command-line interpreter on Windows NT, Windows CE, OS/2 and eComStation operating systems. It is the counterpart of COMMAND.COM in DOS and Windows 9x systems (where it is also called “MS-DOS Prompt”), and analogous to the Unix shells used on Unix-like systems.

To open the Windows command prompt you may do one of the following:

Click Start -> Programs -> Accessories -> Command Prompt
Click Start (or hit the Windows key), type “cmd” in search, then hit [ENTER]
Windows Key + R (#r, not the pound symbol) brings up Run. Then type “cmd” then [ENTER]
SHIFT + right-click in any folder or desktop, then select “open command window here”

BASIC COMMAND PROMPT COMMANDS

x /? = provides syntax info and complete list of all parameters for x (a command, like “cd”)
 cd = change directory
 cd .. = move to the parent directory
 cd\ = move to the root of current drive
 cd x = move to the current\x directory
 cd z: = change to the z root directory (as opposed to c:)
 copy x y = copy file x to directory y (Ex: D:\games\galaga.exe C:\programs[\awesome.exe]), [] = optional
 copy file con = display file contents in console
 copy con file.txt = create text file in the console window, end with ctrl+z (^z or F6)
 date = change the date
 del = delete/erase
 del x = deletes all files/folders fitting x
 del . = deletes all files within current directory
 del *.* = deletes all files within current directory
 dir = display contents of current directory (Ex: dir [c:][\programs]), [] = optional
 dir *.txt = list all .txt files in current directory
 dir *.? = list all files with extensions one character in length in current directory
 dir /w /p *.* = display all contents one screen at a time
 dir | more = display all contents one line at a time
 dir /? = provides syntax info and complete list of all dir parameters
 echo = send command line input to display (by default)
 echo sometext » somefile.txt = append line(s) of text to any file
 echo sometext > somefile.txt = overwrites file with sometext
 erase = delete/erase
 exit = exit the command prompt
 filename.txt = opens filename.txt in current directory in Notepad (or default .txt program)
 format z: = format z drive [Ex: use to format a disc or flash drive]
 mkdir x = make directory x in current directory
 move x y = more or rename x to y
 q = escapes sequential display of contents (i.e. the more parameter)
 rd x = remove/delete directory x if it’s empty
 ren x y = rename file x to y
 time = change the time
 type file = display the contents of the file ‘file’ (displays file contents in console)
 type file |more = display the contents one line at a time

ADVANCED COMMAND PROMPT COMMANDS

ipconfig [/all] = display network adapter information (advanced)
netstat –n = display local address and addresses you are connected to (advanced)
netstat –nb = above with name of foreign addresses (advanced) (this shows your private IP, if you are behind a router or proxy, then your public IP address will be different)
ping google.com = how long it takes for your computer to talk to google.com

CONVERT OUTPUT OF ONE PROCESS INTO INPUT OF ANOTHER PROCESS

Send contents of script.js to the system debug.exe file:
type script.js | c:\programs]debug.exe
programs\debug.exe < script.js

SEND DIRECTORY LISTING TO A PRINTER OR FILE

dir > prn (theoretically to a printer)
dir > somefile.txt
dir *.mp3 > c:\Users\Dan\Desktop\musiclist.txt = print all .mp3 files in current directory to musiclist.txt

MODIFY ANY FILE EXTENSION ASSOCIATIONS

[assoc .extension=fileType]
assoc /? = prints this information
assoc = display list of current file extensions recognized by your computer (any fileType value may be used)
assoc > fileextensions.txt = print list to somefile.txt in current directory
assoc .txt = displays current file association of .txt (.docx, .html, .zip, .htaccess, assoc textfile, et cetera)
assoc .txt= = will delete the association for the given file extension

File Extension Tips/Ideas:
– Windows by default doesn’t know the following extensions, but check anyways with “assoc .”, “assoc .htaccess” and “assoc .xml” anyways just to be sure. If the extension is defined already, then you may not need to change it.

assoc .=txtfile = associate extensionless files with Notepad
assoc .htaccess=txtfile = associate nameless .htaccess files with Notepad
assoc .xml=txtfile = associate XML files with Notepad

ENVIRONMENTAL VARIABLES VIA THE DOS COMMAND PROMPT

System-generated upon Windows startup:

%DATE% = Tue 08/02/2011
%TIME% = 14:23:33.37
%SYSTEMROOT% = C:\Windows
%COMPUTERNAME% = DAN-PC

System-generated upon user login:

%USERNAME% = Dan
%USERDOMAIN% = Dan-PC

Local machine variables for all users:

%PATH% = C:\Windows\system32
%HOMEPATH% = \Users\Dan
%HOMEDRIVE% = C:

(Hint: Use echo)

FUNCTION KEYS

F1 = Sequential, individual repeat of previously entered characters
F2 = Copies any number of characters from the previous command line
F3 = Repeats the contents of the previous command line
F4 = Deletes any number of characters from the previous command line
F5 = Return to the previous command line
F6 = Enters the characters ^z (CTRL+z), indicating “end of file”
F7 = Displays a history of command-line entries for the current session (50-line cache)
F8 = Sequentially displays previous command-line entries
F9 = Enables user to recall previous command lines by number (0 = first line)

Sreehas

The hacking trend these days has definitely turned criminal because of e-commerce ¯\_(ツ)_/¯

up