Windows Terminal from Zero to Hacker

Kamalveer Singh
9 min read3 days ago

--

You might have seen people in movies and in real-life working on their laptops in a terminal like thing and a lot is going on it and it looks pretty cool.

In this blog you are going to learn how to achieve the same look : )

What is Command Prompt

Well simply saying there are two ways to use a device one is with GUI (Graphical User Interface) and the other one is CLI (Command Line Interface) and the CLI is way faster than the GUI method of doing things like creating a file, renaming it, changing directories.

In short you can say that GUI is mouse focused whereas the CLI is keyboard focused.

Why Learn CMD

If you are in the field of computer science, then learning command line becomes an essential part of daily life. It’s faster and gives you more control over the system.

It depends on the user (CLI)

But why Windows CMD

Now many of you might say that developers use Unix based systems like — Linux, for their developing purposes then why learn windows command line?

The answer to that is pretty simple, 77% of devices have Windows OS in them which makes it useful to learn it at least at a basic level. I am not saying that you should only stick with Windows, but you should be familiar with it.

Let’s Start

That’s enough with the talking, now let’s start learning.

Useful TIPS in the end : )

Opening CMD — to open command prompt in windows click on the windows icon and search for CMD or command prompt and select it.

It’ll open a terminal like this.

C:\Users\91638 is the path where you are currently present.

DIR (List Contents)

The dir command is used to display the contents of the present directory or a specified directory.

dir

dir C:\Users\91618\Desktop

dir /a // to see hidden files in a diectory

dir folder_1 // to look for contents of folder_1

dir *.png // used to look for a specific file type in a folder

dir *png *mp4 // can be done for multiple types also

dir /b // view like ls command (compact view)

If you just want to see the filenames then you can use the dir /b command.

CD (Change Directory)

In GUI when you need to change directories (folders) you double click on a folder to go inside of it, in CLI you use the cd command.

cd [absolute or relative path]
cd ..     // used to goo back to its parent directory

cd Desktop/folder_name // multiple directories entry is valid

cd ../.. // goes back 2 steps

cd C:/Users/Desktop // absolute path can be entered as well

cd // it will show your current durectory

TIP: Press tab for auto filling the names

CLS (Clear Screen)

The cls command is used to clear to terminal, which you might need for various purposes.

cls

Opening Files

To open any file like an image you click on it in GUI and to do the same with CLI you just need to type file name (or it’s initial and press TAB to auto complete).

filename.filetype

It can be used for images, video, auio, text, code files etc.

/? (Help)

‘/?’ is used to get information about a particular command.

command_name /?
Use of ‘/?’ to get information about CD command
// some examples

cd /?

dir /?

cls /?

MKDIR (Make Directory)

mkdiris used to create a new directory (folder).

mkdir directory_name
making a directory with the name `new_dir`
mkdir dir_1 dir_2 dir_3   // create multiple directories

mkdir "dir with spaces" // make a directory with spaces in name

RMDIR (Remove Directory)

rmdir is used to remove / delete a directory (folder).

rmdir dir_name
Removing a directory by the name `new_dir`
rmdir dir_1 dir_2 dir_3    // remove multiple directories

rmdir "dir with space" // use "" to remove a dir with spaces in its name

NOTE: If you try to remove a directory which holds some sub directories or files then rmdir won’t work alone.

trying to remove a dir by the name `a`

To delete a directory which has content inside of it you need to use /s tag with the command and then enter Y or N to select to remove it or not.

using `/s` tag with rmdir
// You can place '/s' in between or at the end

rmdir /s dir_with_subfiles

rmdir dir_with_subfiles /s

TREE (See Files Structure)

tree command is used to make a visual tee to see the structure of the path specified.

tree
using `tree` command
tree

tree [dir_path]

tree /f // to see full structure -> even the files

tree /a // output in ascii characters
opening tree for a specific folder

COLOR (Change Colors)

color command is used to change the colors of text and the background os your command prompt shell.

color [background][text]

// example

color 0A
Changing color of the CMD

By using color 0a we get the 0 — black background and a — green color of the text.

Use color /? to see all the options available.

color 0A    // 0 - black and A - light green

color // get to default

color /? // to see the color list
another example to color changing

With this command you can make your terminal look the way you want and also look cool in front of your friends ; )

ATTRIB (Modifying Attributes)

attrib command is used to display, set or remove attribute assigned to files and directories.

attrib    // to view the attributes present directory
`attrib` command use
attrib <filename>       // to see attributes of a specific file

