Windows Command Line
Using the Windows Command Line
If you are serious about development or QA then you are going to be spending a lot of time on the command line.
Here is a quick tutorial that teaches you the most important commands that you will need in the Windows Command Prompt.
Starting the command line
In the Windows search bar, type “cmd”.
You should see an app called “Command Prompt”. Select it and the command prompt window will open.
You should see something similar to this.
The first thing you see, other than that Windows message at the top, is the path where you are currently located at. The part at the front, “C:”, is the drive letter for the hard where the folder is located.
For me, I am located at my user directory, which is the typical starting point after you launch the Command Prompt.
Here is mine:
So let’s compare this with the Windows File Explorer.
Type “File Explorer” in the Windows search bar and open the app.
Copy the directory in the Command Prompt. Make sure to include the whole thing including “c:”.
Paste the directory into the address bar of the file explorer.
You are now at the same directory as the command prompt. Taking a quick look around, you should see a bunch of folders and files.
The Windows command prompt is not case sensitive. What that means is that “DIR” and “dir” will both work perfectly fine.
Spaces in folders and files can cause problems for applications, so I typically recommend never having a space in file or folder names. However, you are likely going to find things with spaces in them.
Whenever you need to do something with a file or folder with a space in the name you need to wrap it in double-quotes.
- “My Documents”
- “family photo.png”
Listing the folders and files
Let’s list out the folders and files in the command prompt.
Type “dir” and hit the enter key.
You will see a list of folders and files with additional information such as date modified, time modified, file sizes, and this thing labeled “<DIR>”.
<DIR> is an indicator to let you know that is a directory or a folder. Everything else in the list is a file.
Take a look around and compare the list to what you see in the file explorer. You should see all the same files and folders.
Take note that the Command Prompt lists the sizes in bytes while the File Explorer uses kb.
In the command prompt type “cd Desktop”. Make sure you have a single space right after the “cd”. Hit that enter key.
Now your path in the Command Prompt should have changed a bit.
Mine looks like:
I am now in the Desktop folder within the Users/Drago directory.
Go ahead and type “dir” again and you will see a new list of files and folders.
On your File Explorer open the Desktop folder and compare with the Command Prompt.
Moving back through directories
So right now my current directory hierarchy would look something like this.
C: -- Users -- Drago -- Desktop
How do I get back to the “Drago” folder?
In the Command Prompt type “cd ..” and hit enter.
You should now have moved back one folder. Let’s go ahead and move back to the Desktop folder by typing “cd Desktop” again.
Let’s try moving back two directories.
Type “cd ….” and hit enter. You should now be here:
You can follow this pattern any number of times until you reach the C:
Let’s go back to where we started. Type “cd c:UsersDragoDesktop”, but enter in your username instead of “Drago”.
Now, let’s jump directly to C:
Type “cd ” and hit enter.
You should now be here:
In your File Explorer jump to the C:. Feel free to do a DIR command to make sure you are in the same spot.
In the Command Prompt type “mkdir Test” and hit enter.
You should see that folder appear on your File Explorer window or if you do a DIR command.
Feel free to make more folders if you would like.
Note: Before you continue here, make sure you are 100% sure you want to delete the folder. Folders and files in the C: are often critical files in making your Operating System work properly. Deleting these critical files could make your computer unusable.
So let’s delete that folder that we created earlier. Type “rmdir Test”.
Check the File Explorer or use the DIR command to confirm the folder is now gone. Feel free to delete any other folders that you created earlier. Be careful. I warned you.
Create a file
Let’s go ahead and create a new folder. Type “mkdir Test” once again to re-create this folder.
Move into the Test folder. You should remember how, or cheat by reviewing above.
Now type “start notepad testfile.txt” and press enter.
You will see the Notepad app open and a warning appears. Go ahead and hit YES.
Check your folder and you should see the file is there. Close the Notepad app.
Delete a folder with files
Wait, we already learned to delete a folder. Yes, but it is easy when there is nothing in the folder.
Move back to the C: and try to delete the Test folder again.
The directory is not empty.
If you see the error below then you didn’t close your Notepad. Close it and try again.
The process cannot access the file because it is being used by another process.
Now, let’s try deleting that folder again. Type “rmdir /s Test” and hit enter. You will get a prompt confirming you want to delete the folder. Type Y and hit enter.
Folder and the file inside it are now gone.
Let’s go ahead and create that “Test” folder one more time.
Create a “test.txt” file inside of it.
Now while you are inside the Test folder create two more folders, Test1 and Test2.
Now while still in the Test folder type “move test.txt Test1” and hit enter.
Go ahead and execute the DIR command. You should now see the test.txt file is gone.
C:Test>dir Volume in drive C is OS Volume Serial Number is 7461-8469 Directory of C:Test 08/22/2019 07:51 PM <DIR> . 08/22/2019 07:51 PM <DIR> .. 08/22/2019 07:51 PM <DIR> Test1 08/22/2019 07:50 PM <DIR> Test2 0 File(s) 0 bytes 4 Dir(s) 53,797,507,072 bytes free
Go ahead and move yourself to the Test1 folder. Run the DIR command again. You should see your .txt file there.
While still in the Test1 folder type “copy test.txt test1.txt” and hit enter.
Run the DIR command. You should now see 2 files in the Test1 folder.
Now try typing “copy test.txt ..” and hit enter. Move yourself back to the Test folder and run the DIR command. You should see the file you just copied.
Stay in the Test folder and type “rename test.txt fun.txt” and hit enter. Run the DIR command. You should see your file was renamed.
C:Test>dir Volume in drive C is OS Volume Serial Number is 7461-8469 Directory of C:Test 08/22/2019 07:58 PM <DIR> . 08/22/2019 07:58 PM <DIR> .. 08/22/2019 07:51 PM 0 fun.txt 08/22/2019 07:54 PM <DIR> Test1 08/22/2019 07:50 PM <DIR> Test2 1 File(s) 0 bytes 4 Dir(s) 53,795,311,616 bytes free
That fun.txt file isn’t very fun so let us delete it. Type “del fun.txt” and hit enter. Run the DIR command and verify the file was deleted.
Running a program
You are able to launch executable files directly from the command line. Executables are program files that end in the .exe extension.
So you are going to need a file to try. Go over to and download Notepad ++. It’s just a little text editor. Completely free.
Move that file to your Test folder.
Run the DIR command in your Test folder.
C:Test>dir Volume in drive C is OS Volume Serial Number is 7461-8469 Directory of C:Test 08/22/2019 08:08 PM <DIR> . 08/22/2019 08:08 PM <DIR> .. 08/22/2019 08:08 PM 3,667,704 npp.7.7.1.Installer.exe 08/22/2019 07:54 PM <DIR> Test1 08/22/2019 07:50 PM <DIR> Test2 1 File(s) 3,667,704 bytes 4 Dir(s) 53,920,813,056 bytes free
For me, the file is called npp.7.7.1.Installer.exe. Yours may be a bit different depending on the version number.
To launch the program just type out the name of the file and hit enter. For me, I type “npp.7.7.1.Installer.exe”.
In about a second you should see Windows ask if you want to allow the program to do stuff and then the Notepad++ installer opens. You can cancel out of the installer.
Now, what if you forget the things I taught you so far?
No worries, just type “help” and hit enter. You will get a list of commands that you can use.
Clearing the console: The console can get quite messy and sometimes you just want to wipe the screen clean. Type “cls” and hit enter. You have a clean slate.
Command history: The Command Prompt remembers the last commands that you entered. You can easily recover these, as long as you don’t close the window. Simply hit the UP arrow on the keyboard and you will see the commands that you last ran. Keep hitting UP or DOWN until you find what you are looking for.
Auto-complete: When you are in a folder and want to quickly get the name of the folder or file in that directory without manually typing in the whole thing.
First thing you can do is hit that TAB key. You will see the names of the files and folders auto-populate in the prompt. Hitting TAB again will give you the next item in the current folder.
If there are a lot of folders and files you can give it the first few letters and then hit the tab key. You will now only get things that match the first letters you entered. Keep hitting TAB and it will cycle through the matching files.
Closing the window
All done. Just type “exit” and hit enter.
Your window is gone and you can go do something else.