Terminal
Beginner
Linux/macOS Terminal Cheat Sheet
Essential Bash commands for navigating files, running tests, managing processes, and automating tasks on Linux and macOS.
Linux/macOS Terminal (Bash/Zsh)
Navigation
pwd # Where am I?
ls # List files
ls -la # List all files with details
cd folder_name # Go into folder
cd .. # Go up one level
cd ~ # Go to home directory
cd - # Go to previous directory
Files & Folders
mkdir test-suite # Create folder
touch test_login.py # Create empty file
cp file.py backup.py # Copy file
mv old.py new.py # Rename/move file
rm file.py # Delete file (careful!)
rm -rf folder/ # Delete folder and contents
cat file.py # Show file contents
head -20 results.log # First 20 lines
tail -f test.log # Follow live output (great for test logs)
Searching
grep "ERROR" test.log # Find text in file
grep -r "login" tests/ # Search recursively in folder
find . -name "*.py" # Find files by name
find . -name "*.py" -mtime -1 # Files modified in last day
Running Tests
python -m pytest tests/ # Run Python tests
npx playwright test # Run Playwright
bundle exec rspec # Run RSpec
mvn test # Run Maven/Java tests
npm test # Run npm test script
Processes
ps aux | grep chrome # Find running processes
kill 12345 # Kill process by PID
top # Live system monitor
Ctrl+C # Stop current command
Ctrl+Z # Suspend current command
command & # Run in background
Permissions
chmod +x run_tests.sh # Make script executable
./run_tests.sh # Run the script
Pipes & Redirects
cat test.log | grep "FAIL" # Pipe: filter output
python tests.py > results.txt # Redirect output to file
python tests.py 2>&1 | tee output.log # Show AND save output
command1 && command2 # Run 2nd only if 1st succeeds
command1 || command2 # Run 2nd only if 1st fails
Environment Variables
export BASE_URL=http://localhost:3000 # Set variable
echo $BASE_URL # Read variable
env # Show all variables
Useful Shortcuts
| Shortcut | Action |
|---|---|
| Tab | Auto-complete |
| ↑/↓ | Previous commands |
| Ctrl+R | Search command history |
| Ctrl+L | Clear screen |
| Ctrl+A | Go to start of line |
| Ctrl+E | Go to end of line |