Back to Blog

Zsh Tutorial: curl, SSH, rsync — Network Like a Pro #23

Sandy LaneSandy Lane

Video: Zsh Tutorial: curl, SSH, rsync — Network Like a Pro #23 by Taught by Celeste AI - AI Coding Coach

Watch full page →

Zsh Tutorial: curl, SSH, rsync — Network Like a Pro

This tutorial introduces essential network commands in Zsh, focusing on tools like curl for HTTP requests and REST API interactions, plus network diagnostics with ping and nc. It also covers SSH configuration for streamlined connections and file synchronization using rsync and scp.

Code

# Basic curl GET request to fetch a webpage
curl https://example.com

# Save the output to a file (-o filename) or save with remote name (-O)
curl -o homepage.html https://example.com
curl -O https://example.com/image.png

# Follow redirects with -L
curl -L https://short.url/link

# Fetch only HTTP headers
curl -I https://example.com

# Send custom headers (e.g., API key)
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/data

# Silent mode with progress info and response time
curl -s -w "Time: %{time_total}s\n" https://example.com -o /dev/null

# POST JSON data to an API endpoint
curl -X POST -H "Content-Type: application/json" -d '{"name":"Alice"}' https://api.example.com/users

# Use basic authentication
curl -u username:password https://api.example.com/secure-data

# Filter JSON response using jq (requires jq installed)
curl -s https://api.example.com/users | jq '.users[] | {id, name}'

# Update or delete resources with PUT and DELETE
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Bob"}' https://api.example.com/users/123
curl -X DELETE https://api.example.com/users/123

# Ping a host to check reachability
ping -c 4 google.com

# Check if a port is open using netcat (nc)
nc -zv example.com 22

# SSH config (~/.ssh/config) example for aliasing
# Host myserver
#   HostName 192.168.1.10
#   User alice
#   Port 2222

# Sync files with rsync (archive mode, verbose)
rsync -av ~/projects/ alice@myserver:/backup/projects/

# Secure copy files over SSH
scp ~/file.txt alice@myserver:/home/alice/

Key Points

  • curl is a versatile tool for HTTP requests, supporting GET, POST, PUT, DELETE, custom headers, and authentication.
  • Use jq to parse and filter JSON API responses directly in the terminal.
  • ping and nc help diagnose network connectivity and port availability.
  • SSH config files simplify connecting to remote hosts with aliases and custom settings.
  • rsync and scp provide efficient and secure options for syncing and copying files over SSH.