Photo blog

Image credit to Martin Wettstein

Published on March 3, 2025

Linux Command Line Cheat Sheet

The Linux command line is a powerful tool that allows users to perform a variety of tasks quickly and efficiently. Whether you're managing files, monitoring system resources, or troubleshooting network issues, knowing essential commands can significantly boost your productivity. This cheat sheet provides a handy reference for commonly used Linux commands, making it easier to navigate and operate your system.

File and Directory Management

  • ls – List files and directories.
  • cd <dir> – Change directory.
  • pwd – Show current directory.
  • mkdir <dir> – Create a directory.
  • rm <file/dir> – Remove file or directory (-r for recursive).
  • cp <source> <destination> – Copy files/directories (-r for directories).
  • mv <source> <destination> – Move or rename a file/directory.
  • find <dir> -name "<pattern>" – Find files by name.

File Viewing and Editing

  • cat <file> – Show file contents.
  • less <file> – View file page by page.
  • head <file> – Show first 10 lines.
  • tail <file> – Show last 10 lines (-f to follow updates).
  • nano <file> – Edit file using Nano.
  • vim <file> – Edit file using Vim.

File Permissions and Ownership

  • chmod <permissions> <file> – Change file permissions (e.g., chmod 755 file).
  • chown <user>:<group> <file> – Change file owner.
  • ls -l – Show file permissions and ownership.

Process Management

  • ps aux – Show running processes.
  • top – Real-time system processes.
  • kill <PID> – Kill a process by PID.
  • killall <name> – Kill all processes with a name.
  • jobs – Show background jobs.
  • bg – Resume job in background.
  • fg – Resume job in foreground.
  • nohup <command> & – Run a command in background.

Disk and System Information

  • df -h – Show disk space usage.
  • du -sh <dir> – Show directory size.
  • free -h – Show memory usage.
  • uptime – Show system uptime.
  • uname -a – Show system info.
  • hostname – Show hostname.
  • whoami – Show current user.

Networking

  • ip a – Show IP addresses.
  • ping <host> – Test connectivity.
  • curl <url> – Fetch a URL.
  • wget <url> – Download a file.
  • netstat -tulnp / ss -tulnp – Show active connections.
  • traceroute <host> – Trace packet path.
  • nslookup <domain> / dig <domain> – Query DNS.

User Management

  • who – Show logged-in users.
  • su <user> – Switch user.
  • sudo <command> – Run as superuser.
  • passwd – Change password.
  • useradd <user> – Create a user.
  • usermod -aG <group> <user> – Add user to group.
  • deluser <user> – Delete a user.

Package Management

Ubuntu/Debian (APT)

  • apt update – Refresh package lists.
  • apt upgrade – Upgrade all packages.
  • apt install <package> – Install a package.
  • apt remove <package> – Remove a package.

Arch Linux (Pacman)

  • pacman -Syu – Update system.
  • pacman -S <package> – Install a package.
  • pacman -R <package> – Remove a package.

RedHat/CentOS (Yum/DNF)

  • dnf install <package> / yum install <package> – Install package.
  • dnf update / yum update – Update packages.
  • dnf remove <package> / yum remove <package> – Remove package.

Logs and Monitoring

  • dmesg – Show system logs.
  • journalctl -xe – View system logs.
  • tail -f /var/log/syslog – Monitor system logs.
  • systemctl status <service> – Check service status.
  • systemctl restart <service> – Restart a service.

Archiving and Compression

  • tar -cvf archive.tar <files> – Create tar archive.
  • tar -xvf archive.tar – Extract tar archive.
  • tar -czvf archive.tar.gz <files> – Create gzipped tar archive.
  • tar -xzvf archive.tar.gz – Extract gzipped tar archive.
  • zip archive.zip <files> – Create zip archive.
  • unzip archive.zip – Extract zip archive.

Other Useful Commands

  • echo "Hello World" – Print text.
  • history – Show command history.
  • alias ll="ls -la" – Create alias.
  • clear – Clear screen.
  • exit – Exit terminal.

Mastering the Linux command line can greatly enhance your efficiency and control over your system. With these essential commands at your fingertips, you’ll be able to navigate files, manage processes, monitor system performance, and troubleshoot issues with ease. Keep this cheat sheet handy, and don’t hesitate to explore further using man pages or online resources. Happy coding!

Last tip: Use man <command> to see detailed documentation for any command!