Skip to main content

Using Local Terminal

Master the local terminal with this comprehensive usage guide covering everyday tasks, workflows, and advanced techniques.

Getting Started​

Opening Your First Local Terminal​

Step 1: Open terminal

Click: "+" button → "New Local Terminal"
Or press: Ctrl+Shift+T (Cmd+Shift+T on Mac)

Step 2: Verify it's local

# You should see:
[💻 Local] tab indicator

# Check where you are:
pwd
# Output: /Users/yourname (macOS)
# /home/yourname (Linux)
# C:\Users\yourname (Windows)

Step 3: Run your first command

echo "Hello from Local Terminal!"
ls -la

You're ready!

Common Workflows​

Workflow 1: Local Development​

Scenario: Frontend development with React

Setup:

Tab 1: Local Terminal - Dev Server
Tab 2: Local Terminal - Build/Watch
Tab 3: Local Terminal - Git
Tab 4: SSH Terminal - Backend API

Tab 1: Development Server

# Start dev server
cd ~/projects/my-app
npm run dev

# Output:
# Local: http://localhost:3000
# Network: http://192.168.1.100:3000

Tab 2: Watch/Build

# Watch for changes
npm run watch

# Or build when needed
npm run build

Tab 3: Git Operations

# Check status frequently
git status

# Make commits
git add .
git commit -m "Add new feature"

# Push changes
git push origin feature-branch

Tab 4: Backend (SSH)

# Connected to remote server
# Monitor API logs
tail -f /var/log/api/access.log

Benefit: Everything visible at once!

Workflow 2: Build and Deploy​

Scenario: Build locally, deploy to server

Step 1: Clean build (Local Terminal)

cd ~/projects/my-app

# Clean previous builds
rm -rf dist/

# Install dependencies
npm ci

# Run tests
npm test

# Build for production
npm run build

Step 2: Verify build (Local Terminal)

# Check build size
du -sh dist/

# List built files
ls -la dist/

# Preview locally
npm run preview

Step 3: Deploy to staging (Switch to SSH Tab)

# Now in SSH terminal connected to staging server
cd /var/www/staging

# Backup current version
mv current current-backup-$(date +%Y%m%d_%H%M%S)

# Receive new build (run rsync from local terminal)

Step 4: Upload from local (Local Terminal)

# Upload build to server
rsync -avz --progress \
dist/ \
user@staging.example.com:/var/www/staging/current/

# Verify upload
ssh user@staging.example.com "ls -la /var/www/staging/current"

Step 5: Test and verify (SSH Terminal)

# Restart service
systemctl restart web-app

# Check status
systemctl status web-app

# Tail logs
journalctl -u web-app -f

Workflow 3: Multi-Project Management​

Scenario: Working on multiple projects

Tab Organization:

[💻 Local: project-a] - Main project
[💻 Local: project-b] - Secondary project
[💻 Local: shared] - Shared tools
[💻 Local: git] - Git operations

Project A:

cd ~/projects/project-a
npm run dev

Project B:

cd ~/projects/project-b
npm run start

Shared Tools:

cd ~/tools

# Run database locally
docker-compose up -d

# Check status
docker ps

Git Tab:

# Quick navigation with aliases
alias pa="cd ~/projects/project-a"
alias pb="cd ~/projects/project-b"

# Use for all git operations
pa
git status
git pull

pb
git status
git commit -am "Update"

Workflow 4: Testing Workflow​

Scenario: Run different types of tests

Tab 1: Unit Tests (Watch Mode)

npm run test:watch

# Output shows test results in real-time
# PASS src/components/Button.test.tsx
# PASS src/utils/helpers.test.ts

Tab 2: Integration Tests

npm run test:integration

# Runs against local API

Tab 3: E2E Tests

npm run test:e2e

# Opens browser, runs tests
# Watch results in terminal

Tab 4: Coverage Report

npm run test:coverage

# Generate and view coverage
open coverage/index.html

