beginner tools Standard Linux/GNU Coreutils 9.10 · Updated April 2026

Linux Command Line Cheatsheet

Master the Linux command line with essential commands, core concepts, and practical patterns for developers.

· 8 min read · AI-reviewed

Quick Overview

The Linux command line, often accessed via a terminal, is a text-based interface for interacting with your operating system. It provides immense power, flexibility, and efficiency for managing files, running programs, automating tasks, and administering systems. Developers use it daily for everything from navigating project directories to deploying applications. While most Linux distributions come with a shell (like Bash) and essential utilities pre-installed, this guide focuses on the fundamental commands provided by GNU Coreutils.

Getting Started

To begin your journey, you’ll need to open a terminal application. This is typically found in your operating system’s applications menu under “Terminal,” “Konsole,” “GNOME Terminal,” or similar. Once open, you’ll see a prompt, indicating the shell is ready for your commands.

# Open your terminal application
# You'll see a prompt like: user@hostname:~ $

Your First Commands

These commands help you understand where you are and what’s around you.

# Print Working Directory: Shows your current location in the filesystem
pwd
# Example output: /home/youruser

# List directory contents: Shows files and subdirectories in the current location
ls
# Example output: Documents Downloads Pictures Public Templates Videos

# Change Directory: Navigate into a directory
cd Documents
# Now your prompt might show: user@hostname:~/Documents $

# Change to parent directory
cd ..

# Change to home directory (shortcut)
cd ~

# Change to the previous directory
cd -

Core Concepts

Understanding these fundamental concepts will help you build a solid mental model for working with the Linux command line.

ConceptDescription
ShellA program that interprets your commands and interacts with the operating system kernel. Bash (Bourne Again SHell) is the most common default.
TerminalA program (or physical device) that provides a text-based interface for interacting with a shell.
CommandAn instruction given to the shell to perform a specific task (e.g., ls, cp, mkdir).
ArgumentAdditional input provided to a command, often specifying what the command should act upon (e.g., myfile.txt in cat myfile.txt).
Option/FlagModifies a command’s behavior. Often prefixed with a hyphen (-) for short options or two hyphens (--) for long options (e.g., -l or --long in ls -l).
Standard I/OStdin (Standard Input), Stdout (Standard Output), and Stderr (Standard Error) are default channels for input and output, allowing commands to be chained and their outputs redirected.
PathThe location of a file or directory in the filesystem. Can be absolute (starting from /, the root) or relative (from the current directory).
PermissionsDefine who (user, group, others) can read, write, or execute a file or directory.

Essential Commands

The 80/20 reference: common commands organized by task.

File & Directory Navigation

# List contents in long format, showing details like permissions, ownership, size, and modification date
ls -l

# List all files, including hidden ones (starting with .)
ls -a

# List contents in long format, including hidden files, and human-readable sizes
ls -lah

# Change to a specific directory using an absolute path
cd /var/log

# Go up two directories
cd ../..

File & Directory Management

# Create a new directory
mkdir myproject

# Create a nested directory structure (parent directories created if they don't exist)
mkdir -p myproject/src/components

# Create an empty file or update its timestamp if it exists
touch myfile.txt

# Copy a file to another location
cp myfile.txt myproject/src/myfile.txt

# Copy a directory and its contents recursively
cp -r myproject myproject_backup

# Move (rename) a file
mv oldname.txt newname.txt

# Move a file to a different directory
mv newname.txt myproject/src/

# Delete a file (prompts for confirmation if interactive mode is on, or with -i)
rm newname.txt

# Delete an empty directory
rmdir empty_folder

# Delete a directory and all its contents recursively (USE WITH CAUTION!)
rm -r myproject

# Force deletion without prompting (USE WITH EXTREME CAUTION!)
rm -rf myproject_backup

Viewing File Contents

# Display the entire content of a file
cat myproject/README.md

# View file content page by page (press SPACE for next page, Q to quit)
less large_log_file.log

# Display the first 10 lines of a file (use -n to specify a different number)
head -n 5 large_log_file.log

# Display the last 10 lines of a file (useful for logs; use -n to specify a different number)
tail -n 20 large_log_file.log

# Continuously display new lines added to a file (useful for real-time logs)
tail -f large_log_file.log

Searching & Filtering

# Search for lines containing "error" in a file
grep "error" large_log_file.log

# Search case-insensitively
grep -i "warning" large_log_file.log

