Post

Week 1: Linux Fundamentals

Week 1: Linux Fundamentals

Week 1: Linux Fundamentals

Duration: 5 days (40 hours)
Goal: Master essential file operations and text handling


Day 1-2: File System Basics

The Linux Directory Structure

Before navigating, know where you’re going. Linux has one unified tree starting at / (root). Every file and device lives somewhere in this tree.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/
├── bin/       → Essential commands (ls, cp, mv, cat)
├── boot/      → Kernel and bootloader files
├── dev/       → Device files (disks, terminals, /dev/null)
├── etc/       → System-wide config files (network, users, services)
├── home/      → User home directories (/home/rahul, /home/alice)
├── lib/       → Shared libraries needed by /bin and /sbin
├── media/     → Auto-mounted removable drives (USB, CD)
├── mnt/       → Manually mounted filesystems (network shares, WSL mounts)
├── opt/       → Optional third-party software
├── proc/      → Virtual filesystem: live kernel/process info (not on disk)
├── root/      → Home directory for the root (admin) user
├── run/       → Runtime data (PIDs, sockets) — cleared on reboot
├── sbin/      → System admin binaries (fdisk, reboot) — usually needs root
├── srv/       → Data served by services (web files, FTP data)
├── sys/       → Virtual filesystem: kernel device info
├── tmp/       → Temporary files — cleared on reboot
├── usr/       → User programs and libraries (/usr/bin, /usr/lib, /usr/share)
└── var/       → Variable data that changes: logs (/var/log), mail, web content

The ones you’ll use every day:

Directory What it is Example
/home/yourname Your personal files cd ~
/etc Config files for everything cat /etc/hostname
/var/log System and app logs tail -f /var/log/syslog
/tmp Scratch space (gone on reboot) Temp downloads, test scripts
/usr/bin Installed programs Where python3, git live
/proc Live system info (not real files) cat /proc/cpuinfo

Quick facts:

  • / is the root — not /root (that’s the admin’s home folder)
  • In WSL, your Windows C: drive appears at /mnt/c/
  • Paths starting with / are absolute; without / they’re relative to where you are
1
2
3
4
5
# Explore these now:
$ ls /
$ ls /etc | head -20
$ ls /var/log
$ ls /proc | head -10

Your First Commands

Open Ubuntu (WSL):

  • Press Windows key
  • Type “Ubuntu”
  • Press Enter

Try these now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ pwd
/home/yourname

$ ls
# Shows your files

$ cd Documents
$ pwd
/home/yourname/Documents

$ cd ..
$ pwd
/home/yourname

$ cd ~
$ pwd
/home/yourname

Essential Navigation

pwd - Where am I?

1
2
$ pwd
/home/rahul

cd - Go somewhere

1
2
3
4
$ cd ~              # Go home
$ cd /tmp           # Go to /tmp
$ cd ..             # Go up one level
$ cd Documents      # Go to Documents folder

ls - What’s here?

1
2
3
4
$ ls                # Basic list
$ ls -la            # All files with details (includes hidden)
$ ls -lrt           # Sorted by time, oldest first (USE THIS IN PRODUCTION!)
$ ls -lrth          # Same but human-readable sizes (1.2M instead of 1234567)

Why ls -lrt matters:

1
2
3
4
5
6
$ ls -lrt /var/log/
# Newest files at bottom - easy to see recent changes
# This is THE most used command in real work!

$ ls -lrth ~/
# Same but shows 1.2G instead of 1234567890

Creating Things

mkdir - Make directories

1
2
$ mkdir projects
$ mkdir -p work/code/python    # Create all parent dirs

touch - Create empty files

1
2
$ touch readme.txt
$ touch file1.txt file2.txt file3.txt

Practice:

1
2
3
4
5
$ cd ~
$ mkdir test
$ cd test
$ touch hello.txt
$ ls -la

Copying and Moving

cp - Copy

1
2
3
$ cp file.txt file_backup.txt
$ cp file.txt /tmp/
$ cp -r folder/ folder_backup/    # Copy directory

mv - Move or rename

1
2
$ mv oldname.txt newname.txt      # Rename
$ mv file.txt /tmp/               # Move

Practice:

1
2
3
4
$ touch test.txt
$ cp test.txt test_backup.txt
$ mv test.txt myfile.txt
$ ls

Deleting (Be Careful!)

rm - Remove

1
2
3
$ rm file.txt                     # Delete file
$ rm -r folder/                   # Delete directory
$ rm -rf folder/                  # Force delete (no confirmation)

NEVER DO THIS:

