Easy Command Cookbook: 25 One‑Line Tricks You Need to Know

Easy Command Cookbook: 25 One‑Line Tricks You Need to Know

A concise, practical collection of 25 single-line command snippets for common tasks in Unix-like shells (bash, zsh, fish) and Windows PowerShell. Focused on productivity, troubleshooting, file and text manipulation, networking checks, and quick system info. Each entry includes the command, a one-line explanation, and a short example of common options or variations.

Sample sections and representative commands

  • File management
    • Find and delete empty directories:

      Code

      find . -type d -empty -delete
    • Move files by extension into a folder:

      Code

      mkdir -p images && mv.jpg images/
  • Text processing
    • Show non‑printable characters:

      Code

      sed -n l file.txt
    • Print unique sorted lines with counts:

      Code

      sort file.txt | uniq -c | sort -nr
  • Searching & pattern matching
    • Recursive grep with line numbers and color:

      Code

      grep -RIn –color=auto “pattern” .
  • Networking & troubleshooting
    • Quick HTTP check using curl:

      Code

    • List open ports (Linux):

      Code

      ss -tuln
  • System info & monitoring
    • Show top memory consumers:

      Code

      ps aux –sort=-%mem | head -n 15
    • Disk usage of current directory:

      Code

      du -sh .
  • Archiving & compression
    • Create a gzipped tar archive:

      Code

      tar czf archive.tar.gz folder/
  • Git & development
    • Amend last commit message without changing contents:

      Code

      git commit –amend -m “New message”
  • Windows PowerShell equivalents
    • List processes sorted by memory:

      Code

      Get-Process | Sort-Object -Property WS -Descending | Select-Object -First 10

Why this cookbook helps

  • Saves time with ready-to-run snippets.
  • Teaches small, composable patterns you can adapt.
  • Useful for beginners and experienced users who want quick reminders.

How to use it

  • Copy the one-liners into your terminal; try them in a safe directory first.
  • Read the short explanation before running commands that modify files.
  • Combine snippets to build longer workflows.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *