← SnapRecaps

20% of Linux Commands You'll Use 80% of the Time (Real-World Example)

► 450,818 views ⏲ 25:01 Watch on YouTube ↗

Summary

A beginner-friendly Linux troubleshooting tutorial in Docker teaches log inspection, file navigation, finding configs, fixing a PostgreSQL port mismatch, and editing permissions with Vim.

Executive Summary

This video is a practical, beginner-friendly Linux troubleshooting tutorial run inside a Docker container, requiring no prior Docker knowledge. It walks through locating and inspecting application logs with commands like pwd, cd, ls, and grep, then shows how to filter and save relevant error lines using pipes and output redirection. The core debugging challenge involves finding a database configuration file with find, comparing it against a backup using diff, and discovering that the app is broken because it points to port 5433 while PostgreSQL runs on the default port 5432. The tutorial also covers essential file-permission fixes with chmod, editing configurations safely in Vim, and quitting read-only files without saving. After correcting the port, restarting the app and exiting the container confirms the host system, reinforcing the full workflow of navigating, filtering, editing, and securing files in a Linux environment.

Key Points

  • ▶ 0:35 Install Docker Desktop and use a provided Docker image to run a Linux environment on Mac or Windows—no Docker knowledge required.
  • ▶ 2:04 Run the container with a terminal flag to enter the Linux environment; this is all the Docker setup needed for the tutorial.
  • ▶ 2:30 The first Linux command is uname, which confirms the operating system by returning Linux.
  • ▶ 3:39 Locate application logs by checking your current directory with pwd and moving to /var/log/application using cd, then use ls/ls -l to inspect files and their details.

  • ▶ 6:23 Filter large log files by chaining commands with a pipe (|) and using grep, e.g., cat error.log | grep database, to display only relevant error lines.

  • ▶ 7:19 Save filtered results for later by redirecting output with > into a new file (e.g., database-errors.txt), then verify the file exists and has content using ls -l and cat.

  • ▶ 9:05 The log file is backed up to /root with cp database_errors.txt /root/db_errors.txt so it isn't lost when the application folder is cleared.
  • ▶ 10:57 grep "connection refused" database_errors.txt filters only the connection-refused errors, using quotes around the multi-word phrase so grep treats it as one search string.
  • ▶ 11:30 Piping the filtered output into wc -l (e.g., grep "connection refused" database_errors.txt | wc -l) counts the total number of failed connection attempts.
  • ▶ 12:20 The database config file is located by searching the entire filesystem with find for .conf files, then filtering with grep for “db” to isolate db.conf.
  • ▶ 15:00 The diff command compares db.conf against db.conf.backup, revealing the exact change that broke the app.
  • ▶ 16:15 Root cause: db.conf points to Port 5433, but PostgreSQL is running on its default Port 5432, so the app cannot connect.
  • ▶ 16:46 Verify the database is reachable using curl -I http://localhost:5432; success shows PostgreSQL is running, revealing the app is configured for the wrong port.
  • ▶ 18:22 Open the config file in vim; remember Vim has two modes — edit mode (enter with i) and navigation mode.
  • ▶ 19:11 A "Changing a read-only file" warning means you lack write permission; to exit without saving, press Escape then type :q!.
  • ▶ 20:35 Configuration files may be locked or read-only in production, so root needs write permission to modify them.
  • ▶ 21:25 chmod uses numeric modes to set permissions for user, group, and others (e.g., 000, 444, 777, and 600 for root-only read/write).
  • ▶ 22:49 Use vim with i for insert mode, then Escape and :wq to save and quit after editing.
  • ▶ 23:32 Save configuration changes in Vim using :wq! (write and quit), then verify the edit is visible in the file.
  • ▶ 23:51 After restarting the application, exit the Docker container with exit and confirm you’re back on the host machine using uname (shows Darwin).
  • ▶ 24:24 Recap: the workflow used Linux commands for troubleshooting, file navigation, config changes, and permission changes—then restore the config file to read-only with chmod for security.

Video Sections

  • ▶ 0:00 Introduction and Linux Environment Setup (0:00 - 3:10) - - Introduces the tutorial, sets up a Linux environment with Docker, and verifies the OS using uname.
  • ▶ 3:10 Inspecting and Filtering Logs (3:10 - 8:27) - - Walks through a debugging scenario: list logs with ls -l, view them with cat, filter with grep and pipes, and save output with >.
  • ▶ 8:27 Backing Up and Analyzing Connection Errors (8:27 - 11:51) - - Backs up log files with cp and filters/counts “connection refused” errors to identify database connection issues.
  • ▶ 11:51 Diagnosing the Database Configuration (11:51 - 16:46) - - Finds and compares database config files, then pinpoints that the app points to port 5433 instead of 5432.
  • ▶ 16:46 Checking the Service and Editing with Vim (16:46 - 19:56) - - Verifies PostgreSQL with curl, opens the config in Vim, and handles the read-only warning and Vim exit.
  • ▶ 19:56 Understanding and Changing File Permissions (19:56 - 23:39) - - Explains file permissions from ls -l, covers numeric permission modes, and changes permissions to enable editing.
  • ▶ 23:39 Verifying Changes and Recap (23:39 - 25:03) - - Confirms the config change, exits the Docker container, and recaps the full debugging workflow.

Exact Transcript

Load the full timestamped transcript on demand and click any time to jump in the video.