Skip to content

Instantly share code, notes, and snippets.

@ephbaum
Last active January 6, 2024 05:39
Show Gist options
  • Save ephbaum/573b0aab6b63c631d35060c309b09453 to your computer and use it in GitHub Desktop.
Save ephbaum/573b0aab6b63c631d35060c309b09453 to your computer and use it in GitHub Desktop.
Linux Cheatsheets

Linux Cheat Sheet for Advanced Users

Scripting and Automation

  • Write a bash script: Create a file with #!/bin/bash at the top and script contents.
  • Execute a bash script: bash [script_file]
  • Schedule a cron job: crontab -e and add line [minute] [hour] [day_of_month] [month] [day_of_week] [command]

Server Setup and Management

  • Install packages (Debian/Ubuntu): apt-get install [package]
  • Install packages (RedHat/CentOS): yum install [package] or dnf install [package]
  • Start/stop a service: systemctl start [service] or systemctl stop [service]
  • Enable/disable a service at boot: systemctl enable [service] or systemctl disable [service]

System Security

  • Change file access control lists: setfacl -m u:[user]:[permissions] [file]
  • Firewall management (iptables): iptables [options]
  • Scan for vulnerabilities (with nmap): nmap -sV -T4 -O -F --version-light [target]

Kernel and System Performance

  • Display kernel messages: dmesg
  • Modify kernel parameters at runtime: sysctl -w [parameter]=[value]
  • Monitor system performance: vmstat, iostat
  • Check available entropy: cat /proc/sys/kernel/random/entropy_avail

Network Troubleshooting

  • Trace route to host: traceroute [host]
  • Monitor network traffic: tcpdump [options]
  • Analyze network performance: iperf3 -s (server) and iperf3 -c [server_ip] (client)

Note: Replace [script_file], [package], [service], [user], [permissions], [file], [options], [target], [parameter], [value], [host], and [server_ip] with your specific details.

Arch Linux and Manjaro Cheat Sheet

Arch Linux Package Management (Pacman)

  • Synchronize and update packages: sudo pacman -Syu
  • Install a package: sudo pacman -S [package]
  • Remove a package and its dependencies: sudo pacman -Rs [package]
  • Search for a package: pacman -Ss [package]
  • List installed packages: pacman -Q

AUR (Arch User Repository) - Common for Arch and Manjaro

  • Install an AUR helper (like yay): git clone [yay_repo_url], then build and install with makepkg -si
  • Install a package from AUR: yay -S [package]

System Configuration for Arch

  • Edit the mirror list: sudo nano /etc/pacman.d/mirrorlist
  • Update the system's locale: sudo nano /etc/locale.gen then sudo locale-gen
  • Set the timezone: sudo timedatectl set-timezone [timezone]

Manjaro Specific Package Management (Pamac)

  • Update system: pamac update
  • Install a package: pamac install [package]
  • Remove a package: pamac remove [package]
  • Search for a package: pamac search [package]

System Services (systemd) - Common for Arch and Manjaro

  • Start a service: sudo systemctl start [service]
  • Enable a service to start at boot: sudo systemctl enable [service]
  • Check the status of a service: systemctl status [service]

Note: Replace [package], [yay_repo_url], [service], [timezone] with your specific details.

Linux Cheat Sheet for Beginners

Basic Navigation

  • List files and directories: ls
  • Change directory: cd [directory]
  • Print current directory: pwd
  • Display contents of a file: cat [file]

File and Directory Operations

  • Create a new file: touch [file]
  • Create a new directory: mkdir [directory]
  • Copy files or directories: cp [source] [destination]
  • Move/rename files or directories: mv [source] [destination]
  • Delete a file: rm [file]
  • Delete a directory: rm -r [directory]

Viewing and Editing Files

  • Open a file in a text editor (Nano): nano [file]
  • Open a file in a text editor (Vim): vim [file]
  • Display the beginning of a file: head [file]
  • Display the end of a file: tail [file]
  • Search within a file: grep '[pattern]' [file]

System Information and Management

  • Display system date and time: date
  • Display disk usage: df
  • Display free memory: free
  • Shutdown the system: shutdown now
  • Reboot the system: reboot

Note: Replace [file], [directory], and [pattern] with your specific details.

Debian and Ubuntu Linux Cheat Sheet