1
2
$ rm -rf /          # DESTROYS SYSTEM!
$ rm -rf /*         # DESTROYS EVERYTHING!

Safe practice:

1
2
$ ls              # Check what you'll delete
$ rm file.txt     # Then delete

WSL-Specific: Accessing Windows Files

Your Windows drives are at /mnt/

1
2
3
4
5
6
$ cd /mnt/c/Users/YourName/Downloads
$ ls -lrth
# You're now in your Windows Downloads folder!

$ cd ~
# Back to Linux home

Access Linux files from Windows:

  • Open Windows Explorer
  • Type in address bar: \\wsl$\Ubuntu\home\yourname

Hidden Files

Files starting with . are hidden

1
2
3
$ ls              # Doesn't show .bashrc
$ ls -la          # Shows .bashrc
$ ls -a           # Shows hidden files, no details

Common hidden files:

1
2
3
.bashrc           # Shell configuration
.ssh/             # SSH keys
.gitconfig        # Git settings

Day 3-4: Text & Permissions

Viewing Files

cat - Display entire file

1
2
$ cat file.txt
$ cat file1.txt file2.txt    # Multiple files

less - View page by page

1
2
3
4
$ less /var/log/syslog
# Press Space for next page
# Press q to quit
# Press / then type to search

head - First 10 lines

1
2
$ head file.txt
$ head -5 file.txt      # First 5 lines

tail - Last 10 lines

1
2
$ tail file.txt
$ tail -f /var/log/syslog     # Follow live updates (Ctrl+C to stop)

Most useful tail command:

1
2
$ tail -f /var/log/apache2/access.log
# Watch web server logs in real-time

Editing Files

nano - Simple text editor

1
$ nano myfile.txt

Essential nano shortcuts:

  • Ctrl+O then Enter - Save
  • Ctrl+X - Exit
  • Ctrl+K - Cut line
  • Ctrl+U - Paste

Practice:

1
2
3
4
5
6
$ nano test.txt
# Type: Hello World
# Press Ctrl+O, Enter (save)
# Press Ctrl+X (exit)
$ cat test.txt
Hello World

File Permissions

Understanding ls -l output:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ ls -l
-rw-r--r-- 1 rahul rahul 1234 May 15 10:00 file.txt
│││││││││
│││││││││
│││││││└─ Others: r (read)
││││││└── Others: - (no write)
│││││└─── Others: - (no execute)
││││└──── Group: r (read)
│││└───── Group: - (no write)
││└────── Group: - (no execute)
│└─────── Owner: w (write)
└──────── Owner: r (read)
First: - (file) or d (directory)

chmod - Change permissions

Most common patterns:

1
2
3
4
5
6
7
8
9
10
11
12
$ chmod 755 script.sh
# Owner: rwx (7 = 4+2+1)
# Group: r-x (5 = 4+0+1)
# Others: r-x (5 = 4+0+1)

$ chmod 644 file.txt
# Owner: rw- (6 = 4+2)
# Group: r-- (4)
# Others: r-- (4)

$ chmod +x script.sh
# Add execute permission (most common!)

When to use what:

1
2
3
4
755 - Scripts and programs (executable)
644 - Regular files (not executable)
600 - Private files (only you can read/write)
700 - Private directories (only you can access)

Practice:

1
2
3
4
5
6
7
8
9
10
11
$ cat > test.sh << EOF
#!/bin/bash
echo "Hello"
EOF

$ ./test.sh
Permission denied

$ chmod +x test.sh
$ ./test.sh
Hello

Day 5: Searching & Pipes

Finding Files

find - Search for files

1
2
3
4
5
6
7
8
$ find . -name "*.txt"
# Find all .txt files in current directory

$ find /home -name "config.php"
# Find config.php in /home

$ find . -name "*.log" 2>/dev/null
# Ignore permission errors

Common patterns:

1
2
3
4
$ find . -name "*.txt"              # All txt files
$ find . -type f -name "*.sh"       # Files only
$ find . -type d -name "backup"     # Directories only
$ find . -mtime -1                  # Modified in last 24h

Searching Inside Files

grep - Search file contents

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ grep "error" logfile.txt
# Show lines with "error"

$ grep -i "error" logfile.txt
# Case insensitive

$ grep -n "error" logfile.txt
# Show line numbers

$ grep -r "TODO" .
# Search all files recursively

$ grep "error" *.log
# Search all .log files

Real-world examples:

1
2
3
4
5
6
7
8
$ grep -i "error" /var/log/syslog
# Find errors in system log

$ grep "Failed" /var/log/auth.log
# Find failed login attempts

$ tail -100 app.log | grep "error"
# Last 100 lines with "error"

Pipes - Chain Commands

Pipe sends output from one command to another:

1
2
3
4
5
6
7
8
$ ls -l | less
# List files, view in pager

$ ps aux | grep python
# Find Python processes

$ cat file.txt | grep "error" | wc -l
# Count error lines

Common patterns:

1
2
3
4
5
6
7
8
$ history | grep "ssh"
# Find ssh commands you've used

$ ls -lrth | tail -5
# Show 5 newest files

$ cat access.log | grep "404" | wc -l
# Count 404 errors

Redirection - Save Output

> - Redirect output (overwrite)

1
2
3
4
5
$ ls -la > files.txt
# Save directory listing to file

$ echo "Hello" > greeting.txt
# Create file with content

» - Append output

1
2
$ echo "World" >> greeting.txt
# Add to file

2> - Redirect errors

1
2
$ find / -name "test" 2>/dev/null
# Hide permission errors

Practice:

1
2
3
4
5
6
$ ls -lrt > filelist.txt
$ cat filelist.txt

$ echo "Line 1" > test.txt
$ echo "Line 2" >> test.txt
$ cat test.txt

Command Substitution

Use command output in another command:

1
2
3
4
5
6
7
8
$ echo "Today is $(date)"
Today is Thu May 15 14:30:22 PDT 2026

$ mkdir $(date -I)
# Creates folder named: 2026-05-15

$ echo "I am $(whoami)"
I am rahul

Practical examples:

1
2
3
4
5
$ mkdir backup_$(date +%Y%m%d)
# Creates: backup_20260515

$ tar -czf backup_$(date -I).tar.gz /important/files/
# Creates dated backup file

Week 1 Exercises

Exercise 1: File System Navigation

1
2
3
4
5
6
7
8
9
10
# 1. Go to home directory
# 2. Create directory: week1_practice
# 3. Go into it
# 4. Create 5 files: file1.txt through file5.txt
# 5. List them with details and time sort
# 6. Copy file1.txt to file1_backup.txt
# 7. Rename file2.txt to file2_renamed.txt
# 8. Delete file3.txt
# 9. List remaining files
# 10. Go back to home

Solution:

1
2
3
4
5
6
7
8
9
10
$ cd ~
$ mkdir week1_practice
$ cd week1_practice
$ touch file{1..5}.txt
$ ls -lrth
$ cp file1.txt file1_backup.txt
$ mv file2.txt file2_renamed.txt
$ rm file3.txt
$ ls -lrth
$ cd ~

Exercise 2: Text and Permissions

1
2
3
4
5
6
7
# 1. Create a file called script.sh
# 2. Add content: echo "Hello World"
# 3. Try to run it: ./script.sh
# 4. Make it executable
# 5. Run it again
# 6. Create a file called notes.txt
# 7. Set it to private (only you can read/write)

Solution:

1
2
3
4
5
6
7
$ echo 'echo "Hello World"' > script.sh
$ ./script.sh                    # Fails
$ chmod +x script.sh
$ ./script.sh                    # Works!
$ touch notes.txt
$ chmod 600 notes.txt
$ ls -l notes.txt

Exercise 3: Searching and Pipes

1
2
3
4
5
# 1. Create a test file with sample log entries
# 2. Count how many lines have "error"
# 3. Find lines with "error" and show line numbers
# 4. Save errors to a separate file
# 5. Count lines in the error file

Solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ cat > sample.log << EOF
INFO: Starting application
ERROR: Connection failed
INFO: Retrying
ERROR: Timeout occurred
INFO: Success
EOF

$ grep -c "ERROR" sample.log
2

$ grep -n "ERROR" sample.log
2:ERROR: Connection failed
4:ERROR: Timeout occurred

$ grep "ERROR" sample.log > errors.txt
$ wc -l errors.txt
2 errors.txt

Week 1 Quick Reference

1
2
3
4
pwd                    # Where am I?
cd ~                   # Go home
cd ..                  # Go up
ls -lrth              # List files (time sorted, human-readable)

Files

1
2
3
4
5
6
7
touch file.txt        # Create file
mkdir dir             # Create directory
mkdir -p a/b/c        # Create nested
cp src dst            # Copy
mv src dst            # Move/rename
rm file               # Delete file
rm -r dir             # Delete directory

Viewing

1
2
3
4
5
cat file              # Show all
less file             # Page through
head file             # First 10 lines
tail file             # Last 10 lines
tail -f file          # Follow updates

Editing

1
2
3
nano file             # Edit file
# Ctrl+O - Save
# Ctrl+X - Exit

Permissions

1
2
3
4
chmod +x file         # Make executable
chmod 755 file        # rwxr-xr-x
chmod 644 file        # rw-r--r--
chmod 600 file        # rw------- (private)

Searching

1
2
3
4
find . -name "*.txt"         # Find files
grep "text" file             # Search in file
grep -r "text" .             # Search all files
grep -i "text" file          # Case insensitive

Pipes

1
2
3
4
cmd1 | cmd2           # Pipe output
cmd > file            # Save output
cmd >> file           # Append output
cmd 2>/dev/null       # Hide errors

Week 1 Complete!

You should now be able to:

  • Navigate the Linux file system
  • Create, copy, move, and delete files
  • View and edit text files
  • Understand and set file permissions
  • Find files and search content
  • Chain commands with pipes
  • Redirect output to files

Continue to Week 2 →


This post is licensed under CC BY 4.0 by the author.