Tag: bash commands

  • Ubuntu Server CLI Cheatsheet

    Ubuntu Server CLI Cheatsheet

    The world’s most popular server OS – CLI essentials for daily administration
    Ubuntu Server 25.10 (Questing Quokka) released October 2025: Kernel 6.17, OpenJDK 25, Python 3.14 RC3, Golang 1.25, Rust 1.85. LTS: 24.04 (Noble Numbat) with 12 years support via Ubuntu Pro.
    Debian-based with apt package manager. All privileged commands require sudo. Access via SSH (port 22) or console.

    1. Installation & Initial Setup

    TaskCommand / Action
    Download ISOubuntu.com/download/server → 25.10 (latest) or 24.04 LTS
    Boot & InstallUSB boot → Language → Install Ubuntu Server → Set hostname, user, SSH key (recommended)
    Enable SSHDuring install: Check Install OpenSSH server Post-install: sudo apt install openssh-server
    Update systemsudo apt update && sudo apt upgrade -y
    Set timezonesudo timedatectl set-timezone America/New_York (or your region)
    Configure firewall (UFW)sudo ufw allow OpenSSH sudo ufw enable
    Add user to sudosudo usermod -aG sudo username

    Cloud Images: For AWS/GCP/Azure: Use official AMIs. Minimal install: ~300MB RAM. Pro Tip: Enable unattended upgrades: sudo apt install unattended-upgrades → sudo dpkg-reconfigure unattended-upgrades.

    2. Navigation & File Management

    TaskCommand
    Show current directorypwd
    List files (detailed)ls -la
    List by time (newest first)ls -lht
    List with human-readable sizesls -lh
    Change directorycd /var/www
    Go homecd ~
    Go up one levelcd ..
    Go to previous directorycd –
    Show directory treetree -L 2 (install: sudo apt install tree)

    3. Create, Copy, Move & Delete

    ActionCommand
    Create directorymkdir foldername
    Create nested directoriesmkdir -p /path/to/nested/folder
    Create empty filetouch filename.txt
    Create multiple filestouch file1.txt file2.txt file3.txt
    Edit/create with nanonano filename.txt (Ctrl+O save, Ctrl+X exit)
    Copy filecp file.txt /backup/
    Copy directory recursivelycp -r folder /backup/
    Move/rename filemv old.txt new.txt
    Move filemv file.txt /new/location/
    Delete filerm file.txt
    Delete directoryrm -r folder (empty) rm -rf folder (with contents, dangerous!) rm -ri folder (with prompts)

    4. Disk & Storage

    TaskCommand
    Disk usage (human-readable)df -h
    Detailed disk outputdf -h –output=source,fstype,size,used,avail,pcentused,target
    Folder sizedu -sh /path
    Current directory sizes (largest first)du -sh * | sort -hr
    List block deviceslsblk
    List all diskssudo fdisk -l
    Interactive disk explorerncdu / (install: sudo apt install ncdu)

    5. Search & Find

    TaskCommand
    Find files by namefind /var/www -name “*.log”
    Find large files (>100MB)find / -type f -size +100M 2>/dev/null
    Search text in filesgrep -r “search term” /var/www
    Case-insensitive filenames onlygrep -ril “text” /etc

    6. Permissions & Ownership

    ActionCommand
    Set file permissions (644)chmod 644 file.txt
    Make executable (755)chmod 755 script.sh
    Recursive permissionschmod -R 755 folder
    Change ownerchown www-data:www-data file.txt
    Recursive ownershipchown -R www-data:www-data /var/www
    Take ownershipchown -R $USER:$USER folder

    7. System Monitoring & Info

    TaskCommand
    Kernel & system infouname -a
    Ubuntu versionlsb_release -a
    Uptime & loaduptime
    Memory usagefree -h
    Process monitortop or htop (install: sudo apt install htop)
    Recent logsjournalctl -xe
    Kernel messagesdmesg | tail

    8. Package Management (APT)

    ActionCommand
    Update package listsudo apt update
    Upgrade packagessudo apt upgrade -y
    Full upgrade (with deps)sudo apt full-upgrade -y
    Remove unusedsudo apt autoremove
    Clean cachesudo apt clean
    Install toolssudo apt install tree htop ncdu
    Search packageapt search keyword
    Show package infoapt show package

    9. Networking & Users

    Networking

    TaskCommand
    Show IP addressesip a
    Listening portsss -tulnp
    Public IPcurl ifconfig.me
    Test connectivityping -c 4 google.com
    Firewall statussudo ufw status
    Allow SSHsudo ufw allow 22/tcp

    Users

    ActionCommand
    Add usersudo adduser username
    Add to sudo groupsudo usermod -aG sudo username
    Change passwordsudo passwd username
    Edit sudoerssudo visudo

    10. Troubleshooting

    IssueCommand
    Fix broken packagessudo apt install -f
    Check servicessudo systemctl status service
    View full logsjournalctl -u service -f
    Boot to recoveryGRUB → Advanced → Recovery Mode
    Clear old logssudo journalctl –vacuum-time=30d
    Reinstall packagesudo apt install –reinstall package

    11. One-Liners

    # Full update + clean

    sudo apt update && sudo apt full-upgrade -y && sudo apt autoremove && sudo apt clean

    # Clean disk view (hide snaps)

    df -h | grep -v snap

    # 10 largest items in current dir

    du -sh * | sort -hr | head -10

    # Delete logs older than 30 days

    find /var/log -type f -mtime +30 -delete

    # Newest files in /var/log

    ls -lht /var/log | head

    # Quick web server (Python)

    cd /var/www && python3 -m http.server 8000

    12. Useful Tools to Install

    sudo apt install htop tree ncdu curl wget vim git ufw unattended-upgrades

    13. Ubuntu Resources

    Official Docs: https://ubuntu.com/server/docs
    Ask Ubuntu: https://askubuntu.com
    Cloud/Server Guide: https://ubuntu.com/server

    # Check for updates offline

    apt list –upgradable

  • Arch Linux Cheatsheet

    Arch Linux Cheatsheet

    Essential commands for installation, package management, system administration, and troubleshooting
    Assumes pacman as primary package manager. All commands require sudo unless run as root.


    1. Installation (Live USB/ISO)

    TaskCommand
    Update keyring (critical first step)pacman -Sy archlinux-keyring --noconfirm
    Sync mirrors (fastest)reflector --latest 10 --sort rate --save /etc/pacman.d/mirrorlist
    List diskslsblk -f or fdisk -l
    Partition disk (example: UEFI + root)cfdisk /dev/sdX
    Format partitionsmkfs.fat -F32 /dev/sdX1 (EFI)
    mkfs.ext4 /dev/sdX2 (root)
    Mount partitionsmount /dev/sdX2 /mnt
    mkdir -p /mnt/boot && mount /dev/sdX1 /mnt/boot
    Install base systempacstrap /mnt base linux linux-firmware
    Generate fstabgenfstab -U /mnt >> /mnt/etc/fstab
    Chroot into systemarch-chroot /mnt
    Set timezoneln -sf /usr/share/zoneinfo/Region/City /etc/localtime
    hwclock --systohc
    Set localeEdit /etc/locale.gen → uncomment en_US.UTF-8 UTF-8
    locale-gen
    echo "LANG=en_US.UTF-8" > /etc/locale.conf
    Set hostnameecho "myhostname" > /etc/hostname
    Add to /etc/hosts127.0.0.1 localhost
    ::1 localhost
    127.0.1.1 myhostname.localdomain myhostname
    Set root passwordpasswd
    Install bootloader (GRUB UEFI)pacman -S grub efibootmgr
    grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB
    grub-mkconfig -o /boot/grub/grub.cfg
    Enable network (systemd)pacman -S networkmanager
    systemctl enable NetworkManager
    Exit & rebootexit
    umount -R /mnt
    reboot

    2. Pacman (Package Management)

    ActionCommand
    Update systempacman -Syu
    Install packagepacman -S package
    Remove package (with deps)pacman -Rns package
    Search packagepacman -Ss keyword
    List installed packagespacman -Q
    List explicitly installedpacman -Qe
    Clean cache (keep last 3 versions)paccache -rk 3
    Remove untracked packagespacman -Rns $(pacman -Qdtq)
    View package infopacman -Qi package
    List files in packagepacman -Ql package
    Which package owns filepacman -Qo /path/to/file
    Sync databasepacman -Syy
    Force refreshpacman -Syyu

    AUR Helper (yay/paru)
    Install: pacman -S --needed git base-devel
    git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si
    Use: yay -S package (replaces pacman for AUR)


    3. System Administration

    TaskCommand
    List servicessystemctl list-unit-files --type=service
    Enable servicesystemctl enable service
    Start servicesystemctl start service
    Check statussystemctl status service
    View logsjournalctl -u service
    Rebootreboot
    Shutdownpoweroff
    View kernel messagesdmesg | less
    Check disk usagedf -h
    Check memoryfree -h
    List processeshtop or top
    Kill processkill PID or pkill name
    Edit config (nano/vim)nano /path/to/file
    Backup pacman databasecp -r /var/lib/pacman /backup/

    4. Users & Permissions

    ActionCommand
    Add useruseradd -m -G wheel username
    Set user passwordpasswd username
    Enable sudo for wheelEDITOR=nano visudo → uncomment %wheel ALL=(ALL) ALL
    Change file ownerchown user:group file
    Change permissionschmod 755 file

    5. Networking

    TaskCommand
    Check IPip a
    Test connectionping archlinux.org
    Wi-Fi (iwctl)iwctl → station wlan0 scan → connect SSID
    Enable Wi-Fisystemctl enable --now iwd
    Check DNScat /etc/resolv.conf
    Restart NetworkManagersystemctl restart NetworkManager

    6. Filesystem & Storage

    TaskCommand
    Mount USBmount /dev/sdb1 /mnt/usb
    Unmountumount /mnt/usb
    Format ext4mkfs.ext4 /dev/sdX1
    Check filesystemfsck /dev/sdX1
    Find large filesdu -ah / | sort -rh | head -n 20
    Search filesfind / -name "filename"

    7. Troubleshooting

    IssueCommand
    Boot into recoveryHold Shift at boot → GRUB → e → add systemd.unit=rescue.target
    Fix broken packagespacman -Dk (check deps)
    pacman -Syu --overwrite '*'
    Reinstall all packagespacman -Qnq | pacman -S -
    Clear journal logsjournalctl --vacuum-time=2weeks
    Check boot errorsjournalctl -b -p err
    Regenerate initramfsmkinitcpio -P
    Update GRUBgrub-mkconfig -o /boot/grub/grub.cfg

    8. Useful Tools to Install

    pacman -S vim htop git curl wget unzip tree reflector rsync

    9. One-Liners

    # Full system update + clean
    pacman -Syu && paccache -ruk0 && pacman -Rns $(pacman -Qdtq)
    
    # Mirrorlist (fastest 10 servers)
    reflector --latest 10 --sort rate --save /etc/pacman.d/mirrorlist && pacman -Syy
    
    # Show orphan packages
    pacman -Qdt
    
    # Rebuild AUR packages after upgrade
    yay -Syu --rebuildall

    10. Arch Wiki Shortcut

    Always check: https://wiki.archlinux.org

    # Search wiki offline (install arch-wiki-docs)
    pacman -S arch-wiki-docs
    wiki-search "query"

    Pro Tip: Keep archinstall script for automated installs:

    pacman -S archinstall
    archinstall