# Search for "pattern" in all .txt files in the current directory and subdirectories
grep -r "pattern" ./*.txt

# Find files by name in the current directory and its subdirectories
find . -name "config.js"

# Find files modified in the last 24 hours
find . -mtime -1

# Find files larger than 100MB
find . -size +100M

Permissions & Ownership

# Change file permissions for user, group, others using octal notation (e.g., rwx = 7, rw- = 6, r-x = 5)
# Make script.sh executable for the owner (read=4, write=2, execute=1; 7 = rwx)
chmod 744 script.sh

# Add execute permission for the owner
chmod u+x script.sh

# Change the owner of a file
sudo chown username myfile.txt

# Change the group of a file
sudo chgrp devgroup myfile.txt

# Change both owner and group
sudo chown username:devgroup myfile.txt

System Information

# Display basic system information (e.g., Linux kernel name)
uname

# Display all system information (kernel name, hostname, kernel release, kernel version, machine hardware name, processor, hardware platform, operating system)
uname -a

# Display disk space usage of filesystems
df -h # Human-readable output

# Display disk usage of files and directories recursively
du -sh myproject/ # Summarize human-readable disk usage for 'myproject'

# List running processes
ps aux # Show all processes for all users

# Display real-time system process status (press 'q' to quit)
top

Common Patterns

Combine commands for more powerful operations.

Piping Output (|)

The | (pipe) operator sends the stdout of one command as the stdin of another.

# List all files and directories, then filter for "config" using grep
ls -l | grep "config"

# Get a list of running processes and search for ones related to 'node'
ps aux | grep node

# Count the number of lines, words, and characters in a file
cat mydocument.txt | wc
# -l: lines, -w: words, -c: characters

# Find all .txt files, then print their contents
find . -name "*.txt" -exec cat {} \;

Redirection (>, >>, <)

Control where a command’s output goes.

# Redirect stdout to a file, overwriting it if it exists
ls -l > file_list.txt

# Redirect stdout to a file, appending to it if it exists
echo "Another line of text" >> file_list.txt

# Redirect stderr to a file (2> for stderr)
command_that_might_fail 2> error.log

# Redirect both stdout and stderr to the same file (append)
command_that_might_fail &>> combined.log

# Use a file as stdin for a command
wc < mydocument.txt

Command Chaining (;, &&, ||)

Execute multiple commands in a sequence.

# Run multiple commands sequentially, regardless of success
echo "Starting cleanup"; rm -rf temp_files/; echo "Cleanup complete."

# Run a command only if the previous one succeeded
mkdir new_dir && cd new_dir && touch new_file.txt

# Run a command only if the previous one failed
command_that_might_fail || echo "Command failed, taking alternative action."

Wildcards (*, ?)

Match patterns in filenames.

# Match any sequence of characters
ls *.log # Lists all files ending with .log

# Match a single character
ls report_?.txt # Matches report_1.txt, report_A.txt, but not report_10.txt

Environment Variables

Store dynamic values accessible by processes.

# Display all environment variables
env

# Display the value of a specific environment variable
echo $PATH

# Set a temporary environment variable (lasts for the current session or until unset)
export MY_VAR="hello world"

# Use the variable
echo $MY_VAR

Gotchas & Tips

Things that often trip up beginners and even seasoned pros.

  • Case Sensitivity: Linux filenames and commands are case-sensitive (File.txt is different from file.txt).
  • sudo for Administrator Privileges: Many commands that modify system-wide settings or protected files require sudo (SuperUser DO). Be mindful when using it, as it executes commands with root privileges.
    # Run the previous command with sudo
    sudo !!
  • Tab Completion: Pressing Tab while typing a command, filename, or directory path will attempt to autocomplete it. Pressing Tab twice will show available options. This is a huge time-saver and reduces typos.
  • Command History:
    • Use the Up/Down arrow keys to cycle through previously executed commands.
    • history: Shows a list of all commands you’ve entered.
    • Ctrl+R (Reverse Search): Start typing a part of a command, and it will search your history for matching commands. Press Ctrl+R again to cycle through older matches.
    • !!: Repeats the last command.
    • !N: Repeats the Nth command from your history (e.g., !123).
    • !string: Repeats the most recent command starting with string.
  • Aliases: Create custom shortcuts for long or frequently used commands.
    # Create a temporary alias for 'ls -lah'
    alias ll='ls -lah'
    ll
    # To make aliases permanent, add them to your shell's configuration file (e.g., ~/.bashrc or ~/.zshrc)
  • Copy/Paste in Terminal: Ctrl+C and Ctrl+V are often used for signals in the terminal (like terminating a process with Ctrl+C). For copying and pasting text, you typically use Ctrl+Shift+C and Ctrl+Shift+V (on Linux terminals) or Cmd+C / Cmd+V (on macOS).
  • Don’t rm -rf /: Seriously. This command recursively and forcefully deletes everything from the root directory, effectively destroying your system. Always double-check rm -rf commands and avoid using them on critical paths unless you are absolutely sure.

Next Steps


Source: z2h.fyi/cheatsheets/linux-command-line-cheatsheet — Zero to Hero cheatsheets for developers.

Source: z2h.fyi/cheatsheets/linux-command-line-cheatsheet — Zero to Hero cheatsheets for developers.