Bash

Bash Shell Cheatsheet

Essential Bash commands for file operations, text processing, and shell scripting.

28 commands
Windows MacOS Linux
#scripting #terminal #Popular

File Operations

List files with details
ls -la
Change directory
cd <dir>
Create directory
mkdir -p <dir>
Copy recursively
cp -r <src> <dst>
Move/rename
mv <src> <dst>
Remove recursively
rm -rf <path>
Find files
find . -name "*.txt"

Text Processing

Display file
cat <file>
Search in file
grep "pattern" <file>
Replace text
sed 's/old/new/g' <file>
Extract columns
awk '{print $1}' <file>
Sort lines
sort <file>
Remove duplicates
uniq
Count lines
wc -l <file>

Process Management

List processes
ps aux
Interactive process viewer
top
Kill process
kill <pid>
Force kill
kill -9 <pid>
Run in background
nohup <cmd> &

Variables & Scripting

Set variable
VAR="value"
Print variable
echo $VAR
Export to environment
export VAR
If statement
if [ condition ]; then
For loop
for i in {1..5}; do
While loop
while [ condition ]; do

Quick Commands

Delete log files older than 7 days
find . -name "*.log" -mtime +7 -delete
Recursively search in directory
grep -r "pattern" .
Find specific process
ps aux | grep <process>