Command Line Tutorial for Windows (Like You’re 12!)
Table of contents
- 1. What is the Command Line?
- 2. How to Open the Command Line
- 3. Basic Commands
- 4. Working with Files and Folders
- 5. Advanced Commands
- 6. Navigation and Shortcuts
- 7. Batch Files
- 8. Environment Variables (What Are They and How to Use Them?)
- 9. Piping & Redirection
- 10. Scripting and Automation
- 11. Networking and Internet
- 12. Conclusion
1. What is the Command Line?
The Command Line is a tool that lets you interact with your computer using text commands. It’s like sending instructions to your computer in a special language. This might feel different from clicking on things, but once you understand it, you can do some amazing stuff quickly!
2. How to Open the Command Line
To open the Command Line in Windows:
Press the Windows Key on your keyboard or click the Start button.
Type
cmd
and hit Enter.
A black window will appear—that’s the Command Line!
3. Basic Commands
Let’s start with some simple commands. Type these into the command line and press Enter after each.
a. dir
This command shows you a list of files and folders in your current location (folder).
dir
b. cd
(Change Directory)
This command moves between folders.
cd foldername
If you want to go back to the previous folder, type:
cd ..
c. cls
(Clear Screen)
This command clears everything from the screen, so you get a fresh start.
cls
4. Working with Files and Folders
Now, let's learn how to create, delete, and manage files and folders.
a. mkdir
(Make Directory)
This command creates a new folder.
mkdir myfolder
b. rmdir
(Remove Directory)
This deletes a folder, but it has to be empty.
rmdir myfolder
If a folder is not empty and you want to remove it:
rmdir /S myfolder
c. del
(Delete Files)
This deletes files.
del myfile.txt
d. copy
(Copy Files)
This makes a copy of a file.
myfile.txt myfile_copy.txt
5. Advanced Commands
Let’s get a little fancy with these powerful commands.
a. move
Moves a file from one place to another.
move myfile.txt C:\NewFolder
b. ren
(Rename)
Renames a file or folder.
ren oldname.txt newname.txt
c. echo
This command prints a message to the screen or creates a file.
echo Hello World!
To write to a file:
echo Hello World! > greeting.txt
6. Navigation and Shortcuts
You don’t always have to type everything perfectly. Use these shortcuts:
a. tab
autocomplete
Start typing the name of a file or folder and press Tab. The command line will auto-complete it!
b. History navigation
Press the Up Arrow to scroll through commands you’ve already typed. This is great when you need to run the same command again!
7. Batch Files
You can save a bunch of commands in a text file with a .bat
extension and run them all at once!
Open Notepad.
Type some commands like this:
echo Hello!
dir
pause
- Save it as
mybatch.bat
.
Now, when you double-click on mybatch.bat
, the command line will run everything in that file.
8. Environment Variables (What Are They and How to Use Them?)
Environment Variables are like built-in shortcuts in the Command Line that store important information about your system. They hold data such as the location of programs, your username, or the temporary file storage folder. Instead of typing long paths or specific values, you can use these shortcuts.
How to View All Environment Variables
To see all the environment variables currently in use on your system, type:
set
This command will list all environment variables, along with their values.
Common Environment Variables
Here are some commonly used environment variables in Windows:
%USERPROFILE%
: Refers to the path of your user directory (likeC:\Users\YourName
).cd %USERPROFILE%
%SystemRoot%
: Refers to the Windows installation directory (usuallyC:\Windows
).cd %SystemRoot%
%TEMP%
or%TMP%
: Points to the directory where temporary files are stored.cd %TEMP%
%PATH%
: A special variable that contains a list of directories where the system looks for programs. When you type a command, the system searches through these directories to find it.
You can access any of these by surrounding the variable name with %
symbols. For example, if you type cd %USERPROFILE%
, the Command Line will take you to your user’s home directory.
Setting Your Own Environment Variables
You can create your own environment variables to store frequently used paths or values.
Temporarily set a new environment variable (this lasts only until you close the Command Prompt):
set MYVAR=C:\MyFolder
Now you can use
%MYVAR%
in commands:cd %MYVAR%
To see the value of a specific environment variable:
echo %MYVAR%
Permanently Setting Environment Variables
To permanently set environment variables, you need to modify them in the system settings:
Right-click on This PC or My Computer and choose Properties.
Click on Advanced System Settings on the left-hand side.
In the System Properties window, click the Environment Variables button.
You can either edit the User variables (for the current user only) or System variables (for all users).
Add, edit, or delete environment variables as needed.
Tip: Be careful when modifying environment variables, especially the PATH
variable, as it can affect how your system runs commands.
9. Piping & Redirection
You can connect commands together with piping (|
) or save their output with redirection (>
).
Example: Redirecting output to a file
dir > fileslist.txt
This saves the output of dir
to fileslist.txt
.
Example: Piping
dir | find "txt"
This shows only files with "txt" in their name by combining dir
and find
.
10. Scripting and Automation
You can write scripts to automate tasks. For example, a script to back up files every day:
@echo off
xcopy C:\myfolder D:\backupfolder /E /H /C /I
pause
11. Networking and Internet
The Command Line can also check your network settings and test your internet connection.
a. ipconfig
Shows your computer’s IP address and network information.
ipconfig
b. ping
Tests if you can reach a website. It sends small packets of data to see if the site is responding.
ping google.com
12. Conclusion
Congratulations! You’ve learned the basics and some advanced topics in the Command Line. Keep practicing these commands, and soon, you’ll be able to do things faster than using a mouse!
When you get really good, you can even use this knowledge to create programs, automate tasks, or troubleshoot your computer.
Subscribe to my newsletter
Read articles from Gift Ayodele directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by