Use the right command line prompts to instantly troubleshoot your router’s Wi-Fi, permissions errors, or slow connections—without wasting time guessing. These commands work across Linux, macOS, and even Windows Subsystem for Linux (WSL). No admin rights are needed for most of them, but you’ll need basic familiarity with text input.

What You'll Need

  • A computer running Linux, macOS, or Windows 10/11 with WSL installed (to use Linux commands on Windows).
  • Basic typing skills—no coding experience required.
  • Admin or sudo access for commands modifying system files (e.g., `/etc/`).
  • Your router’s admin panel credentials (if troubleshooting network settings).
  • Terminal or command prompt open (press Ctrl+Alt+T on Linux/macOS or search "Terminal" on Windows).

Step-by-Step

  1. Open your terminal.
    1. On Linux/macOS: Press Ctrl+Alt+T or search for "Terminal."
    2. On Windows (WSL): Open PowerShell or Command Prompt, then type wsl to switch to WSL (if installed).
  2. Check your network connection. Use these prompts to diagnose Wi-Fi issues:
    1. ping 8.8.8.8 – Tests if your internet is working (Google’s DNS server). If packets are lost, your connection is unstable.
    2. ifconfig (Linux/macOS) or ipconfig /all (Windows) – Lists all network interfaces. Look for wlan0 (Wi-Fi) or eth0 (Ethernet).
    3. curl ifconfig.me – Shows your public IP address (useful for port-forwarding checks).
    4. nslookup google.com – Verifies DNS resolution. If it fails, your router’s DNS may be misconfigured.
  3. Fix permission errors. Common issues (e.g., "Permission denied") are solved with:
    1. sudo chmod -R 755 /path/to/folder – Grants read/write/execute permissions to a folder (use sudo if prompted).
    2. ls -la – Lists hidden files/folders with permissions (e.g., -rw-r--r-- means owner can read/write).
    3. chown -R user:group /path/to/file – Changes ownership (replace user:group with your username and group).
    Warning: Modifying system files (/bin/, /sbin/) can break your system. Only edit user directories (e.g., ~/Downloads).
  4. Search and delete files. Use these to find and remove files safely:
    1. find /home -type f -name "*.log" – Searches for all .log files in your home directory.
    2. rm /path/to/file – Deletes a file. Add -r for folders (e.g., rm -r old_backups).
    3. grep "error" /var/log/syslog – Searches system logs for errors (requires sudo on Linux).
    Caution: The rm command is irreversible. Double-check paths with ls before deleting.
  5. Optimize slow Wi-Fi. Run these to check and fix bottlenecks:
    1. iwconfig – Shows Wi-Fi signal strength. Look for Signal level (higher = better).
    2. sudo iwlist scan – Lists nearby networks and their channels. Switch to a less crowded channel in your router settings.
    3. speedtest-cli (install with sudo apt install speedtest-cli on Debian/Ubuntu) – Tests download/upload speeds.
    4. sudo lsof -i :80 – Checks if port 80 (HTTP) is blocked by another app (use sudo on Linux).
  6. Edit system files (advanced). For custom configurations (e.g., /etc/hosts):
    1. Open the file with sudo nano /etc/hosts (install nano with sudo apt install nano if missing).
    2. Make changes, then save with Ctrl+O and exit with Ctrl+X.
    3. Apply changes with sudo systemctl restart networking (Linux) or reboot.
    Warning: Editing system files can cause instability. Backup first with sudo cp /etc/hosts /etc/hosts.bak.

Common Mistakes

  1. Ignoring permission errors. Many users try to force commands (e.g., rm -rf /), which can destroy your OS. Always use sudo or chmod first.
  2. Running `rm` without verification. The rm -rf combo is infamous for deleting entire hard drives. Always check paths with ls before deleting.
  3. Assuming `ping` = internet access. ping 8.8.8.8 checks connectivity to Google’s DNS, but other sites may fail due to DNS issues. Use nslookup to verify.
  4. Overlooking typos in commands. ping google.com fails if you mistype it as ping googel.com. Terminal is case-sensitive—double-check spelling.
  5. Forgetting to install tools. Some commands (e.g., speedtest-cli) require installation. Use sudo apt install (Debian/Ubuntu) or brew install (macOS).