Workflow 5: Database Management​

Scenario: Local database operations

Tab 1: Database Server

# Start PostgreSQL locally
docker run -d \
-p 5432:5432 \
-e POSTGRES_PASSWORD=password \
postgres:latest

# Or MongoDB
docker run -d \
-p 27017:27017 \
mongo:latest

Tab 2: Database Client

# Connect to PostgreSQL
psql -h localhost -U postgres

# Run queries
SELECT * FROM users;

# Or MongoDB
mongosh

# Show databases
show dbs

Tab 3: Migrations

# Run migrations
npm run migrate

# Check status
npm run migrate:status

# Rollback if needed
npm run migrate:rollback

Tab 4: Database Backups

# Backup database
pg_dump mydb > backup-$(date +%Y%m%d).sql

# Restore
psql mydb < backup-20240117.sql

File Management​

Basic navigation:

# Go to home directory
cd ~
cd

# Go to directory
cd ~/projects/my-app

# Go up one level
cd ..

# Go back to previous directory
cd -

# Show current directory
pwd

Quick jumps:

# Jump to root
cd /

# Jump to user's home
cd ~username

# Using environment variables
cd $HOME/Documents
cd $OLDPWD # Previous directory

Directory stack:

# Push directory onto stack
pushd ~/projects/app1

# Do something...

# Return to previous directory
popd

# View directory stack
dirs -v

File Operations​

Listing files:

# List all files
ls -la

# Human-readable sizes
ls -lah

# Sort by modification time
ls -lt

# Only show directories
ls -d */

# Show hidden files only
ls -d .*

Creating files/directories:

# Create empty file
touch file.txt

# Create multiple files
touch file1.txt file2.txt file3.txt

# Create directory
mkdir newdir

# Create nested directories
mkdir -p path/to/nested/dir

# Create directory with permissions
mkdir -m 755 mydir

Copying and moving:

# Copy file
cp source.txt destination.txt

# Copy directory recursively
cp -r source_dir/ dest_dir/

# Copy with progress (verbose)
cp -v large_file.zip /destination/

# Move/rename file
mv oldname.txt newname.txt

# Move to directory
mv file.txt ~/Documents/

# Move multiple files
mv *.txt ~/Documents/

Deleting:

# Delete file
rm file.txt

# Delete directory and contents
rm -rf directory/

# Delete with confirmation
rm -i file.txt

# Delete empty directory
rmdir empty_dir/

# Find and delete
find . -name "*.log" -delete

Searching Files​

Find by name:

# Find file by name
find . -name "config.json"

# Case-insensitive
find . -iname "README*"

# Find directories only
find . -type d -name "node_modules"

# Find files only
find . -type f -name "*.js"

Find by content:

# Search text in files
grep -r "search term" .

# Case-insensitive
grep -ri "error" logs/

# Show line numbers
grep -rn "TODO" src/

# Show only filenames
grep -rl "deprecated" .

Find by date:

# Files modified today
find . -mtime 0

# Files modified in last 7 days
find . -mtime -7

# Files not accessed in 30 days
find . -atime +30

Find by size:

# Files larger than 10MB
find . -size +10M

# Files smaller than 1KB
find . -size -1k

# Files between 1MB and 10MB
find . -size +1M -size -10M

File Permissions​

View permissions:

# Detailed listing
ls -la

# Output: -rwxr-xr-x
# ↓↓↓ ↓↓↓ ↓↓↓
# own grp oth

Change permissions:

# Make executable
chmod +x script.sh

# Remove write for others
chmod o-w file.txt

# Set specific permissions
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--

# Recursive
chmod -R 755 directory/

Change ownership:

# Change owner
sudo chown user file.txt

# Change group
sudo chgrp group file.txt

# Change both
sudo chown user:group file.txt

# Recursive
sudo chown -R user:group directory/

Package Management​

npm (Node.js)​

Install packages:

# Install dependencies
npm install

