Welcome to a quick tutorial on the basic Windows command prompt commands. Once upon a time in the Dark Ages of computing, there is only a command-line when we turn on a computer. No wallpaper, no windows, no graphics. Today, we have the convenience of the graphical user interface (GUI), and most people will shy away from the command line.
Little did they know that a lot of the “hacker” controls cannot be done in the graphical interface… But we are not going there in this guide. Let us start with the basics, which will make you look cool enough anyway. Read on!
REAL QUICK SLIDES
TABLE OF CONTENTS
|Getting Started||Basic Commands||Summary & Links|
GETTING STARTED WITH COMMAND PROMPT
Before we dive into the commands, let us start with the raw basics of “how to open the command prompt” in Windows.
HOW TO LAUNCH THE COMMAND PROMPT
windows + Rto open the run window.
- Type in “cmd” and hit “OK”.
A NOTE ABOUT SECURITY
By default, launching the command prompt in Windows 10 will be in “restricted access mode”. Meaning, messing with the critical system stuff is not allowed. If you want an unrestricted command prompt, here is how to do it:
windows> search for “command prompt”.
- Right-click on it, run as administrator.
But beware, this gives the full administrator access to change the system files. This can potentially do some irreversible damage if you do not know what you are doing.
BASIC WINDOWS COMMANDS
Now that you have launched the command line, here are some of the basic commands to know.
1) CHANGING THE CURRENT DRIVE
Microsoft Windows [Version 10.0.18362.535] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\W.S. Toh>d: D:\>e: E:\>
When the command prompt is launched, all that is staring back is a
C:\Users\NAME. This should pretty self-explanatory, it is your “current directory”. That is, the current location is at the
C:\ drive, inside the default
If you want to change the current directory to another drive, simply enter the drive letter – For example
2) LIST CONTENTS OF CURRENT DIRECTORY
D:\>dir Volume in drive D is DATA Volume Serial Number is CATE-DOGE Directory of D:\ 11/02/2018 03:42 PM <DIR> Documents 12/13/2018 10:06 PM <DIR> http 12/15/2018 09:11 PM <DIR> NetBeans 8.2 06/17/2017 08:53 PM <DIR> obs-studio 06/17/2017 02:18 PM <DIR> Rainmeter 05/28/2018 01:58 PM <DIR> xampp 0 File(s) 0 bytes 6 Dir(s) 46,296,956,928 bytes free
To list the contents of the current folder, use the
3) CHANGE CURRENT DIRECTORY
D:\>cd http D:\http>
Next, we have the
cd command… Should be Captain Obvious, changes the current directory. There is one trick here – We don’t actually need to type out the full folder name. For the above example, we can just type out
cd h and press
tab to cycle through the list of folders starting with “h”.
D:\http>cd d:\Documents\eBooks D:\Documents\eBooks>
Another way to use the
cd command is to enter a full file path.
D:\Documents\eBooks>cd.. D:\Documents> D:\Documents\eBooks>cd/ D:\>
cd.. to go up one level, or
cd/ to go all the way back to the root of the current drive.
4) CLEAR SCREEN
When the screen gets too messy, use
cls to clear the screen.
5) LAUNCHING APPLICATIONS
From the command prompt, we can also launch various apps.
Captain Obvious to the rescue again. Hit
exit when done, and this will close the current session.
7) COPYING FILES
D:\http>copy README.txt d:\http\temp 1 file(s) copied.
To copy a file, simply specify the source file and destination –
copy SOURCE DESTINATION.
D:\http>copy *.* d:\http\temp ALT-dummy.php ALT-retrieve.php ALT-stats.php ALT-store.php JSON-retrieve.php JSON-store.php README.txt sql-fav-color.sql sql-people.sql 9 file(s) copied.
To copy all the files in the current directory, use
copy *.* DESTINATION.
D:\http\test>xcopy *.* d:\http\temp /e D:ALT-dummy.php D:ALT-retrieve.php D:ALT-stats.php D:ALT-store.php D:JSON-retrieve.php D:JSON-store.php D:README.txt D:sql-fav-color.sql D:sql-people.sql 9 File(s) copied
Now, the problem with
copy is that it only copies files, but not the folders within. So if you want to copy everything, including the folders within, use the slightly more advanced
xcopy *.* DESTINATION /e instead.
9) MOVING FILES
D:\http\test>move README.txt d:\http\temp 1 file(s) moved. D:\http\test>move *.* d:\http\temp D:\http\test\ALT-dummy.php D:\http\test\ALT-retrieve.php D:\http\test\ALT-stats.php D:\http\test\ALT-store.php D:\http\test\JSON-retrieve.php D:\http\test\JSON-store.php D:\http\test\sql-fav-color.sql D:\http\test\sql-people.sql 8 dir(s) moved.
Don’t think this one needs explanation,
move is the cousin of
copy and the usage is the same –
move SOURCE DESTINATION.
10) REPLACING FILES AND FOLDERS
D:\http\test>replace READLATER.txt d:\http\temp Replacing D:\http\temp\READLATER.txt
move will prompt if you want to replace existing files. This can get irritating when moving a large number of files, so use
replace SOURCE TARGET if you just want to replace everything.
11) RENAMING FILES AND FOLDERS
D:\http>ren README.txt READLATER.txt
ren FROM TO.
12) CREATING A NEW FOLDER
13) DELETING FILES
To delete a single file.
To delete all the files in the folder.
14) REMOVING FOLDERS
D:\http>rmdir myNewFolder /S myNewFolder, Are you sure (Y/N)? y
Please take note that the previous
del command will only delete files, but not remove the folder itself. To remove a folder, we have to use the
rmdir command instead. If you want to remove the folder entirely (all the files and folders contained within), add a
/S option at the end.
15) FILE COMPARE
D:\http>comp doge.txt cate.txt /A Comparing doge.txt and cate.txt... Compare error at OFFSET A file1 = D file2 = C Compare error at OFFSET B file1 = o file2 = a Compare error at OFFSET C file1 = g file2 = t Compare error at OFFSET 10 file1 = G file2 = E Compare error at OFFSET 11 file1 = o file2 = v Compare error at OFFSET 12 file1 = o file2 = i Compare error at OFFSET 13 file1 = d file2 = l Compare more files (Y/N) ? n
Finally, this is a not-so-useful command that compares 2 files and shows you the differences between them.
16) REPEAT COMMANDS
Want to repeat a previous command? Press the up and down arrow keys to scroll through your previous commands – No need to retype everything.
Is the default black-and-white color scheme too boring for you? You can change the colors with the
color command. It takes 2 alphanumeric characters from 0 to F. The first one is the background color, and the second one is the text color.
This is the “swag way” to shut down a computer.
/soption will do a full shutdown.
/rto do a reset instead.
19) GETTING HELP
C:\>replace /? Replaces files. REPLACE [drive1:][path1]filename [drive2:][path2] [/A] [/P] [/R] [/W] REPLACE [drive1:][path1]filename [drive2:][path2] [/P] [/R] [/S] [/W] [/U]
Need help with a command? Simply append
/? to the end, or you can use the
help command to get a full list of available commands.
C:\>help For more information on a specific command, type HELP command-name ASSOC Displays or modifies file extension associations. ATTRIB Displays or changes file attributes. BREAK Sets or clears extended CTRL+C checking. BCDEDIT Sets properties in boot database to control boot loading.
USEFUL BITS & LINKS
That’s all for the examples, and here is the summary/cheat sheet of all the basic commands plus some links that may be useful to you.
ALL THE COMMANDS
|c: d: e:||Change the current drive.|
|dir||Display the contents of the current directory.|
|cd||Change the current directory.|
|cls||Clear the screen.|
|exit||Closes the current session.|
|copy||Copy files from one place to another.|
|xcopy||The slightly more advanced version of copy.|
|move||Move files from one place to another.|
|replace||Copy and automatically replace target file(s).|
|ren||Rename a file or folder.|
|mkdir||Create a new folder.|
|del||Delete a file or files.|
|rmdir||Remove a folder|
|compare||Compare 2 files.|
|Up and down arrow keys||Scroll through the previous commands.|
|Tab key||Autocomplete a file or folder name; Cycles between the files and folders.|
|color||Change the color scheme of the command line.|
|shutdown||Shutdown the computer.|
|help||Display all available commands, get more details on the options of a specific command.|
INFOGRAPHIC CHEAT SHEET
LINKS & REFERENCES
- 15 Windows CMD Commands You Must Know – Make Use Of
- Windows Commands – Microsoft
- 21 CMD Commands All Windows Users Should Know – Help Desk Geek
Thank you for reading, and we have come to the end of this guide. I hope this has helped you to better understand the command line and make you look a little more like a legit hacker. If you have anything to share with this guide, please feel free to comment below. Good luck and happy computing. May the cyber force be with you.