[Linux 101] The Terminal: Don’t Be Afraid of the Dark

9 minute read

Published:

Let’s turn that scary black screen into a hacker’s playground.

Linux beginners often see the black terminal screen as a scary trap that might explode if they touch the wrong key. You don’t want to accidentally press a button that blows up your “home” directory. But once you get used to it, this screen makes you look like a cool hacker working at a cafe.

By the end of this post, you’ll be able to move around the Linux terminal, manage files, and edit text without panic.

Table of Contents

(Click the image to watch the tutorial on YouTube)


> 1. The Dark House

Navigating the CLI (Command Line Interface) is like waking up in the middle of the night.

If someone takes your convenient GUI (Graphical User Interface) away and throws you into a CLI screen, it feels like a power outage.

Imagine you took a nap on the couch and woke up at 3 A.M. It is pitch black. You know how to get to your bed, but you can’t see the obstacles on the way.

Using a terminal is exactly the same. You need to verify where you are and what is around you before you take a step. If you know exactly where to go, you can walk straight to your room. But you should always be careful not to trip.


> 2. Navigating Your Home

Okay, it’s 3 A.M., the power is out, and you don’t have a flashlight. You want to go to your bed.

First, you need to locate yourself. This is what pwd (Print Working Directory) does. It tells you exactly where you are standing.

$ pwd
/home/my_family/first_floor

Before you move, you want to know what’s around you so you don’t kick the table. The ls (List) command is your hands feeling the surroundings. You can add options to see hidden items or details.

$ ls
couch kitchen lamp restroom staircase trash_bin TV

$ ls -a
couch kitchen lamp .phone .remote restroom TV user123_room
# Now you found a phone and a remote hidden under the couch!
# (Files starting with '.' are hidden in Linux)

$ ls -l
total 32
-rwxr-xr-x. 1 family  family   4096 Dec 27 20:22 couch
drwxr--r--. 1 family  family   4096 Dec  6 20:02 kitchen
-rwxr--r--. 1 family  family  10517 Dec 26 18:51 lamp
drwxr-xr-x. 1 family  family   4096 Dec 26 17:49 restroom
-rwxr-xr-x. 1 parents family    840 Dec 26 18:03 TV
-rwxr-xr-x. 1 family  family    840 Dec 26 18:03 trash_bin
drwxr-xr-x. 1 user123 family   4096 Dec 26 18:03 user123_room
# You can see full details about each item or room
# You won't see hidden items here

Note: You can combine -a and -l as -la to see full details of all items

The detailed view (-l) shows some cryptic codes. Let’s ignore the first column for now (those are permissions). Focus on the rest:

  • Columns 3 & 4: Owner & Group
  • Column 5: Size
  • Column 6-8: Last modified date & time
  • Last Column: Item Name

Let’s go to the restroom first. Since you can see it in your list, you can walk straight in. Use the cd (Change Directory) command.

$ cd restroom

$ pwd
/home/my_family/first_floor/restroom

$ ls
bath_tub body_wash hand_soap shampoo shower sink toilet towel

You finished your business and want to go to your bed (user123_room). But wait, ls shows no room here! You have two options:

  1. Step out to the hall, check locations, and then enter your room.
    $ cd ..
    $ cd user123_room
    
  2. Go out and immediately enter your room in one go.
    $ cd ../user123_room
    

What is “..”? In Linux, a single dot . represents Here (Current location), and double dots .. represent Parent (One level up). (Unfortunately, it stops at 2 dots. There is no “...” or “....”)

Relative vs. Absolute Path Using dots (. or ..) works within your house. But what if you are at a friend’s house? You can get out of their restroom (..), but you won’t find user123_room there. In that case, you need an Absolute Path (Full address).

# Relative path (Works only if you are in the hallway)
$ cd user123_room

# Absolute path (Works from anywhere in the universe)
$ cd /home/my_family/user123_room


> 3. Magic Spells: File Operations

Here, we need more imagination. You are not just a person in the dark; you are a Wizard. Your magic wand can create rooms, clone items, or make trash disappear.

Creation (mkdir, touch)
First, let’s create an empty room. The spell is mkdir (Make Directory).

$ mkdir new_room

If you want to create an item (an empty file), use touch.

$ touch magic_scroll.txt

Teleportation (mv)
You want to move the TV from the living room to your new room. Cast mv (Move).

