Skip to main content

Linux Command-Line Flashcard Collection formatted for Anki 🗂️

I have grouped the content into four major sections to keep the structure clean and readable. The actual flashcard text is provided inside indented markdown blocks so you can easily copy and paste them directly into your Anki Cloze notes.


🧭 1. Navigation, Files & Permissions

This section covers moving around the file system and managing files, directories, and their permissions.

  1. Working Directory & Navigation Knowing where you are and how to jump back is the foundation of terminal usage.

    To print the working directory in Linux, use the {{c1::pwd}} command. To return intuitively to the *previous* directory you were in, use the command {{c2::cd -}}.
    
      • Extra tip: You can instantly return to your user's home directory by using cd ~.
  2. Advanced Listing You rarely use plain ls when doing server maintenance.

    The command {{c1::ls -lah}} lists directory contents in a long format, including {{c2::hidden (dot)}} files, with {{c3::human-readable}} file sizes.
    
  3. Creating Directories & Files Creating structures efficiently saves a lot of time.

    To create a directory along with its parent directories as needed, use the command {{c1::mkdir -p}}. To quickly create an empty file or update an existing file's timestamp, use {{c2::touch}}.
    
  4. Copying in Archive Mode This is critical when making backups of configuration directories.

    The command {{c1::cp -a}} copies directories in "archive mode", which preserves vital metadata like {{c2::permissions}} and {{c3::times}}.
    
  5. Dangerous Deletions Always double-check your path before executing this!

    To recursively delete a directory and force the removal without prompting, use {{c1::rm -rf}} (use with extreme caution!).
    
  6. Symbolic Links Very common in web server configurations (e.g., Nginx sites-enabled).

    To create a symbolic link, use the command {{c1::ln -s}} followed by the target path and the intended link name.
    
  7. Understanding chmod Permissions Permissions mapping is a daily necessity for a system admin.

    The command `chmod {{c1::755}} script.sh` sets the permissions to `rwxr-xr-x`, meaning the owner gets read/write/execute access, while the group and others get {{c2::read}} and {{c3::execute}} access only.
    
  8. Recursive Ownership Changes Often used when setting up web roots for service accounts.

    To change the owner and group of a directory recursively, use the command {{c1::chown}} combined with the {{c2::-R}} flag.
    

This section focuses on streaming data, reading logs, and transforming text output using pipes.

  1. Choosing the Right Pager Don't flood your screen with giant log files.

    For reading small files, {{c1::cat}} is useful, but for paging through large text files interactively, you should prefer {{c2::less}}.
    
  2. Tailing Logs Live Essential for real-time debugging.

    To view the last 50 lines of an error log, use `tail` with the {{c1::-n 50}} option. To "follow" appended log lines in real-time, use the {{c2::-f}} option.
    
  3. Grep Essentials Searching inside files is arguably the most used diagnostic technique.

    In the command `grep -R "DB_HOST" .`, the `-R` flag stands for {{c1::recursive search}}. To simultaneously include line numbers in your output, you would append the {{c2::-n}} flag.
    
  4. The Stream Editor (Sed) Basics Used for mass finding/replacing data streaming through the terminal.

    The stream editor {{c1::sed}} processes text one line at a time. The command `sed 's/http:/https:/g'` uses the {{c2::g}} flag to replace {{c3::all matches}} in the line.
    
      • Printing control: By default, sed prints every line. Combine the -n (suppress) flag with the p command to selectively print lines (e.g., sed -n '1,20p').
  5. In-Place File Edits with Sed Direct manipulations require caution but are incredibly powerful.

    To perform an in-place edit using sed (which modifies the file directly on disk), you must use the {{c1::-i}} flag.
    
  6. Awk for Column Data When parsing space-delimited logs, awk is king.

    The {{c1::awk}} command is excellent for column processing. For example, `awk '{print \$1, \$9}'` extracts the first and ninth {{c2::fields}}.
    
  7. Sorting and Unique-ing Collapsing duplicate log entries to find anomalies.

    The {{c1::uniq}} command collapses adjacent duplicates, meaning it is almost inevitably preceded by the {{c2::sort}} command in a text pipeline.
    
  8. Bash Redirection Operators Mastering standard out and standard error streams.

    In Bash redirection, {{c1::>}} completely overwrites a file, {{c2::>>}} safely appends to a file, and {{c3::2>}} specifically redirects standard error.
    
  9. The tee Command Splitting the stream to a file and the screen at the same time.

    The {{c1::tee}} command takes standard input and writes it to both {{c2::standard output (the terminal)}} and one or more {{c3::files}}.
    

