Cheatsheet

23 entries

commands and tricks for day to day

  • Delete All Commit History on GitHub

    Reset a repository's commit history by creating an orphan branch

    git checkout --orphan latest_branch
    git add -A
    git commit -am "reset configs"
    git branch -D main
    git branch -m main
    git push -f origin main
  • Chrome Bookmarks (filter by folder)

    Extract URLs from a specific Chrome bookmark folder using jq

    cat ~/.config/google-chrome/Default/Bookmarks \
      | jq -r '.roots.bookmark_bar.children[]
          | select(.name == "tree")
          | .children[]
          | .url'
  • Chrome Bookmarks (list all)

    List all bookmarks from Chrome's JSON file showing name and URL

    cat ~/.config/google-chrome/Default/Bookmarks \
      | jq '.roots.bookmark_bar.children[] | {name: .name, url: .url}'
  • Chrome Bookmarks (list folders)

    List all Chrome bookmark folders using jq

    cat ~/.config/google-chrome/Default/Bookmarks \
      | jq -r '[.. | objects | select(.type == "folder") | .name] | unique | sort | .[]'
  • Chrome Internals Pages

    Useful chrome:// internal pages for debugging DNS, events, and proxy settings

    chrome://net-internals/#dns
    chrome://net-internals/#events
    chrome://net-internals/#proxy
  • Chrome Bookmarks MacOS(bookmark bar root)

    List all entries from the root of Chrome's bookmarks bar

    jq -r '.roots.bookmark_bar.children[]' \
      "$HOME/Library/Application Support/Google/Chrome/Default/Bookmarks"
  • Post-install Docker

    Add current user to docker group after installation

    sudo usermod -aG docker $USER
    exec su -l $USER
    groups $USER
    docker ps
  • k6 Load Testing

    Basic k6 script with ramp-up, sustained load, and ramp-down stages

    import http from 'k6/http';
    import { sleep } from 'k6';
    
    export const options = {
        stages: [
            { duration: '10s', target: 100 },
            { duration: '30s', target: 100 },
            { duration: '10s', target: 0 }
        ]
    }
    
    export default function () {
        http.get('http://192.168.68.108:3000');
        sleep(1);
    }
  • ntfy Send Notification

    Send a push notification via ntfy.sh using curl

    curl -d "Backup successful" ntfy.sh/mytopic
  • curl with --resolve

    Force curl to resolve a hostname to a specific IP address, bypassing DNS

    curl --resolve <hostname>:<porta>:<ip> <protocolo>://<hostname>:<porta>
    curl --resolve meuservidor.com:8080:192.168.0.100 http://meuservidor.com:8080
    curl --resolve google.com:8888:127.0.0.1 https://google.com:8888
  • Windows Activation (massgrave)

    Activate Windows using the massgrave open-source script

    irm https://massgrave.dev/get | iex
  • View WiFi Passwords

    Retrieve saved WiFi passwords on Linux using NetworkManager

    ls /etc/NetworkManager/system-connections/
    sudo cat /etc/NetworkManager/system-connections/[network-name]
    nmcli device wifi list
    sudo nmcli connection show "<wifi_name>" --show-secrets
  • Encrypt / Decrypt File with Password

    Use OpenSSL AES-256-CBC with PBKDF2 to encrypt and decrypt files

    # Encrypt
    echo "Este é um arquivo de teste" > original.txt
    openssl enc -aes-256-cbc -salt -pbkdf2 -in original.txt -out secreto.enc
    
    # Decrypt
    openssl enc -aes-256-cbc -d -salt -pbkdf2 -in secreto.enc
    
    # Decrypt from remote URL
    curl -s https://raw.githubusercontent.com/apolzek/apolzek.github.io/main/secreto.enc \
      | openssl enc -aes-256-cbc -d -salt -pbkdf2
  • Linux Network Connections

    View all saved NetworkManager connection configs

    sudo cat /etc/NetworkManager/system-connections/*
  • Set Network Interface MTU

    Lower the MTU on a network interface to avoid packet drops (e.g. on iPhone tethering)

    sudo ip link set wlp3s0 mtu 1280
  • macOS DNS Commands

    Commands for viewing, configuring, and troubleshooting DNS on macOS

    # Show current DNS resolver configuration (system-wide)
    scutil --dns
    
    # Display DNS servers currently in use (per interface)
    networksetup -getdnsservers Wi-Fi
    
    # Set custom DNS servers for Wi-Fi (replace with your desired servers)
    sudo networksetup -setdnsservers Wi-Fi 1.1.1.1 8.8.8.8
    
    # Reset DNS back to automatic (DHCP-provided DNS)
    sudo networksetup -setdnsservers Wi-Fi empty
    
    # Flush DNS cache (modern macOS)
    sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
    
    # Query DNS resolution for a domain (low-level system resolver test)
    dig example.com
    
    # Alternative DNS lookup tool (simpler output)
    nslookup example.com
    
    # Test which DNS server is resolving a domain
    dig example.com +short
    
    # Show detailed resolver behavior and search domains
    scutil --dns | grep 'nameserver'
    
    # Check current network services (to identify correct interface name)
    networksetup -listallnetworkservices
    
    # View DNS configuration for a specific interface (example: Ethernet)
    networksetup -getdnsservers Ethernet
    
    # Set DNS for Ethernet interface
    sudo networksetup -setdnsservers Ethernet 9.9.9.9 1.1.1.1
  • Ubuntu Linux DNS Commands

    Commands for viewing, configuring, and troubleshooting DNS on Ubuntu (systemd-resolved and NetworkManager based systems)

    # Show current DNS configuration (systemd-resolved)
    resolvectl status
    
    # Alternative command (older systems)
    systemd-resolve --status
    
    # Show DNS servers currently in use per interface
    nmcli dev show | grep DNS
    
    # Show NetworkManager connection profiles
    nmcli connection show
    
    # Set DNS servers for a specific connection (replace 'Wired connection 1')
    sudo nmcli connection modify "Wired connection 1" ipv4.dns "1.1.1.1 8.8.8.8"
    
    # Ignore DHCP-provided DNS and use manual DNS
    sudo nmcli connection modify "Wired connection 1" ipv4.ignore-auto-dns yes
    
    # Restart connection to apply DNS changes
    sudo nmcli connection down "Wired connection 1" && sudo nmcli connection up "Wired connection 1"
    
    # Flush DNS cache (systemd-resolved)
    sudo resolvectl flush-caches
    
    # Alternative cache restart (forces full reload of resolver)
    sudo systemctl restart systemd-resolved
    
    # Query DNS resolution using system resolver
    getent hosts example.com
    
    # Query DNS records with dig (recommended tool)
    dig example.com
    
    # Query specific DNS record type (A record)
    dig example.com A
    
    # Show trace of DNS resolution path
    dig example.com +trace
    
    # Simple DNS lookup tool (basic output)
    nslookup example.com
    
    # Check /etc/resolv.conf (often symlinked to systemd stub)
    cat /etc/resolv.conf
    
    # Verify if systemd stub resolver is active
    ls -l /etc/resolv.conf
    
    # Temporarily set DNS by editing resolv.conf (not persistent on most modern systems)
    sudo bash -c 'echo -e "nameserver 1.1.1.1\nnameserver 8.8.8.8" > /etc/resolv.conf'
  • macOS Clipboard Basic Commands

    Minimal commands to copy file content to clipboard and paste it back

    # Copy file content to clipboard using pipe
    cat arquivo.txt | pbcopy
    
    # Paste clipboard content in terminal
    pbpaste
  • Linux Clipboard (Ubuntu) Equivalent to pbcopy/pbpaste

    Setup and commands to copy file content to clipboard and paste it back on Ubuntu using xclip or xsel

    # Install clipboard utility (xclip)
    sudo apt update && sudo apt install -y xclip
    
    # Copy file content to clipboard (equivalent to: cat arquivo.txt | pbcopy)
    cat arquivo.txt | xclip -selection clipboard
    
    # Paste clipboard content to terminal (equivalent to pbpaste)
    xclip -selection clipboard -o
    
    # Alternative install (xsel instead of xclip)
    sudo apt install -y xsel
    
    # Copy file content using xsel
    cat arquivo.txt | xsel --clipboard --input
    
    # Paste clipboard content using xsel
    xsel --clipboard --output
    
    # Optional aliases for convenience (add to ~/.bashrc or ~/.zshrc)
    alias pbcopy='xclip -selection clipboard'
    alias pbpaste='xclip -selection clipboard -o'
  • Finds all files larger than 10 MB in the current directory tree

    Searches recursively for files larger than 10 MB, filters out any files inside .git directories, removes the leading ./ from the paths, and appends the resulting file paths to .gitignore.

    find . -type f -size +10M | grep -v ".git" | sed 's|^\./||' >> .gitignore 
  • Linux Inotify Cheat Sheet

    Quick reference for checking, increasing, and troubleshooting Linux Inotify limits, including watches, instances, event queues, and common filesystem monitoring errors.

    # Show current inotify limits
    sysctl fs.inotify.max_user_instances
    sysctl fs.inotify.max_user_watches
    sysctl fs.inotify.max_queued_events
    
    # Show all inotify-related kernel parameters
    sysctl -a | grep inotify
    
    # Temporarily increase the maximum number of inotify instances per user
    sudo sysctl -w fs.inotify.max_user_instances=1024
    
    # Temporarily increase the maximum number of watched files/directories per user
    sudo sysctl -w fs.inotify.max_user_watches=1048576
    
    # Temporarily increase the inotify event queue size
    sudo sysctl -w fs.inotify.max_queued_events=65536
    
    # Persist custom inotify limits across reboots
    sudo tee /etc/sysctl.d/99-inotify.conf > /dev/null <<EOF
    fs.inotify.max_user_instances=1024
    fs.inotify.max_user_watches=1048576
    fs.inotify.max_queued_events=65536
    EOF
    
    # Reload all sysctl configuration files
    sudo sysctl --system
    
    # Reload a specific sysctl configuration file
    sudo sysctl -p /etc/sysctl.d/99-inotify.conf
    
    # Check how many watches are currently allocated system-wide
    sudo find /proc/*/fdinfo -type f 2>/dev/null | xargs grep -h '^inotify' 2>/dev/null | wc -l
    
    # Show processes using inotify
    sudo lsof | grep inotify
    
    # Show per-process inotify usage (PID and count)
    for pid in /proc/[0-9]*; do
      count=$(grep -c '^inotify' "$pid"/fdinfo/* 2>/dev/null)
      [ "$count" -gt 0 ] && echo "$(basename "$pid"): $count"
    done
    
    # Monitor filesystem events in real time (requires inotify-tools)
    inotifywait -m /path/to/watch
    
    # Monitor recursively including subdirectories
    inotifywait -mr /path/to/watch
    
    # Watch for specific events only
    inotifywait -m -e create,modify,delete /path/to/watch
    
    # Continuously print filesystem events
    inotifywatch -v /path/to/watch
    
    # Install inotify-tools (Debian/Ubuntu)
    sudo apt install inotify-tools
    
    # Install inotify-tools (RHEL/CentOS/Fedora)
    sudo dnf install inotify-tools
    
    # Check kernel messages for inotify-related errors
    dmesg | grep -i inotify
    
    # Find common watch-limit errors in logs
    journalctl -xe | grep -Ei 'inotify|watch'
  • Linux Performance Analysis

    Linux Performance Analysis Commands

    uptime
    dmesg | tail
    vmstat 1
    mpstat -P ALL 1
    pidstat 1
    iostat -xz 1
    free -m
    sar -n DEV 1
    sar -n TCP,ETCP 1
    top
  • VirtualBox Guest Additions (Ubuntu)

    Install Guest Additions on an Ubuntu guest, plus the ISO/Extension Pack setup on the host

    ### HOST (your machine running VirtualBox) ###
    
    # Ships the ISO at /usr/share/virtualbox/VBoxGuestAdditions.iso
    # Skip it if VirtualBox came from Oracle's .deb (ISO already bundled)
    sudo apt install virtualbox-guest-additions-iso
    
    # Needed for USB passthrough
    sudo usermod -aG vboxusers $USER
    
    # Optional Extension Pack (USB 2.0/3.0, RDP) - version MUST match
    VBoxManage --version
    VBoxManage extpack install ~/Downloads/Oracle_VM_VirtualBox_Extension_Pack-*.vbox-extpack
    VBoxManage list extpacks
    
    ### GUEST (inside the Ubuntu VM) ###
    
    # Build deps - dkms rebuilds the module after kernel upgrades
    sudo apt update
    sudo apt install build-essential dkms linux-headers-$(uname -r)
    
    # Menu: Devices > Insert Guest Additions CD image, then:
    sudo mkdir -p /mnt/cdrom
    sudo mount /dev/cdrom /mnt/cdrom
    sudo /mnt/cdrom/VBoxLinuxAdditions.run
    sudo reboot
    
    # Alternative without the ISO (may lag the host version slightly)
    sudo apt install virtualbox-guest-x11   # virtualbox-guest-utils if headless
    
    # Shared folders access - logout/login afterwards
    sudo usermod -aG vboxsf $USER
    
    # Verify (in the guest, after reboot)
    lsmod | grep vboxguest
    modinfo vboxguest | grep version