CheatsheetLinuxBashTerminalDevOpsDeveloper ToolsSysAdmin8 min read
Linux & Bash Cheat Sheet: Terminal Commands & Scripting (2026)
By Vishnu
|Updated: Jul 30, 2026
Linux and Bash command-line interfaces form the backbone of modern cloud infrastructure, DevOps pipelines, and developer environments. Mastering terminal navigation, process management, file permissions, network utilities, and shell scripting enables system administrators and developers to operate Linux servers efficiently.
Key Takeaways
Use `chmod` and `chown` to manage Linux file permissions and user access rights.
Combine CLI tools via pipes (`|`) to stream data across grep, awk, sort, and uniq pipelines.
Monitor real-time processes using `ps aux`, `htop`, and manage background jobs with `bg` and `fg`.
Configure automated system tasks using `crontab -e` and establish secure remote connections via SSH.
How do you navigate the filesystem and manipulate files in Linux?
Filesystem navigation uses path operators (cd, pwd, ls), while file operations create, copy, move, and remove files and directories.
File & Directory Navigation
Command
Action
ls -la
List all files including hidden dotfiles with permissions & sizes
cd /var/www
Change directory to /var/www
cd ..
Move up one parent directory level
cd ~
Return to current user’s home directory
cd -
Switch back to previously active working directory
pwd
Print absolute working directory path
mkdir -p path/to/dir
Create directory structure along with parent folders
cp file.txt copy.txt
Copy a file
cp -r dir/ copy_dir/
Copy a directory recursively
mv old.txt new.txt
Rename or move a file
rm file.txt
Remove a file
rm -r dir/
Remove a directory recursively
rm -rf dir/
Force remove directory and contents without prompts
ln -s target_file link_name
Create a symbolic link
Reading & Inspecting File Contents
Command
Action
cat file.txt
Print entire file content to stdout
less file.txt
Paginated interactive file viewer (press q to exit)
head -n 20 file.txt
Display first 20 lines of a file
tail -n 20 file.txt
Display last 20 lines of a file
tail -f /var/log/syslog
Follow live stream updates to log files
wc -l file.txt
Count total line count in a file
wc -w file.txt
Count total word count in a file
How do you search files and text using grep and find?
grep searches for text patterns inside files, while find locates files across directory trees based on name, size, or modification date.
Grep Text Searching
Command
Action
grep "pattern" file.txt
Search for exact pattern in a file
grep -r "pattern" ./src
Search recursively across all files in directory
grep -i "pattern" file.txt
Perform case-insensitive pattern match
grep -n "pattern" file.txt
Display line numbers alongside matching text
grep -v "pattern" file.txt
Invert match (display lines that do NOT match)
grep -l "pattern" dir/*
List filenames containing pattern matches
grep -C 3 "error" app.log
Display 3 lines of context before and after match
Find File Searching
Command
Action
find . -name "*.js"
Find files matching name pattern
find . -type f -name "*.log"
Find regular files only
find . -type d -name "node_modules"
Find directories by name
find . -mtime -7
Find files modified within the last 7 days
find . -size +10M
Find files larger than 10MB
find . -name "*.tmp" -delete
Find and delete matching temporary files
How do Linux file permissions and user access rights work?
Linux uses permission modes (read, write, execute) assigned to owner, group, and others to protect system files.
Permission Management
Command
Action
ls -l
Display detailed permissions, owner, and group
chmod 755 script.sh
Set rwxr-xr-x permissions (Owner: read/write/exec, Group/Others: read/exec)
chmod +x script.sh
Make file executable
chmod -R 755 /var/www
Set permissions recursively across directory tree
chown user file.txt
Change file owner
chown user:group file.txt
Change file owner and group
chown -R user:group dir/
Change owner and group recursively
sudo command
Execute command with superuser (root) privileges
Permission Mode Numeric Breakdown
Numeric Mode
Permission Scope
Symbol
7
Read + Write + Execute
rwx
6
Read + Write
rw-
5
Read + Execute
r-x
4
Read Only
r--
0
No Permissions
---
How do you inspect processes, memory, disk usage, and network ports?
System administration requires monitoring CPU/RAM consumption, process lifecycles, disk space, and open network sockets.
Process Control & Resource Monitoring
Command
Action
ps aux
List all running system processes
ps aux | grep node
Search for running process IDs by name
top / htop
Interactive real-time process and system resource monitor
kill PID
Terminate process gracefully (SIGTERM)
kill -9 PID
Force terminate process immediately (SIGKILL)
killall node
Kill all running processes named node
df -h
Display disk space usage in human-readable units
du -sh dir/
Display total size of a directory
free -h
Display total, used, and available system RAM memory
Networking & SSH Utilities
Command
Action
ip a
Display network interfaces and IP addresses
ss -tulnp
List active listening TCP/UDP network ports and process IDs
ping host
Verify ICMP network reachability to remote host
curl -I https://example.com
Fetch HTTP response status and headers
ssh user@host
Open secure shell connection to remote server
scp local.txt user@host:/remote/path/
Copy file to remote server over SSH
rsync -avz src/ user@host:/dest/
Efficiently sync directories over SSH
How do you manage archives, pipes, shell variables, and cron jobs?
Shell automation relies on standard input/output redirection (>, |), environment variables (export), and scheduled cron jobs.
Archives & Pipes
Symbol / Command
Action
tar -czf archive.tar.gz dir/
Create gzipped tar archive
tar -xzf archive.tar.gz
Extract gzipped tar archive
cmd1 | cmd2
Pipe output of cmd1 as input to cmd2
> file.txt
Redirect stdout to file (overwrite existing content)
>> file.txt
Redirect stdout to file (append to existing content)
2>&1
Redirect stderr to stdout stream
/dev/null
Discard output stream completely
Shell Keyboard Shortcuts & Environment
Shortcut / Command
Action
Ctrl+C
Interrupt and kill currently executing process
Ctrl+Z
Suspend running process to background
Ctrl+L
Clear terminal screen
Ctrl+R
Reverse search command history
export VAR=value
Set an environment variable available to child subshells
source ~/.bashrc
Reload active shell environment configuration
Cron Scheduled Tasks (crontab -e)
bash
# Format: minute hour day-of-month month day-of-week command# Run script every minute* * * * * /path/to/script.sh# Run script every day at midnight (00:00)0 0 * * * /path/to/backup.sh# Run script every Monday at 9:00 AM0 9 * * 1 /path/to/weekly-report.sh# Run script every 15 minutes*/15 * * * * /path/to/health-check.sh
Writing Executable Bash Scripts (script.sh)
bash
#!/bin/bashset -e # Exit immediately if any command returns non-zero errorset -u # Treat unset variables as errorsNAME="Developer"echo "Processing deployment for $NAME..."# Conditionalsif [ -f "config.json" ]; then echo "Configuration file found."else echo "Configuration file missing!" exit 1fi# Command substitutionTODAY=$(date +%Y-%m-%d)echo "Deployment date: $TODAY"
Frequently Asked Questions
What is the difference between > and >> in Bash?
> redirects command output to a file, completely overwriting any existing contents. >> appends command output to the end of the target file without overwriting existing data.
How do I make a Bash script executable?
Run chmod +x script.sh to add execute permissions, then execute it in your terminal using ./script.sh.