⚙️ 3. System, Network & Remote Operations

This section is all about managing running processes, network connections, and archives.

  1. Piping Process States The standard way to check if a specific daemon is running.

    To show all running processes and filter specifically for `nginx`, use the pipeline: `{{c1::ps aux}} | {{c2::grep nginx}}`.
    
  2. Signaling Processes Asking nicely versus pulling the plug.

    To gracefully request a process to terminate via its PID, use the command `kill {{c1::-TERM}} 1234`. To force termination as a last resort, use `kill {{c2::-KILL}} 1234`.
    
      • Targeting by name: Instead of finding the PID first, you can use pkill followed by the process name.
  3. Systemd Services & Logs The modern Linux initialization and logging standard.

    On modern distributions, system services are started/enabled using the {{c1::systemctl}} command, while system logs are queried using {{c2::journalctl}}.
    
  4. Network Sockets Seeing what ports your web server is binding to.

    To view TCP and UDP listening ports along with their associated process names, the standard modern command is {{c1::ss -tulpn}}.
    
  5. Debugging Web Requests Checking HTTP responses directly from the console without a browser.

    The command {{c1::curl -I}} fetches only the HTTP {{c2::headers}} of a target URL, while {{c3::curl -v}} provides a verbose output useful for TLS and connection debugging.
    
  6. DNS Troubleshooting Verifying domain propagation.

    To perform a DNS lookup for the domain `example.com`, the modern tool typically used is {{c1::dig}}, though older tutorials may still reference {{c2::nslookup}}.
    
  7. Tarball Creation & Extraction The default way to bundle up folders in Linux.

    To create a gzip-compressed tar archive of a directory, use the command `tar {{c1::-czf}} archive.tar.gz dir/`. To extract that same archive, use `tar {{c2::-xzf}}`.
    
  8. Secure File Transfers Moving backups or code safely using SSH protocols.

    To copy a file securely over SSH from your local machine to the `/tmp/` directory on a remote server, use the syntax: {{c1::scp file.txt user@server:/tmp/}}.
    

🛠️ 4. Help, Discovery & Environment States

This section is tailored to discovering help, finding lost files, and managing the active shell environment.

  1. Manual Pages Keyword Search What if you forget the name of the tool you need?

    The {{c1::man}} command opens comprehensive manual pages. If you need to search within descriptions by a keyword, you should use {{c2::man -k}}.
    
  2. Command Execution Origins Understanding whether you are running a binary, alias, or built-in shell function.

    To discover the source path of a binary like Python, use `which`. To find out if a command is actually an alias or a shell builtin, use the {{c1::type}} command instead.
    
  3. Finding Files by Date or Size Locating hidden bloat or analyzing recent compromises.

    To search for files modified strictly within the last 7 days inside `/var/log`, use the command `find /var/log -type f {{c1::-mtime -7}}`.
    
      • Size flags: To search for files larger than 100MB, use the -size +100M flag.
  4. Locate vs. Find The trade-off between speed and accuracy.

    The {{c1::locate}} command provides a fast filename search using a pre-compiled {{c2::database}}, which means you must periodically update its index for it to reflect recent file changes.
    
  5. Printing the Environment Confirming your paths or custom variables.

    To print text or the value of a shell variable (like `\$HOME`) directly to the console, use the {{c1::echo}} command.
    
  6. Environment Variable Scope Differentiating local variables from inherited variables.

    To set an environment variable for the duration of the current shell session so that child processes inherit it (e.g., `NODE_ENV=production`), use the {{c1::export}} command.
    
  7. Reviewing Past Commands A lifesaver when you execute a complex chained pipeline and need to see exactly what you did.

    To output a numbered list of your previously executed shell commands, use the {{c1::history}} command.