# Install specific package
npm install lodash

# Install dev dependency
npm install --save-dev jest

# Install globally
npm install -g typescript

# Install specific version
npm install react@17.0.2

Run scripts:

# Run script from package.json
npm run build
npm run test
npm run dev

# Run with arguments
npm run test -- --watch

# List available scripts
npm run

Package info:

# Check outdated packages
npm outdated

# Check for security issues
npm audit

# Fix security issues
npm audit fix

# View package info
npm info lodash

# List installed packages
npm list --depth=0

pip (Python)​

Install packages:

# Install package
pip install requests

# Install from requirements
pip install -r requirements.txt

# Install specific version
pip install django==3.2

# Upgrade package
pip install --upgrade requests

Virtual environments:

# Create virtual environment
python3 -m venv venv

# Activate (Unix)
source venv/bin/activate

# Activate (Windows)
venv\Scripts\activate

# Deactivate
deactivate

Package info:

# List installed packages
pip list

# Show package info
pip show requests

# Check outdated packages
pip list --outdated

# Freeze requirements
pip freeze > requirements.txt

Homebrew (macOS/Linux)​

Install packages:

# Install package
brew install wget

# Install cask (GUI apps)
brew install --cask google-chrome

# Install specific version
brew install node@16

Manage packages:

# Update Homebrew
brew update

# Upgrade packages
brew upgrade

# Uninstall package
brew uninstall wget

# Search packages
brew search python

Package info:

# List installed
brew list

# Show package info
brew info node

# Check outdated
brew outdated

# Cleanup old versions
brew cleanup

Git Operations​

Basic Git​

Initialize:

# Create new repository
git init

# Clone repository
git clone https://github.com/user/repo.git

# Clone specific branch
git clone -b develop https://github.com/user/repo.git

Status and changes:

# Check status
git status

# Short status
git status -s

# Show changes
git diff

# Show staged changes
git diff --staged

# Show last commit
git show HEAD

Stage and commit:

# Stage file
git add file.txt

# Stage all changes
git add .

# Stage interactively
git add -p

# Commit
git commit -m "Add feature"

# Commit all tracked changes
git commit -am "Update files"

# Amend last commit
git commit --amend

Branching​

Create and switch:

# Create branch
git branch feature-name

# Switch branch
git checkout feature-name

# Create and switch
git checkout -b feature-name

# Delete branch
git branch -d feature-name

# Force delete
git branch -D feature-name

View branches:

# List local branches
git branch

# List all branches
git branch -a

# List with last commit
git branch -v

# Show merged branches
git branch --merged

Remote Operations​

Manage remotes:

# View remotes
git remote -v

# Add remote
git remote add origin https://github.com/user/repo.git

# Change remote URL
git remote set-url origin https://github.com/user/new-repo.git

# Remove remote
git remote remove origin

Push and pull:

# Push to remote
git push origin main

# Push new branch
git push -u origin feature-name

# Pull changes
git pull origin main

# Pull with rebase
git pull --rebase origin main

# Fetch without merging
git fetch origin

History and Logs​

View history:

# Show log
git log

# One line per commit
git log --oneline

# Show graph
git log --graph --oneline --all

# Show last N commits
git log -5

# Show commits by author
git log --author="John"

# Show commits with specific message
git log --grep="fix"

Search history:

# Find commit that added/removed string
git log -S "function_name"

# Show file history
git log --follow file.txt

# Show changes in file
git log -p file.txt

Process Management​

Running Processes​

Start process:

# Start in foreground
npm run dev

# Start in background
npm run dev &

# Start with nohup (survives terminal close)
nohup npm run dev > output.log 2>&1 &

# Start detached
npm run dev > /dev/null 2>&1 &

Check processes:

# Show all processes
ps aux

# Search for process
ps aux | grep node

# Show process tree
pstree

# Show processes by user
ps -u username

Manage processes:

# List background jobs
jobs

# Bring to foreground
fg %1

