Top 10 Essential Linux Commands: Hands-On Beginner's Guide

Basic Commands Introduction - Linux Command Basics

What You'll Learn

  • Instantly know "Where am I?" and "What's here?" using pwd/ls
  • Master file/directory operations (create, view, copy, move, delete)
  • Troubleshoot common issues (No such file / Permission denied / overwrite accidents) on your own

Target audience: Beginners working with Ubuntu servers (or local PC)

Prerequisites: Contains dangerous operations (rm). Only run commands in the "practice directory"

Quick Summary (The Pattern)

1) pwd → 2) ls -la → 3) cd → 4) mkdir -p → 5) touch → 6) echo ... > file → 7) cat → 8) cp -i → 9) mv -i → 10) rm -i

Table of Contents

  1. First, Create a Safe Practice Environment
  2. pwd: Check Your Location (Prevent Getting Lost)
  3. ls: List Contents (Look First)
  4. cd: Navigate (The King of "No such")
  5. mkdir: Create Directories (-p is Your Safety Net)
  6. touch: Create Empty Files
  7. echo: Output Text
  8. cat: Display Contents
  9. cp: Copy (-i Prevents Accidents)
  10. mv: Move/Rename (-i Prevents Accidents)
  11. rm: Delete (Be Extra Careful)
  12. Common Troubleshooting
  13. Efficiency Tips
  14. Practice Exercise (10 min)
  15. Next Steps

First, Create a Safe Practice Environment (Don't Practice Elsewhere)

To prevent "I don't know where I'm working" accidents, run this first:

$ mkdir -p ~/pgym/basic-commands
$ cd ~/pgym/basic-commands
$ pwd
$ ls -la
/home/user/pgym/basic-commands
total 8
drwxr-xr-x 2 user user 4096 Dec 17 10:00 .
drwxr-xr-x 3 user user 4096 Dec 17 10:00 ..

Key Point: Only practice within this directory. If lost, return to pwd and ls -la.

1) pwd: Check Your Location (Prevent Getting Lost)

Basic

$ pwd
/home/user/pgym/basic-commands

Common Issues → Recovery

  • "I don't know where I'm working"
    → Recovery: First pwd, then ls -la. These two commands reveal 80% of the situation
  • Symbolic links may show different paths than actual location
    → Recovery: Learn pwd -P (actual path) later (not required now)

2) ls: List Contents (Look First)

Basic

$ ls

The Pattern for Real Work (Remember This)

$ ls -la
total 12
drwxr-xr-x 2 user user 4096 Dec 17 10:00 .
drwxr-xr-x 3 user user 4096 Dec 17 10:00 ..
-rw-r--r-- 1 user user    0 Dec 17 10:01 a.txt

What to Look For (Super Important)

  • First character: - (file) / d (directory)
  • rwx: permissions
  • user user: owner/group

Common Issues → Recovery

  • Hidden files (.env etc.) not visible
    → Recovery: Use ls -a or always use ls -la
  • "I don't understand permissions or owner"
    → Recovery: Use ls -la (ls alone lacks info)

3) cd: Navigate (The King of "No such")

Basic

$ mkdir -p dir1
$ cd dir1
$ pwd
/home/user/pgym/basic-commands/dir1

Common Shortcuts

$ cd ~      # Go home
$ cd ..     # Go up one level
$ cd -      # Return to previous

Common Issues → Recovery (Must Know)

bash: cd: xxx: No such file or directory

  • 99% caused by: typo or wrong location
  • Recovery pattern:
    1. pwd (check current location)
    2. ls -la (check available options)
    3. Copy correct spelling and cd

Directory names with spaces

  • → Recovery: Use quotes like cd "My Documents"

4) mkdir: Create Directories (-p is Your Safety Net)

Basic

$ mkdir my_project

Real Work Pattern (Creates Parents Too)

$ mkdir -p projects/web/frontend

Usually no output (silence means success).

Common Issues → Recovery

  • File exists: Same name already exists
    → Recovery: Check with ls -la. Use a different name
  • Permission denied: No permission in that location
    → Recovery: Work in ~/ (home directory)