$ mv /home/my_family/first_floor/TV /home/my_family/first_floor/new_room/

Note: In Linux, renaming is just moving a file to the same place with a new name.

$ mv old_name.txt new_name.txt

Cloning (cp)
If you take the TV, your dad will be sad. Let’s create a clone using cp (Copy).

# Copy TV to the parent directory
$ cp ./TV ../

Now everyone is happy!

Destruction (rm)
Your mom asked you to take out the trash. With your magic power, you can simply incinerate it. Use rm (Remove).

$ rm ./trash_bin

Tip: When using rm, prefer relative paths so you clearly see what you’re deleting.

Warning: Unlike Windows/Mac, Linux has no Recycle Bin. When you rm a file, it is gone forever. It is incinerated. So please, think twice before you cast this spell.


> 4. X-Ray Vision (Checking Files)

While you were out, your parents left a note on the table.

Hey, we are leaving to pick up your cousin.
Please clean up the kitchen.
Don’t watch TV all evening.
… (100 lines more) …
Make sure to finish your homework before we are back.
Call if you want us to pick up anything for dinner.

How do you read this?

  1. cat: Opens the entire note at once.
  2. less: Opens content in a readable way and lets you scroll up and down
  3. head: Peeks at the top few lines.
  4. tail: Peeks at the bottom few lines.

My Suggestion:

Command Use Case
cat Short file (Fits in one screen)
less Long file (Log files, code)
head Just checking the beginning
tail Checking the latest update (End of logs)

Note: less is a contents viewer. You can press q to close it.

# Read the first 2 lines
$ head -2 note.txt
Hey, we are leaving to pick up your cousin from the airport.
You have a few things to do once you are back.

# Read the last 2 lines
$ tail -2 note.txt
Make sure to finish your homework before we are back.
Call if you want us to pick up anything for dinner.


> 5. Write It Down (Editors)

You want to write a reply. On the terminal, you can’t just open Microsoft Word. You need terminal editors like nano or vim.

And… Let’s not talk about emacs now. I’m sorry if you are an emacs fan.

Option 1: Nano (The Notepad) If you want a simple sticky note and pen, use nano. It is beginner friendly.

$ nano reply.txt

Nano

You can simply type whatever you want. The menu is at the bottom.

  • ^ means Ctrl key.
  • To Save: Press Ctrl + O (Write Out), then Enter.
  • To Exit: Press Ctrl + X.

Option 2: Vim (The Pro Tool) I am a vim user. It is powerful but a bit more tricky.

Vim

  1. Type vim reply.txt.
  2. Press i to start typing (Insert Mode).
  3. When done, press Esc (to exit Insert Mode).
  4. Type :wq and Enter (Write and Quit).
  5. If you are stuck and panic? Press Esc and type :q! (Force Quit without saving).


> 6. Secret Tips

Let’s keep these tips between us.

1. Tab Autocomplete (Magic Key) Don’t type long filenames manually. Just type the first few letters and hit TAB.

$ cd /home/my_family/first_f [TAB]
# Becomes:
$ cd /home/my_family/first_floor/

2. History (Arrow Keys) Did you make a typo? Don’t retype the whole command. Just press the Up Arrow key to bring up your previous command and fix it.

3. The Abort Button (Ctrl+C) Stuck in a running program? Or typed a long command you want to cancel? Press Ctrl + C.

[user@linux]$ i_wrote_a_very_long_random_command [Ctrl+C]
[user@linux]$ i_wrote_a_very_long_random_command^C
[user@linux]$ (Canceled!)

4. The Clean Slate (clear) Is your screen too messy? Type clear. It wipes the screen clean.

The Forbidden Spell One last warning. Don’t ever run this:

$ rm -rf /

This is the Nuke Button for your Linux world. It tries to delete everything from the root directory. Once launched, there is no going back.


Summary

  1. Navigate: pwd (Where am I?), ls (What’s here?), cd (Enter/Change).
  2. Manage: mkdir (Create room), touch (Create file), cp (Copy), mv (Move/Rename), rm (Destroy).
  3. View: cat (Short), less (Long), head/tail (Top/Bottom).
  4. Edit: nano (Simple), vim (Advanced).
  5. Survival: TAB to autocomplete, Ctrl+C to abort.

Great job! You can now move comfortably in the darkness.

Happy Computing!