# Send to background
bg %1

# Kill job
kill %1

# Kill by PID
kill 12345

# Force kill
kill -9 12345

# Kill by name
pkill node

Monitoring​

System resources:

# Interactive process viewer
top

# Enhanced top (if installed)
htop

# One-time snapshot
top -bn1

# Monitor specific user
top -u username

Disk usage:

# Check disk space
df -h

# Directory sizes
du -sh *

# Largest files
du -ah | sort -rh | head -20

# Find large directories
du -h --max-depth=1 | sort -rh

Memory usage:

# Show memory
free -h

# Show swap
swapon --show

# Memory by process
ps aux --sort=-%mem | head

Environment Variables​

View Variables​

List all variables:

# All environment variables
env

# Specific variable
echo $PATH
echo $HOME
echo $USER

Common variables:

# Show important variables
echo $PATH # Executable search path
echo $HOME # User home directory
echo $USER # Current username
echo $SHELL # Default shell
echo $PWD # Current directory
echo $OLDPWD # Previous directory

Set Variables​

Temporary (current session):

# Set variable
export MY_VAR="value"

# Use variable
echo $MY_VAR

# Set multiple
export VAR1="value1" VAR2="value2"

# Add to PATH
export PATH="$PATH:/new/path"

Permanent:

# Add to shell profile
# For bash: ~/.bashrc or ~/.bash_profile
# For zsh: ~/.zshrc
# For fish: ~/.config/fish/config.fish

echo 'export MY_VAR="value"' >> ~/.bashrc

# Reload profile
source ~/.bashrc

For single command:

# Set for one command only
MY_VAR="value" command

# Example:
NODE_ENV=production npm run build

Tips & Tricks​

Reverse search:

# Press Ctrl+R
# Type search term
# Press Enter to execute
# Or Ctrl+G to cancel

History commands:

# Show history
history

# Execute command from history
!123 # Execute command #123

# Execute last command
!!

# Execute last command starting with 'git'
!git

# Use argument from previous command
ls /some/path
cd !$ # cd to /some/path

2. Command Aliases​

Create aliases:

# In ~/.bashrc or ~/.zshrc

# Navigation
alias ..='cd ..'
alias ...='cd ../..'
alias ~='cd ~'

# Listing
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'

# Git shortcuts
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git pull'

# Safety nets
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Quick edits
alias bashrc='code ~/.bashrc'
alias zshrc='code ~/.zshrc'

3. Useful One-Liners​

File operations:

# Create timestamped backup
cp file.txt file.txt.backup-$(date +%Y%m%d_%H%M%S)

# Find and replace in files
find . -name "*.js" -exec sed -i 's/old/new/g' {} \;

# Count files in directory
find . -type f | wc -l

# Find duplicate files
find . -type f -exec md5sum {} \; | sort | uniq -w32 -dD

Text processing:

# Remove empty lines
sed '/^$/d' file.txt

# Print specific lines
sed -n '10,20p' file.txt

# Replace text
sed 's/old/new/g' file.txt

# Extract column
awk '{print $1}' file.txt

System info:

# Current date/time
date +"%Y-%m-%d %H:%M:%S"

# System uptime
uptime

# Logged in users
who

# Last logins
last | head

4. Keyboard Shortcuts Reminder​

Line editing:

  • Ctrl+A - Beginning of line
  • Ctrl+E - End of line
  • Ctrl+U - Delete to beginning
  • Ctrl+K - Delete to end
  • Ctrl+W - Delete word backward
  • Alt+D - Delete word forward

Navigation:

  • Ctrl+B - Backward one character
  • Ctrl+F - Forward one character
  • Alt+B - Backward one word
  • Alt+F - Forward one word

Control:

  • Ctrl+C - Cancel command
  • Ctrl+D - Exit (EOF)
  • Ctrl+Z - Suspend process
  • Ctrl+L - Clear screen
  • Ctrl+R - Reverse search

Next Steps​