Common Package Management (APT)

  • Update package list: sudo apt update
  • Upgrade all packages: sudo apt upgrade
  • Install a package: sudo apt install [package]
  • Remove a package: sudo apt remove [package]
  • Search for a package: apt search [package]

System Services (systemd)

  • Start a service: sudo systemctl start [service]
  • Stop a service: sudo systemctl stop [service]
  • Enable a service to start at boot: sudo systemctl enable [service]
  • Disable a service from starting at boot: sudo systemctl disable [service]

User Management

  • Add a new user: sudo adduser [username]
  • Delete a user: sudo deluser [username]
  • Add a user to a group: sudo usermod -aG [group] [username]

Networking

  • Debian - Edit network configuration: sudo nano /etc/network/interfaces
  • Ubuntu - Edit network configuration: sudo nano /etc/netplan/*.yaml then apply with sudo netplan apply
  • Assign IP address with DHCP: sudo dhclient [interface]
  • Display network configuration: ip addr

Ubuntu Specific

  • Use Snap for package management: sudo snap install [package]
  • List Snap packages: snap list
  • Remove Snap package: sudo snap remove [package]

Note: Replace [package], [service], [username], [group], [interface] with your specific details.

Fedora and Red Hat Enterprise Linux (RHEL) Cheat Sheet

Package Management (DNF for Fedora, YUM for RHEL)

  • Fedora - Update package list and upgrade: sudo dnf update
  • RHEL - Update package list and upgrade: sudo yum update
  • Install a package: sudo dnf install [package] or sudo yum install [package]
  • Remove a package: sudo dnf remove [package] or sudo yum remove [package]
  • Search for a package: dnf search [package] or yum search [package]

System Services (systemd)

  • Start a service: sudo systemctl start [service]
  • Stop a service: sudo systemctl stop [service]
  • Enable a service to start at boot: sudo systemctl enable [service]
  • Disable a service from starting at boot: sudo systemctl disable [service]

User Management

  • Add a new user: sudo useradd [username]
  • Delete a user: sudo userdel [username]
  • Add a user to a group: sudo usermod -aG [group] [username]

SELinux Management

  • Check SELinux status: sestatus
  • Change file or directory SELinux context: sudo chcon -t [context_type] [file_or_directory]
  • Manage SELinux booleans: sudo setsebool [boolean_name] [on|off]

Networking

  • Assign IP address with DHCP: sudo dhclient [interface]
  • Display network configuration: nmcli d
  • Edit network configuration: sudo nmtui

RHEL Specific

  • Register with Red Hat Subscription Manager: sudo subscription-manager register
  • Attach a subscription: sudo subscription-manager attach --auto

Note: Replace [package], [service], [username], [group], [interface], [context_type], [file_or_directory], [boolean_name] with your specific details.

Linux Cheat Sheet for Intermediate Users

System Monitoring

  • Display active processes: top or htop
  • Monitor system logs: tail -f /var/log/syslog (Debian/Ubuntu) or /var/log/messages (RedHat/CentOS)
  • Display disk usage: df -h
  • Check memory usage: free -m
  • List processes: ps aux

Network Commands

  • Display network configuration: ifconfig or ip addr
  • Ping a host: ping [host]
  • Scan network with nmap: nmap [options] [host]
  • Display listening ports: netstat -tuln or ss -tuln

Process Management

  • Kill a process: kill [pid] or killall [process_name]
  • Change priority of a running process: renice [nice_value] [pid]
  • Start a job in the background: [command] &
  • Bring a job to the foreground: fg [job_number]

User and Group Management

  • Add a new user: useradd [username]
  • Change user password: passwd [username]
  • Add a user to a group: usermod -aG [group] [username]
  • Create a new group: groupadd [groupname]
  • List groups of a user: groups [username]

File Permissions and Ownership

  • Change file permissions: chmod [permissions] [file]
    • Examples:
      • chmod 755 [file]: rwx for owner, rx for group and others.
      • chmod 644 [file]: rw for owner, r for group and others.
  • Change file owner: chown [user]:[group] [file]
  • Change group ownership of a file: chgrp [group] [file]
  • Set sticky bit on a directory: chmod +t [directory]

Note: Replace [host], [options], [pid], [process_name], [command], [job_number], [username], [group], [groupname], [permissions], [file], and [directory] with your specific details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment