Skip to main content

Linux CLI Essentials

Intro – what & why

The Linux command line is the simplest, most reliable way to inspect files, run processes, and automate tasks on development machines and servers. This page gives a compact, practical set of commands and a short workflow most developers use daily.

Concept explained

The shell (bash, zsh, etc.) interprets commands you type. Key concepts:

  • Files and directories: absolute vs relative paths.
  • Standard streams: stdin, stdout, stderr; redirection and pipes.
  • Permissions and ownership: who can read/write/execute.
  • Processes: run, background, and stop programs.

Knowing a few commands lets you navigate projects, inspect logs, search, and safely modify files.

Step-by-step example

Goal: open a project, find TODOs, view a log, and create a backup of a config file.

Commands you can copy-paste:

# Go to your project directory
cd ~/projects/my-app

# See where you are and list hidden files
pwd
ls -la

# Find lines containing "TODO" in .js and .py files (recursive)
grep -R --line-number --exclude-dir=node_modules "TODO" --include="*.js" --include="*.py"

# View the end of a log file and follow new lines
tail -n 100 logs/app.log
tail -f logs/app.log

# Create a timestamped backup of a config
cp config.yml "config.yml.$(date +%F_%H%M%S).bak"

# Show file permissions and owner
ls -l config.yml

# Edit the file with a simple terminal editor (nano is common)
nano config.yml
# or use vim if you prefer
vim config.yml
tip

Use --exclude-dir with grep or find to avoid scanning large folders like node_modules.

Variations & gotchas

  • Different shells: bash and zsh behave mostly the same for these commands, but shell-specific config files differ (~/.bashrc vs ~/.zshrc).
  • Files with spaces require quotes: cp "my file.txt" "backup.txt".
  • Case sensitivity: Linux filenames are case-sensitive (File.txtfile.txt).
  • Redirection: > overwrites, >> appends.
caution

Be careful with rm -rf – it removes recursively and without confirmation. Double-check the path before running.

Common mistakes

  • Running destructive commands as root unnecessarily (use sudo only when needed).
  • Forgetting to quote paths with spaces.
  • Using rm instead of moving files to a separate temporary folder for recovery.
  • Confusing > (overwrite) and >> (append) when redirecting output.

Best practices

  • Learn man and --help: man grep, command --help.
  • Use tab completion and history (Ctrl+R) to speed up work.
  • Alias dangerous commands in your shell config, e.g. alias rm="rm -i" while learning.
  • Keep small, timestamped backups before editing important files.
  • Use set -o noclobber in scripts to avoid accidental overwrites (or >| to force).

When to use / when not to use

When to use the CLI:

  • Quick file inspection and edits on remote servers.
  • Automation through scripts.
  • Searching logs and debugging running processes.

When not to use:

  • Complex visual tasks (image editing, heavy design).
  • If a GUI tool is safer for non-technical users (e.g., database management for novices).

Key takeaways

  • Learn a handful of commands (cd, ls, grep, tail, cp, mv, rm, chmod, chown) – they cover most day-to-day needs.
  • Use pipes and redirection to combine tools (grep pattern file | less).
  • Protect yourself from accidents: backups, aliases, and cautious use of sudo.