Tips

  • Use tab completion. Start typing a command or path, then press Tab to auto-fill it (saves time and reduces errors).
  • Pipe output for cleaner results. Combine commands with |. Example: ps aux | grep "nginx" lists all Nginx processes.
  • Save frequently used commands. Create a text file (e.g., ~/.bash_aliases) with your go-to prompts and source it with source ~/.bash_aliases.
  • Check man pages for help. Type man (e.g., man ping) for detailed usage. Press q to exit.
  • Use `sudo !!` to repeat the last command. If you forgot sudo, type sudo !! to rerun the previous command with elevated privileges.
  • Test commands in a VM first. If you’re unsure about a risky command (e.g., modifying /etc/), practice in a virtual machine or Docker container.

Troubleshooting

If a command fails, follow this order:

  1. Check spelling and syntax. Copy-paste commands from this guide to avoid typos. For example, ping google.com ≠ ping goole.com.
  2. Verify permissions. If you get "Permission denied," prepend sudo or check ownership with ls -la.
  3. Restart your router. Network issues often resolve after a reboot. Unplug the router for 30 seconds, then reconnect.
  4. Check for typos in paths. Commands like find /home -name "file.txt" fail if the path is wrong. Use pwd to confirm your current directory.
  5. Update your system. Outdated software can cause command failures. Run:
    1. Linux: sudo apt update && sudo apt upgrade (Debian/Ubuntu).
    2. macOS: softwareupdate --list (check for updates).
  6. Reinstall the terminal app. Corrupted installations can cause crashes. Reset it via:
    1. Windows: winget upgrade Microsoft.WindowsTerminal.
    2. macOS: Delete /Applications/Utilities/Terminal.app, then reinstall from the App Store.
    3. Linux: sudo apt reinstall gnome-terminal (Ubuntu).
  7. Try WSL if on Windows. If native Command Prompt fails, enable WSL (Windows Subsystem for Linux) via Settings > Apps > Optional Features > Add a Feature, then install Ubuntu from the Microsoft Store.
  8. Check for conflicting apps. Some security software (e.g., antivirus) blocks terminal commands. Temporarily disable them to test.
  9. Factory reset your router (last resort). If network commands fail, reset your router to default settings via the Reset button (usually a small hole on the back). Note: This erases all custom configurations.

Frequently Asked Questions

Why does `ping` work but my browser doesn’t load pages?

This usually means your DNS is misconfigured. Try switching to Google’s DNS (8.8.8.8, 8.8.4.4) in your router settings or use sudo dscacheutil -flushcache (macOS) to clear the local DNS cache.

How do I list all users on my Linux system?

Use getent passwd to show all users, or cat /etc/passwd for a raw list. Avoid editing this file manually unless you know what you’re doing.

Can I use these commands on my Android phone?

No, these commands require a full terminal (Linux/macOS/WSL). However, you can use Termux (Android app) for limited Linux-like functionality, but it lacks root access by default.

What does `sudo: command not found` mean?

This happens if you’re not using a Linux/macOS system or if WSL isn’t installed (Windows). On Windows, enable WSL via Settings > Apps > Optional Features > Add a Feature, then install Ubuntu from the Microsoft Store.

How do I find a file I deleted?

If you deleted files without rm, check the Trash (macOS/Linux). If using rm -rf, recovery depends on your filesystem. For Linux, try Extundelete (advanced) or use a data recovery tool like TestDisk. On Windows, use File History or third-party tools like Recuva.

Why does `ifconfig` say “no wireless extensions”?

This means your Wi-Fi adapter isn’t supported or drivers are missing. Check your laptop/model online and install the correct drivers (e.g., iwconfig may work if ifconfig doesn’t). On some systems, use ip a instead of ifconfig.

Is it safe to edit `/etc/hosts`?

Yes, but proceed with caution. This file maps domain names to IPs. To block a website, add a line like 127.0.0.1 example.com. Always back up the file first with sudo cp /etc/hosts /etc/hosts.bak.