5) touch: Create Empty Files (Content Doesn't Increase)

Basic

$ touch a.txt b.txt
$ ls -la
-rw-r--r-- 1 user user 0 Dec 17 10:05 a.txt
-rw-r--r-- 1 user user 0 Dec 17 10:05 b.txt

Common Issues → Recovery

  • Touching existing file "creates" → actually updates timestamp
    → Recovery: As intended. Content unchanged (can be confusing)

6) echo: Output Text (> overwrites, >> appends)

Basic (Display)

$ echo "Hello Linux"
Hello Linux

Write to File (Overwrite / Append)

$ echo "first line" > memo.txt
$ echo "second line" >> memo.txt
$ cat memo.txt
first line
second line

Common Issues → Recovery

  • Used > to overwrite (meant to append)
    → Recovery: Use >> next time. Use set -o noclobber to prevent overwrites, but beginners should just use >>
  • Permission denied (can't write there)
    → Recovery: Check permissions with ls -la → move to ~/

7) cat: Display Contents (Don't Use on Large Files)

Basic

$ cat memo.txt

With Line Numbers (Useful for Logs/Configs)

$ cat -n memo.txt
     1  first line
     2  second line

Common Issues → Recovery

  • cat on large file - screen scrolls too fast
    → Recovery: Use less (not in this top 10, but essential for real work)
    Example: less /var/log/syslog (press q to exit)
  • No such file or directory
    → Recovery: Check filename with ls -la (often a typo)

8) cp: Copy (-i Prevents Accidents)

Basic (File Copy)

$ cp a.txt a-copy.txt
$ ls -la

Real Work Pattern (Confirm Overwrite)

$ cp -i a.txt memo.txt
cp: overwrite 'memo.txt'? 

Copy Directory (-r)

$ mkdir dir2
$ cp -r dir1 dir2/dir1-backup

Common Issues → Recovery

  • cp: cannot stat 'xxx': No such file or directory
    → Recovery pattern: pwdls -la → fix path/spelling
  • Worried about overwrite accidents
    → Recovery: Always use cp -i

9) mv: Move/Rename (-i Prevents Accidents)

Basic (Rename)

$ mv a-copy.txt a2.txt
$ ls -la

Basic (Move)

$ mkdir moved
$ mv a2.txt moved/
$ ls -la moved

Real Work Pattern (Confirm Overwrite)

$ mv -i memo.txt moved/

Common Issues → Recovery

  • "Moved it but can't find it"
    → Recovery: ls -la, then find . -name "memo.txt" (see find article)
  • Worried about overwrite
    → Recovery: Always use mv -i

10) rm: Delete (Be "Too Careful" Here)

Basic (Delete File)

$ rm a.txt

Real Work Pattern (With Confirmation: Start Here)

$ rm -i b.txt
rm: remove regular file 'b.txt'? 

Common Issues → Recovery

  • rm: cannot remove 'dir1': Is a directory
    → Recovery: Directories need rm -r (dangerous - check contents with ls -la first)
  • Permission denied
    → Recovery: No permission. Don't blindly sudo. See Permission denied article
  • Wildcard accident (e.g., rm -rf *)
    → This is the king of accidents. Beginners should never use rm -rf

Common Troubleshooting (Quick Diagnosis)

1) "No such file or directory" appeared

  • First pwd
  • Then ls -la
  • If still failing: "wrong path", "spelling", or "case sensitivity"

2) "Permission denied" appeared

Efficiency Tips (Quick Wins Only)

  • Tab completion: Type part of file/directory name and press Tab
  • Ctrl + A (go to start) / Ctrl + E (go to end)
  • history and Ctrl + R (search past commands)

Practice Exercise (10 min)

This exercise covers the essential pattern for real work (create → write → verify → organize).

$ cd ~/pgym/basic-commands
$ mkdir -p my_profile
$ cd my_profile
$ touch profile.txt
$ echo "name: your_name" > profile.txt
$ echo "role: beginner" >> profile.txt
$ cat -n profile.txt

Expected output:

     1  name: your_name
     2  role: beginner

Next Steps

Verification Environment

Commands in this article verified on Ubuntu 24.04 LTS / bash 5.2.

Master Basic Commands Through Practice

Once you've learned the "patterns" for these 10 commands, practice hands-on with Penguin Gym Linux exercises to solidify your skills.