Vibe monitoring with Last9 MCP: Ask your agent to fix production issues! Setup →
Last9 Last9

Feb 27th, ‘25 / 4 min read

Your Go-To Linux Commands Cheat Sheet

Speed up your workflow with this Linux commands cheat sheet—practical, easy to follow, and packed with real-world use cases.

Your Go-To Linux Commands Cheat Sheet

If you work with Linux, the terminal is either your best friend or your worst enemy—sometimes both on the same day. If you're just starting out or managing servers, a solid Linux commands cheat sheet can save you time and frustration.

Essential Linux Directory Navigation Commands

1. Navigating and Managing Directories Effectively

  • pwd – Prints the absolute path of the current working directory, so you always know where you are.
  • ls – Lists files and directories in the current directory. Use ls -l for detailed info and ls -a to see hidden files.
  • cd <directory> – Changes the current directory to the specified directory. Example: cd /home/user/docs.
  • cd .. – Moves up one level in the directory tree.
  • cd - – Switches back to the previous directory you were in.
  • mkdir <dir> – Creates a new directory. Example: mkdir new_folder.
  • rmdir <dir> – Removes an empty directory. For non-empty directories, use rm -r <dir>.
  • rm -r <dir> – Deletes a directory and all its contents. Use with caution!
💡
If you find this Linux cheat sheet helpful, check out our Git Commands Cheat Sheet to level up your version control game.

2. File Creation, Management, and Manipulation

  • touch <file> – Creates an empty file or updates the timestamp if the file exists.
  • cp <source> <destination> – Copies files or directories. Example: cp file1.txt /backup/.
  • mv <source> <destination> – Moves or renames files. Example: mv oldname.txt newname.txt.
  • rm <file> – Deletes a file permanently.
  • cat <file> – Displays the content of a file. Combine with | more to paginate.
  • less <file> – Opens a file for reading, allowing scrolling up and down.
  • head <file> – Shows the first 10 lines of a file. Example: head -20 file.txt for 20 lines.
  • tail <file> – Shows the last 10 lines of a file. Use tail -f file.log to monitor a log file in real time.

Managing Users and Permissions in Linux

3. User and Group Management

  • whoami – Displays the currently logged-in user.
  • who – Lists all users currently logged in.
  • id – Shows the user ID (UID) and group ID (GID).
  • adduser <username> – Creates a new user and sets up a home directory.
  • passwd <username> – Changes the password for a user.
  • usermod -aG <group> <username> – Adds a user to an existing group.
  • deluser <username> – Deletes a user account.

4. Managing File Permissions and Ownership

  • ls -l – Lists files with detailed permission settings.
  • chmod <permissions> <file> – Changes file permissions. Example: chmod 755 script.sh (rwx for owner, rx for others).
  • chown <user>:<group> <file> – Changes file owner and group.
  • chgrp <group> <file> – Changes the group ownership of a file.
  • umask <value> – Sets default file permissions for newly created files.
💡
If you're working with Kubernetes, our kubectl Commands Cheat Sheet will make your life easier.

Monitoring and Managing System Processes

5. Process Management and Monitoring Tools

  • ps aux – Lists all running processes with details.
  • top – Shows real-time system processes and resource usage.
  • htop – Interactive version of top, requires installation.
  • kill <PID> – Terminates a process by ID. Example: kill 1234.
  • pkill <name> – Kills a process by its name. Example: pkill firefox.
  • jobs – Lists background processes.
  • fg %<job_id> – Brings a background job to the foreground.
  • nohup <command> & – Runs a command immune to logout.

Networking and Connectivity in Linux

6. Essential Networking Commands for Troubleshooting

  • ip a – Displays IP addresses of network interfaces.
  • ping <host> – Tests connectivity to a host.
  • curl <URL> – Fetches a webpage or API response.
  • wget <URL> – Downloads a file from the internet.
  • netstat -tulnp – Shows active network connections.
  • ss -tulnp – Modern alternative to netstat.
  • nslookup <domain> – Queries DNS records.
  • dig <domain> – Retrieves detailed DNS info.
  • traceroute <host> – Shows the route packets take.
💡
If you often run commands inside Kubernetes pods, check out our kubectl exec guide for examples and best practices.

Disk Usage, Storage, and File System Management

7. Analyzing and Managing Disk Usage

  • df -h – Displays available disk space.
  • du -sh <directory> – Shows the size of a directory.
  • mount – Lists mounted filesystems.
  • umount <device> – Unmounts a filesystem.
  • fsck <device> – Checks and repairs filesystems.

Managing Software and Packages

8. Handling Software Packages Efficiently

Debian-based (Ubuntu, Debian)

  • apt update – Refreshes package lists.
  • apt upgrade – Upgrades installed packages.
  • apt install <package> – Installs a package.
  • apt remove <package> – Uninstalls a package.
  • dpkg -i <package.deb> – Installs a .deb package.

RHEL-based (CentOS, Fedora)

  • yum update – Updates all packages (CentOS 7).
  • dnf update – Updates all packages (Fedora, CentOS 8+).
  • yum install <package> – Installs a package.
  • dnf install <package> – Installs a package (Fedora, CentOS 8+).
  • rpm -i <package.rpm> – Installs an .rpm package.

System Performance and Monitoring

9. Checking System Health and Performance

  • uptime – Shows system uptime.
  • free -h – Displays memory usage.
  • vmstat – Reports system performance.
  • iostat – Displays CPU and disk usage stats.
  • sar – Collects system activity data.
  • mpstat – Displays per-core CPU usage.
  • iotop – Monitors disk I/O in real-time.
💡
If you've ever wondered why Linux kills processes under memory pressure, our OOM Killer guide breaks it down.

Handling Logs and Troubleshooting

10. Managing and Analyzing Logs

  • dmesg – Views system boot logs.
  • journalctl – Views system logs.
  • tail -f /var/log/syslog – Monitors system logs live.
  • tail -f /var/log/auth.log – Monitors authentication logs.

Automating Tasks and Scheduling

11. Setting Up Cron Jobs and Scheduled Tasks

  • crontab -l – Lists scheduled cron jobs.
  • crontab -e – Edits cron jobs.
  • crontab -r – Removes all cron jobs.
  • systemctl list-timers – Displays systemd timers.
  • at <time> – Schedules a one-time job.

Security and Firewall Management

12. Strengthening Linux Security with Firewalls

  • ufw status – Checks firewall status.
  • ufw allow <port> – Opens a port.
  • ufw deny <port> – Blocks a port.
  • iptables -L – Lists firewall rules.
  • fail2ban-client status – Checks Fail2Ban status.
💡
If you're dealing with logs, our Log Files guide covers everything you need to manage and troubleshoot them effectively.

Contents


Newsletter

Stay updated on the latest from Last9.

Authors
Anjali Udasi

Anjali Udasi

Helping to make the tech a little less intimidating. I love breaking down complex concepts into easy-to-understand terms.