Basic Intro to the command-line interface (Windows)
Note: 'Please note that throughout this post, we use the terms 'directory' or 'folder' but they are the same thing.'
Let's get started!!
What is the command line?
The command-line or command-line interface is a text-based application for viewing and handling files on your computer through the use of commands. It's much like Windows Explorer or Finder on the Mac, but without the graphical interface. Other names for the command line are cmd, CLI, prompt, console, or terminal.
Open the command-line interface
To start, we need to open our command-line interface first.
Depending on your version of Windows and your keyboard, one of the following should open a command window (you may have to experiment a bit, but you don't have to try all of these suggestions
- Go to the Start menu or screen, and enter "Command Prompt" in the search field.
- Go to Start menu → Windows System → Command Prompt.
- Hold the Windows key and press the "R" key to get a "Run" window. Type "cmd" in the box, and click the OK key.
Prompt
On Windows, you probably see a >
, like this:
command-line
>
Each command will be prepended by a >
and one space, but you should not type it. Your computer will do it for you.
The part up to and including the >
is called the command line prompt, or prompt for short. It prompts you to input something there.
Writing your first command
Let's start by typing this command:
Your first command: Windows
command-line
> whoami
And then hit enter
.
The computer will print your username.
Basics
It'd be nice to know where are we now, right? Let's see. Type this command and hit enter
:
Current directory
command-line
> cd
We should see something similar to this:
C:\Users\username
Note: 'cd' stands for 'change directory'.
Learn more about a command
Many commands you can type at the command prompt have built-in help that you can display and read! For example, to learn more about the current directory command:
Command Help
List files and directories
So what's in it? It'd be cool to find out. Let's see:
List files and directories
command-line
> dir
Directory of C:\Users\username
05/08/2020 07:28 PM <DIR> Applications
05/08/2020 07:28 PM <DIR> Desktop
05/08/2020 07:28 PM <DIR> Downloads
05/08/2020 07:28 PM <DIR> Music
Note: 'DIR' stands for 'Directory'.
We can also cd into a folder and see all the list of items in that folder:
> cd Desktop
> dir
And hit enter, you should see all the files inside of your desktop directory.
Change current directory
command-line
> cd Documents
Hit Enter after that!
Check if it's changed:
Create directory
command-line
> mkdir Testing
To Create a folder or directory
> cd Testing
To open or navigate to the folder or directory
Exercise!
A small challenge for you: in your newly created practice
directory, create a directory called test
. (Use the cd
and mkdir
commands.)
Exercise solution
Now that you are in the Testing directory
Create another folder or directory inside it using the mkdir command like we did above and give it any name of your choice and navigate to that folder using the cd command
Having done that, Congrats!
Clean up
We don't want to leave so many commands on our CLI, we can easily navigate back to our Desktop Directory using the following command:
command-line
> cd ..
Using ..
the cd
command will change your current directory to the parent directory (that is, the directory that contains your current directory or the folder that contains your current folder).
Deleting the Testing directory
Note: Deleting files using
del
,rmdir
orrm
is irrecoverable, meaning the deleted files will be gone permanently! So be very careful with this command.
command-line
> rmdir /S Testing
Testing, Are you sure <Y/N>? Y
Done! To be sure it's deleted, let's check it:
Check deletion
command-line
> dir
If you do not see the Testing Dir, Congrats!! You have successfully deleted it.
Exit
That's it for now! You can safely close the command line now. Let's do it the hacker way
command-line
> exit
Cool, huh?
Summary
Here is a summary of some useful commands:
Command (Windows) | Description | Example | ||
---|---|---|---|---|
exit | close the window | exit | ||
cd | change directory | cd testing | ||
cd | show the current directory | cd | ||
dir | list directories/files | dir | ||
mkdir | create a new directory | mkdir testingdirectory | ||
rmdir (or del) | delete a file | del c:\testing\testing.txt | ||
rmdir /S | delete a directory | rm -r testdirectory | ||
[CMD] /? | get help for a command | cd /? |
These are just a very few of the commands you can run in your command line.
Answers ( 0 )