attrib /? // to see the various attributes

attrib +h <filename> // to add an attribute to a file => h -> hidden

attrib -h <filename> // to remove an attribute from a file

Below you can see how you can really make use of it —

Adding and removing hidden feature to a file

This is similar to right clicking on a file then navigating to a property and then selecting that property like read only, hidden etc.

DEL (Delete a File)

del command is used to delete a files, it can’t be used to delete folders.

del file.filetype
Using `del` command
del demo.txt

del *.png // delete all .png files present in current folder

del C:\Folder\*.log // to delete all .log files present in specified folder

del /f read_only_file.txt // to force delete a file

del /s *.tmp // deletes all .tmp files in current directory and sub-directories

del /A:R example.txt // deletes all files based on attribute

ECHO (Print a Message)

Echo command is used to print something on the terminal or put/append data onto a file.

echo Hello, World!
Echo command use
echo data > file.txt
Putting text inside `greet.txt` file

To append data on a file use >> instead of >.

echo Second Line >> file.txt

TYPE (See a File)

The type command is used to read the content from a file and display or put it inside another file.

type filename.txt
Seeing contents inside `greet.txt`
type file1.txt file2.txt                 // read from multiple files

type file1.txt > file2.txt // put data of file1 to file2

type file1.txt >> file2.txt // append data from file1 to file2

type file1.txt file2.txt > combined.txt // combined file creation

You can also save outputs from commands like below —

dir >> output.txt
Saving `dir` output in `output_of_dir.txt`

This can be very useful in many places, like pip freeze if you know about it.

COPY (Copy files)

copy command is used to copy files from one location to another.

copy [source] [destination]

copy study_material.mp4 D:\Backup\ // it's not what you think it is ;)
Copying a file to a folder named `Backup`
copy *.mp4 D:\Backup\       // copy all mp4 files to Backup

copy file1.txt file2.txt // copy and rename a file

copy code.txt code.cpp // copy and change type of file

copy file1.txt+file2.txt+file3.txt combined.txt // combines and copies

MOVE (Move files)

move command is used to move files or directories from one place to another.

move [source] [destination]

move file.txt D:\Backup\
Moving files from source folder to destination
move *.png D:\Backup\                // move specific type of files

move file.txt D:\Backup\haha.txt // move and rename file

move folder1 D:\folder2\ // move directories

move C:\folder1 C:\renamed_folder // raname a directory

RENAME (Renaming files)

rename or ren command is used to rename a particular file or folder.

rename file.txt new_name.txt
Renaming Example
ren *.txt *.bat               // rename multiple files at once

ren file.txt file.py // changing file extensions

rename file.txt D:\Backup\new_file.txt // move files + rename

rename file.txt "file with spaces.txt" // use "" to add spaces in file name

ren folder_1 folder_69 // rename folders/drectories

EXPLORER / START (Open GUI)

explorer or start command is used to open the current or specified location in GUI File Explorer.

explorer .

Very useful sometimes.

start ..             // to open parent directory
explorer ..

explorer C:\Users // open a specific location

Note: in terminal ‘.’ represents the current location, if you are in ‘C:\Users\Documents’ then ‘.’ is equivalent to that.

You can also do the reverse process by clicking on the loacation and typing cmd there.

Typing `cmd` inside location field

It’ll open up the command line in the same location.

command line opened in same location

CODE (To Open file in Code Editor)

code command is used to open the specified location in your default code editor. (like — VS Code.

code [location]

code . // "to open current directory in code editor"
Example of `code` command

PROMPT (To change the prompt)

The prompt command is used to rename the location

prompt your_prompt$g          // $g is for getting `>` sign
Use case of `prompt` command

If you messed up and want to get to default just type prompt without anything else.

Exit (Exit out of CMD)

Now, that you have only used your keyboard for all these tasks it would be nice to exit out of it without clicking on close button with mouse.

We can use the exit commmand to exit out of out terminal.

exit
exit command to close terminal

Shortcuts / Tips

1. Use up and down arrows to toggle between previous and next commands typed by you.
2. Use home and end buttons to go to first and last index of your prompt.
3. Use ctrl + left/right arrows to move between words.
4. If you are confused about a command, then use /? for its documentation.

At first it might look like the GUI approach is better but with a little practice you’ll see the speed increase in your daily tasks while programming.

I hope it helped you : )

Follow me on Twitter — Kamal Stark

--

--