Windows Command Line Basics

You’ve got the user interface figured and want to step up your game by using the command line? This guide will teach you the basics in 5 minutes.

What is the command line?

The command line (or CMD) is a built in Windows tool which lets you do the following things:

  • File operations (Copy, Rename, Move, Delete, Create)
  • Network tools (ping, traceroute, netstat)
  • Connect to other computer’s command lines (telnet)
  • Do stuff quicker than over the GUI (Connecting network drives, open text files as administrator)
  • Script reoccurring tasks (like copying a file every day)

This guide will handle the first two points. The other stuff is a bit more advanced, so first get good at the basics before Part 2 will be up!

How do I access the command line?

The command line can be accessed via either the search function (windows symbol bottom left -> enter “cmd”) or Windows+R -> “cmd”.

Don’t be scared of that black little window! You’ll soon know how to use it.

Basics

Upon opening you will be greeted by some system information – you can ignore that. The interesting part is the last line of text. It should read something like this:

C:\Users\Name>

C:\Users\Name is the path it is currently located. This will be very important later.

the > tells you that you’ll write after it.

Go ahead and just write something into the console, doesn’t matter what. Just get the feel.

Commands

Moving around

Now let’s try to navigate in the File System. There’s some commands you should know for that:

Let’s start with the most basic ones

  • cd
    • Let’s you change directories
  • dir
    • Shows you the files in the current directory

Go ahead and type “dir” into the command line. Look at the output. Does it look familiar? It’s your user folder! Neatly listed.

Now let’s go into a folder. You’ll probably have one named “Documents”. To change the folder type the following command:

cd Documents

Now the text before the > should have changed. Do you see it? It’s now C:\Users\Name\Documents>!

Now list the directories in that folder!

You probably figured that out right? Use “dir” to show the folders.

To get back up to your user folder, use the command:

cd ..

The two points stand for “one above” and can be used everywhere (Except when there’s no folder above).

Do you want to see something cool? Type in “tree” and it will give you a nice little list of folders, subfolders and files.

Creating, Renaming, Moving and Deleting Files / Folders

Creating Files isn’t that intuitive but I am sure you’ll get the gist of it. You actually need to put something in a file to even create it – and that’s easy, you can use the “crocodile mouth” for than “>”. Put the following command in:

test > newFile.txt

Now open up the newFile.txt (you can do so by typing “notepad newFile.txt” into the command line) and see if your text is in it. If you want to put whole sentences in, put the text in quotation marks “”.

newFile.txt isn’t an all that great name is it? Let’s rename it:

rename newFile.txt supercoolname.txt

To move files use “mv” it’s mv OldLocation NewLocation

mv newFile.txt C:\Test\newFile.txt

To delete the file use “rem”

rem newFile.txt

Getting Help

You surely got the gist of it by now? Let me show you how you can find out what you can do:

The first command you’ll need is

help

“help” will show you a list (not complete) of available commands. If one suits your needs you can use “/?” at the end of the command:

rem /?

This will show you what you can do with that command and which parameters you can set.

Networking Commands

CMD has many commands to test your network. The first and the most used is “ping” Go ahead and try the following command:

ping www.google.com

It will now try to reach www.google.com four times. You can see how long it took and if it was successful.

If you’d like to know what path your little packet to google takes to reach it, you can try “tracert”

tracert www.google.com

This will show you all hops to google. It’s sometimes interesting where you’ll land. If you don’t live in the US, the last few hops will be in the country you live in probably. Going to www.google.com will just take you to the nearest google servers. (The country code or city code is in the hostname of the last step).

 

Now that’s it for the basics – try these commands (especially help and /?) until you think “man this is easy, why didn’t I try this before?

 

 

 

Was this article helpful?