MeshWorld India LogoMeshWorld.
CheatsheetLinuxBashTerminalDevOpsDeveloper ToolsSysAdmin8 min read

Linux & Bash Cheat Sheet: Terminal Commands & Scripting (2026)

Vishnu
By Vishnu
|Updated: Jul 30, 2026
Linux & Bash Cheat Sheet: Terminal Commands & Scripting (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

CommandAction
ls -laList all files including hidden dotfiles with permissions & sizes
cd /var/wwwChange 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
pwdPrint absolute working directory path
mkdir -p path/to/dirCreate directory structure along with parent folders
cp file.txt copy.txtCopy a file
cp -r dir/ copy_dir/Copy a directory recursively
mv old.txt new.txtRename or move a file
rm file.txtRemove a file
rm -r dir/Remove a directory recursively
rm -rf dir/Force remove directory and contents without prompts
ln -s target_file link_nameCreate a symbolic link

Reading & Inspecting File Contents

CommandAction
cat file.txtPrint entire file content to stdout
less file.txtPaginated interactive file viewer (press q to exit)
head -n 20 file.txtDisplay first 20 lines of a file
tail -n 20 file.txtDisplay last 20 lines of a file
tail -f /var/log/syslogFollow live stream updates to log files
wc -l file.txtCount total line count in a file
wc -w file.txtCount 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

CommandAction
grep "pattern" file.txtSearch for exact pattern in a file
grep -r "pattern" ./srcSearch recursively across all files in directory
grep -i "pattern" file.txtPerform case-insensitive pattern match
grep -n "pattern" file.txtDisplay line numbers alongside matching text
grep -v "pattern" file.txtInvert match (display lines that do NOT match)
grep -l "pattern" dir/*List filenames containing pattern matches
grep -C 3 "error" app.logDisplay 3 lines of context before and after match

Find File Searching

CommandAction
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 -7Find files modified within the last 7 days
find . -size +10MFind files larger than 10MB
find . -name "*.tmp" -deleteFind 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

CommandAction
ls -lDisplay detailed permissions, owner, and group
chmod 755 script.shSet rwxr-xr-x permissions (Owner: read/write/exec, Group/Others: read/exec)
chmod +x script.shMake file executable
chmod -R 755 /var/wwwSet permissions recursively across directory tree
chown user file.txtChange file owner
chown user:group file.txtChange file owner and group
chown -R user:group dir/Change owner and group recursively
sudo commandExecute command with superuser (root) privileges

Permission Mode Numeric Breakdown

Numeric ModePermission ScopeSymbol
7Read + Write + Executerwx
6Read + Writerw-
5Read + Executer-x
4Read Onlyr--
0No 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

CommandAction
ps auxList all running system processes
ps aux | grep nodeSearch for running process IDs by name
top / htopInteractive real-time process and system resource monitor
kill PIDTerminate process gracefully (SIGTERM)
kill -9 PIDForce terminate process immediately (SIGKILL)
killall nodeKill all running processes named node
df -hDisplay disk space usage in human-readable units
du -sh dir/Display total size of a directory
free -hDisplay total, used, and available system RAM memory

Networking & SSH Utilities

CommandAction
ip aDisplay network interfaces and IP addresses
ss -tulnpList active listening TCP/UDP network ports and process IDs
ping hostVerify ICMP network reachability to remote host
curl -I https://example.comFetch HTTP response status and headers
ssh user@hostOpen 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 / CommandAction
tar -czf archive.tar.gz dir/Create gzipped tar archive
tar -xzf archive.tar.gzExtract gzipped tar archive
cmd1 | cmd2Pipe output of cmd1 as input to cmd2
> file.txtRedirect stdout to file (overwrite existing content)
>> file.txtRedirect stdout to file (append to existing content)
2>&1Redirect stderr to stdout stream
/dev/nullDiscard output stream completely

Shell Keyboard Shortcuts & Environment

Shortcut / CommandAction
Ctrl+CInterrupt and kill currently executing process
Ctrl+ZSuspend running process to background
Ctrl+LClear terminal screen
Ctrl+RReverse search command history
export VAR=valueSet an environment variable available to child subshells
source ~/.bashrcReload 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 AM
0 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/bash
set -e    # Exit immediately if any command returns non-zero error
set -u    # Treat unset variables as errors

NAME="Developer"
echo "Processing deployment for $NAME..."

# Conditionals
if [ -f "config.json" ]; then
  echo "Configuration file found."
else
  echo "Configuration file missing!"
  exit 1
fi

# Command substitution
TODAY=$(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.


Share_This Twitter / X
Vishnu
Written By

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Enjoyed this article?

Support MeshWorld and help us create more technical content