Bash — Commands
File operations
ls -la # List files
pwd # Print working directory
cd /path # Change directory
mkdir -p dir # Create directory
touch file # Create empty file
cp -r src dest # Copy recursively
mv src dest # Move/rename
rm -rf dir # Remove recursively
Text processing
cat file # Print file
head -n 10 file # First 10 lines
tail -n 10 file # Last 10 lines
grep pattern file # Search
sed 's/old/new/g' file # Replace
awk '{print $1}' file # Column extraction
sort file # Sort lines
uniq file # Remove duplicates
wc -l file # Count lines
cut -d',' -f1 file # Extract column
tr 'a-z' 'A-Z' # Translate characters
Finding files
find /path -name "*.txt" # Find by name
find /path -type f -mtime -7 # Modified in last 7 days
find /path -size +1M # Larger than 1MB
locate filename # Quick search
which command # Find command location
Process management
ps aux # List processes
top # Process monitor
kill PID # Kill process
kill -9 PID # Force kill
bg # Background process
fg # Foreground process
jobs # List jobs
Disk usage
df -h # Disk space
du -sh * # Directory sizes
du -sh /path # Specific path size
Mini Practice
Write Bash code that:
- Lists files with details
- Searches for files with
find - Processes text with
grepandawk - Monitors processes with
ps
Up Next
In the next lesson, you'll learn about Files — file operations in Bash.
Related Topics
Frequently Asked Questions about Commands
What is Commands in Bash?
Commands is a fundamental concept in Bash. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Commands?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Commands.
Why is Commands important in Bash?
Commands is essential for Bash development. Understanding this concept will help you write better code and solve real-world problems more effectively.