---
title: "Unix Basics"
format:
revealjs:
theme: beige
transition: fade
width: 1280
height: 720
center: true
---
## Why Learn Unix?
- Foundational philosophy for modern computing
- Powers most of the digital world
- Born at AT&T's Bell Labs in late 1960s
- Design principles: simplicity, modularity
## Unix Today
- **Certified Unix**: macOS
- **Unix-like Systems**: GNU/Linux, BSD variants
- **Linux**: Dominant Unix-like OS
- Understanding Unix = understanding DNA of modern OS
## Unix System Overview
**Multi-user, Multitasking Operating System**
```{mermaid}
graph TD
A[OS Kernel] --> B[User 1 Process]
A --> C[User 2 Process]
A --> D[User 3 Process]
B --> E[File System]
C --> E
D --> E
style A fill:#2e86ab,color:#fff
style B fill:#a23b72,color:#fff
style C fill:#f18f01,color:#fff
style D fill:#c73e1d,color:#fff
style E fill:#3c8d5f,color:#fff
```
## File System Structure
**Hierarchical Tree Organization**
```{mermaid}
graph TD
Root[/] --> etc["/etc
config files"]
Root --> home["/home
user directories"]
Root --> usr["/usr
system software"]
Root --> var["/var
variable data"]
home --> user1[/user1/]
home --> user2[/user2/]
user1 --> docs[Documents]
user1 --> downloads[Downloads]
style Root fill:#2e86ab,color:#fff;
style etc fill:#a23b72,color:#fff;
style home fill:#f18f01,color:#fff;
style usr fill:#c73e1d,color:#fff;
style var fill:#3c8d5f,color:#fff;
```
## File Naming Rules
**Allowed Characters:**
- Letters (a-z, A-Z), Numbers (0-9)
- Recommended: `.`, `%`, `-`, `_`, `:`, `=`
**Key Rules:**
- **Case sensitive**: `File.txt` ≠ `file.txt` ≠ `FILE.TXT`
- **No leading dash**: `-file` causes issues (use `./-file`)
- **Hidden files**: Start with `.` (e.g., `.bashrc`)
**Best Practices:**
```bash
good_file.txt # Clear and safe
data-set-01.csv # Descriptive with hyphens
project_config # No extension needed
```
## Globbing - Pattern Matching
**Wildcard Characters:**
```bash
* # Any sequence of characters
? # Any single character
[abc] # Any character in set
[a-z] # Any character in range
```
**Practical Examples:**
```bash
ls *.txt # All text files
ls report?.pdf # report1.pdf, reportA.pdf
ls [abc]*.log # a.log, b_data.log, c-backup.log
ls image[0-9].jpg # image0.jpg through image9.jpg
```
## Advanced Globbing
**Combining Patterns:**
```bash
ls *.{txt,md} # All .txt AND .md files
ls project_{dev,prod} # project_dev, project_prod
ls file[!0-9]* # Files NOT starting with digit
```
**Use in Commands:**
```bash
cp *.txt backup/ # Copy all text files
rm temp_*.log # Remove temporary logs
chmod +x *.sh # Make all scripts executable
```
**Pattern Expansion:**
```bash
echo *.py # Shows what patterns match
ls data_202{3,4}*.csv # Multiple year patterns
```
## Globbing vs Regular Expressions
**Key Differences:**
- **Globbing**: File matching (`ls *.txt`)
- **Regex**: Text pattern matching (`grep "^A" file.txt`)
**Remember:** Globbing happens **before** command execution!
## File Permissions
**Three categories × Three rights**
```bash
-rwxr-xr-- # Owner: read, write, execute
# Group: read, execute
# Others: read only
```
```{=html}
```
## Process Concept
**Program vs Process**
```{=html}
```
## Shell Environment
**Your Command Interface**
```{=html}
```
## Command Structure
```bash
command [options] [arguments] [redirections]
```
**Examples:**
```bash
ls -l /home # List with details
grep "error" log.txt # Search pattern
find . -name "*.txt" # Find files
```
## Input/Output Redirection
**Controlling Data Flow**
```{mermaid}
flowchart LR
A[Input File
data.txt] --> B{Command
program}
B --> C[Output File
results.txt]
style A fill:#2e86ab,color:#fff
style B fill:#a23b72,color:#fff
style C fill:#f18f01,color:#fff
```
## Pipes - Command Chaining
**Connect processes together**
```bash
cat file.txt | grep "error" | sort | uniq
```
```{mermaid}
flowchart LR
A[cat
Reads file] -->|stdout| B[grep
Filters text]
B -->|stdout| C[sort
Orders data]
C -->|stdout| D[uniq
Removes duplicates]
style A fill:#2e86ab,color:#fff
style B fill:#a23b72,color:#fff
style C fill:#f18f01,color:#fff
style D fill:#3c8d5f,color:#fff
```
## Essential Commands
| Category | Commands | Purpose |
|----------|----------|---------|
| **Files** | `ls, cp, mv, rm, mkdir` | Manage files and directories |
| **Navigation** | `cd, pwd` | Move around file system |
| **Text** | `cat, grep, head, tail, wc` | View and search text |
| **Process** | `ps, kill, &, bg, fg` | Manage running programs |
| **Help** | `man, --help` | Get command information |
## Getting Started
**Next Steps:**
- Practice basic file operations
- Learn command combinations with pipes
- Study pattern matching with wildcards
- Explore shell scripting for automation
- Use `man` pages for detailed help
**Remember:** Unix mastery comes through practice!