Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unix cheat sheet
  • df -h: Show disk space for humans
  • scp file user@server:path/file: Transfer file over SSH
  • whereis command: Path to command
  • ssh user@server: Start SSH session (exit with exit)
  • lshw -short: Hardware information for humans
  • ls -lah dir: Show content of directory for humans, including hidden files
  • cd dir: Change directory
  • mkdir: Create directory
  • rm -rf dir: Delete full directory
  • rm file: Delete file
  • mv file file: Move or rename file
  • dpkg -l: List installed packages
  • dpkg -i file.deb: Install package (ignore select dependencies with —ignore-depends=package)
  • dpkg --r file: Remove package installed with dpkg
  • ifconfig: Show network interfaces
  • chmod +x file: Make file executable
  • lsmod: Show loaded kernel modules
  • lsusb: Show connected USB devices
  • tar -xvzf file.tar.gz: Unpack archive
  • tar -tvf file.tar.gz: List contents of archive
  • ln -s file file: Create symbolic link
  • ufw: Firewall
  • adduser -m user: Add new user
  • usermod -aG sudo user: Add user to sudoers
  • apt update: Update repository sources
  • apt-cache search package: Search package
  • apt install package: Install package from repository
  • apt remove package: Remove package from repository
  • ps aux: Show currently running processes
  • kill -KILL number: Kill process
  • kill -s SIGNAL: Send signal to process (i.e. USR1 to restart caddy)
  • zip -r file.zip dir: Create zip file from all files in the directory
  • lspci: Show connected PCI devices
  • cp -avr dir dir: Copy full directory (verbose)
  • mv `ls | head -500` dir: Move the first 500 files into directory
  • w: Who is logged in?
  • passwd: Change password
  • su - user: Temporarily switch to user
  • du -sh dir: Estimate size of directory
  • history: Show command history
  • lsof -i: Show open ports (if not managed with ufw)
  • cat file: Print contents of file
  • man command: Show help for command
  • git add file: Add file to git repository
  • git add -u: Add all changed files
  • git init repo: Initialize new local repository
  • git init --bare repo.git: Initialize new remote (bare) repository (has no working tree)
  • git remote add name: Add remote
  • git remote remove name: Remove remote
  • git remote -v: List remotes
  • git commit -m "message": Commit changes
  • git push origin branch: Push changes to branch on origin
  • git pull: Pull changes from repository
  • git clone repo.git: Clone (remote) repository
  • git rm file: Delete file from repository
  • git log: Show commit history
  • git remote set-url --add --push origin git://additional/repo.git: Add second upstream to repository
  • nano: Editor
  • restart: Restart
  • systemctl ...: Systemd control
  • service ...: Systemd control
  • which command: Which binary does command use?
  • mount folder: Mount resource associated (i.e. in /etc/fstab) with folder
  • umount folder: Unmount resource associated (i.e. in /etc/fstab) with folder
  • curl url: Retrieve URL
  • wget url: Retrieve URL
  • sudo dpkg-reconfigure tzdata: Set time zone
  • nohup command&: Run command in the background and do not terminate when session (e.g. over SSH) is closed
  • tail -n 500 file: Print last 500 lines of file
  • tree: Nice directory structure
  • htop: Nice resource monitor
  • ls -1 | wc -l: Number of files in current directory
  • lsblk: Show disk info, add -f to also show IDs, file systems, and partitions
  • sudo mkfs.ext4 /dev/sdX: Quick format disk or partition
  • timedatectl list-timezones: List timezones
  • sudo timedatectl set-timezone timezone: Set timezone
  • sensors: Temperature (run sudo detect-sensors first)
  • nvidia-smi: GPU info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment