Linux Command Line Essentials

The terminal is where Linux power lives. GUIs exist, but they are wrappers around command-line tools — when something goes wrong or you need to do something complex, you will end up in the terminal. The good news: you only need to learn about 30-40 commands to be productive, and most follow predictable patterns.

This article covers the commands you will use daily. For a broader reference, see [LinuxCommands](LinuxCommands).

The Terminal and the Shell

When you open a terminal, you are running a **shell** — a program that reads your commands and executes them. The default shell on most distributions is **Bash** (Bourne Again Shell). Some distributions default to **Zsh**, which adds convenience features on top of Bash.

The **prompt** tells you who you are, where you are, and whether you have admin privileges:

```

jakefear@laptop:~/Documents$```

- `jakefear` — your username

- `laptop` — the computer's hostname

- `~/Documents` — your current directory (`~` means your home directory)

- `$` — normal user (`#` means root/admin)

Navigation

| Command | What It Does | Windows Equivalent |

|---------|-------------|-------------------|

| `pwd` | Print working directory (where am I?) | `cd` with no arguments |

| `ls` | List files and directories | `dir` |

| `ls -la` | List all files (including hidden) with details | `dir /a` |

| `cd /path/to/dir` | Change directory | `cd \path\to\dir` |

| `cd ..` | Go up one directory | `cd ..` |

| `cd ~` | Go to your home directory | `cd %USERPROFILE%` |

| `cd -` | Go to the previous directory | No equivalent |

**Hidden files:** In Linux, files starting with `.` are hidden (e.g., `.bashrc`, `.config/`). Use `ls -a` to see them. There is no "hidden" attribute — the dot prefix is the convention.

File Operations

| Command | What It Does | Example |

|---------|-------------|--------|

| `cp source dest` | Copy a file | `cp report.txt backup/report.txt` |

| `cp -r dir1 dir2` | Copy a directory recursively | `cp -r photos/ backup/photos/` |

| `mv source dest` | Move or rename | `mv old.txt new.txt` |

| `rm file` | Delete a file (no recycle bin!) | `rm temp.txt` |

| `rm -r directory` | Delete a directory and contents | `rm -r old_project/` |

| `mkdir dirname` | Create a directory | `mkdir new_project` |

| `mkdir -p a/b/c` | Create nested directories | `mkdir -p src/main/java` |

| `touch filename` | Create an empty file (or update timestamp) | `touch notes.txt` |

**Critical warning:** `rm` does not move files to a trash can. They are gone. `rm -rf /` would delete your entire system. Be careful with `rm`, especially with wildcards (`rm *.txt`). Always double-check before pressing Enter.

Reading Files

| Command | When to Use It |

|---------|---------------|

| `cat file` | Display entire file (short files) |

| `less file` | Paginate through a long file (q to quit) |

| `head -20 file` | First 20 lines |

| `tail -20 file` | Last 20 lines |

| `tail -f logfile` | Follow a log file in real time (Ctrl+C to stop) |

| `wc -l file` | Count lines |

`less` is the one to master. It lets you scroll up and down, search with `/pattern`, and navigate large files efficiently.

Finding Things

| Command | What It Finds | Example |

|---------|--------------|--------|

| `find /path -name "*.txt"` | Files by name pattern | `find /home -name "*.log"` |

| `find /path -type d` | Only directories | `find . -type d` |

| `find /path -mtime -7` | Files modified in last 7 days | `find . -mtime -1` |

| `grep "pattern" file` | Lines matching a pattern in a file | `grep "error" app.log` |

| `grep -r "pattern" dir/` | Search recursively in a directory | `grep -r "TODO" src/` |

| `grep -i "pattern" file` | Case-insensitive search | `grep -i "warning" *.log` |

| `which command` | Where a command's binary lives | `which python3` |

| `locate filename` | Fast file search (from a database) | `locate nginx.conf` |

`grep` is arguably the most important tool in Linux. You will use it constantly — searching logs, filtering output, finding code. Learn its flags: `-i` (case-insensitive), `-r` (recursive), `-n` (show line numbers), `-v` (invert — show lines that do NOT match).

Piping and Redirection

This is the concept that separates Linux power users from beginners. **Piping** sends the output of one command as input to another:

```

command1 | command2 | command3

```

Examples:

```bash

Find the 10 largest files in current directory

ls -lS | head -10

Count how many .py files exist

find . -name "*.py" | wc -l

Find unique IP addresses in a log

cat access.log | awk '{print$1}' | sort | uniq -c | sort -rn

Search for errors and show context

grep -n "ERROR" app.log | tail -20

```

**Redirection** sends output to a file:

```bash

command > file.txt # Write output to file (overwrite)

command >> file.txt # Append output to file

command 2> errors.txt # Redirect error output

command &> all.txt # Redirect both stdout and stderr

```

Text Processing

Linux has powerful text manipulation tools. These become essential when working with logs, data files, or configuration:

| Command | Purpose | Example |

|---------|---------|--------|

| `sort` | Sort lines | `sort names.txt` |

| `uniq` | Remove adjacent duplicates | `sort names.txt \| uniq` |

| `cut -d',' -f2` | Extract a column from delimited text | `cut -d':' -f1 /etc/passwd` |

| `awk '{print $3}'` | Extract/transform columnar data | `awk '{print$1,$4}' access.log` |

| `sed 's/old/new/g'` | Find and replace in text | `sed 's/http/https/g' urls.txt` |

| `tr 'A-Z' 'a-z'` | Translate characters | `echo "HELLO" \| tr 'A-Z' 'a-z'` |

Process Management

| Command | What It Does |

|---------|-------------|

| `ps aux` | List all running processes |

| `top` or `htop` | Live process monitor (htop is more user-friendly) |

| `kill PID` | Send termination signal to a process |

| `kill -9 PID` | Force-kill a process (last resort) |

| `Ctrl+C` | Stop the currently running command |

| `Ctrl+Z` | Suspend the current command (resume with `fg` or `bg`) |

| `command &` | Run a command in the background |

| `jobs` | List background jobs |

Getting Help

Linux has built-in documentation for almost everything:

| Command | What It Shows |

|---------|---------------|

| `man command` | Full manual page (detailed, sometimes dense) |

| `command --help` | Brief usage summary |

| `tldr command` | Community-maintained simplified examples (install `tldr` first) |

| `apropos keyword` | Search manual pages by keyword |

`man` pages are dense but complete. If you want quick examples, install `tldr` — it shows the most common uses of any command.

Building Fluency

Command-line fluency comes from usage, not memorization. Strategies:

1. **Use tab completion.** Press Tab to autocomplete file names, directory names, and commands. Press Tab twice to see all options.

2. **Use command history.** Press the up arrow to cycle through previous commands. Use `Ctrl+R` to search history.

3. **Read error messages.** Linux error messages are usually informative. "Permission denied" means you need `sudo`. "No such file or directory" means check your path.

4. **Start with real tasks.** Do not memorize commands in isolation. Use them to accomplish something: organize files, search logs, process data.

5. **Alias common commands.** Add `alias ll='ls -la'` to your `~/.bashrc` for shortcuts you use frequently.

Further Reading

- [LinuxForWindowsUsers](LinuxForWindowsUsers) — The complete learning roadmap

- [Linux Filesystem and Permissions](LinuxFilesystemAndPermissions) — Understanding what `ls -la` output means

- [Linux Shell Scripting Fundamentals](LinuxShellScriptingFundamentals) — Turn command chains into reusable scripts

- [LinuxCommands](LinuxCommands) — Quick command reference

- [Linux System Administration](LinuxSystemAdministration) — Using commands to manage a system