lynx Command

The lynx command is a text-based web browser that runs in the terminal. It allows you to browse websites, follow links, download files, and navigate the web without a graphical interface, making it ideal for servers, automation, and accessibility.

Syntax

lynx [OPTIONS] [URL]

Description

The lynx browser is a fully-featured web browser that operates entirely in text mode. It supports HTML, forms, cookies, SSL, and many modern web features while maintaining a lightweight footprint.

Key features:

  • Text-based web browsing
  • Support for HTML, forms, and cookies
  • SSL/HTTPS support
  • File download capabilities
  • Configurable user agent and settings
  • Accessibility features for screen readers
  • Scripting and automation support
Note: Lynx may need to be installed on some systems. Use your package manager (apt, yum, dnf) to install it if not available.

Common Options

Option Description
-dump Output page content as formatted text and exit
-source Output raw HTML source and exit
-listonly List only the links found in the page
-crawl Output each page to a file and continue crawling
-traversal Traverse all links from starting page
-accept_all_cookies Accept all cookies without prompting
-anonymous Apply anonymous restrictions (no downloads, etc.)
-auth=id:pw Set authentication credentials
-cfg=file Use specified configuration file
-cookies Toggle cookie support
-display=DISPLAY Set X display for external programs
-editor=EDITOR Set external editor for forms
-homepage=URL Set home page URL
-mime_header Include MIME headers in output
-nolist Don't list links at end of dump
-useragent=string Set User-Agent header
-width=N Set screen width for formatting

Navigation Keys

Key Action
Arrow Keys Navigate between links and text
Enter Follow selected link
Tab Move to next link
Shift+Tab Move to previous link
g Go to URL
G Edit current URL
h Help
k Show keymap
o Options menu
p Print page
q Quit
r Reload page
s Search in page
u Go back
v View bookmarks
/ Search forward
? Search backward
Space Page down
b Page up

Examples

Basic web browsing

lynx https://www.example.com

Open a website in interactive mode

Dump page content as text

lynx -dump https://www.example.com

Extract page content as formatted text

Get raw HTML source

lynx -source https://www.example.com

Download raw HTML source code

List all links on a page

lynx -listonly -dump https://www.example.com

Extract all links from a webpage

Set custom user agent

lynx -useragent="MyBot/1.0" https://www.example.com

Browse with custom User-Agent string

Accept all cookies

lynx -accept_all_cookies https://www.example.com

Accept cookies without prompting

Set output width

lynx -width=120 -dump https://www.example.com

Format output for specific width

Save to file

lynx -dump https://www.example.com > page.txt

Save page content to a file

Web Scraping and Automation

Content Extraction

Extract text content

# Basic text extraction lynx -dump -nolist https://news.ycombinator.com # With custom width lynx -dump -width=80 -nolist https://www.example.com # Include MIME headers lynx -dump -mime_header https://www.example.com

Extract clean text content from web pages

Link extraction

# List all links lynx -listonly -dump https://www.example.com # Extract only URLs lynx -listonly -dump https://www.example.com | grep "http" # Get links with descriptions lynx -dump https://www.example.com | tail -n +$(lynx -dump https://www.example.com | grep -n "References" | cut -d: -f1)

Extract links and references from web pages

Batch Processing

Process multiple URLs

# Process URL list while read url; do echo "Processing: $url" lynx -dump "$url" > "$(echo $url | sed 's|https\?://||' | tr '/' '_').txt" done < urls.txt # Extract titles from multiple pages for url in $(cat urls.txt); do title=$(lynx -dump "$url" | head -1) echo "$url: $title" done

Process multiple URLs in batch

Web crawling

# Simple crawling lynx -crawl -traversal https://www.example.com # Crawl with depth limit (manual implementation) lynx -listonly -dump https://www.example.com | \ grep "http" | head -10 | \ while read url; do lynx -dump "$url" > "crawled_$(date +%s).txt"; done

Crawl websites and extract content

Form Handling

Submit forms programmatically

# Interactive form filling (requires user input) lynx https://httpbin.org/forms/post # For automation, consider using curl or wget for form submission # lynx is better for viewing and understanding form structure

Handle web forms (limited automation capabilities)

Configuration

Configuration Files

User configuration

# User config file location ~/.lynxrc # System config /etc/lynx.cfg # Use custom config lynx -cfg=/path/to/custom.cfg https://www.example.com

Lynx configuration file locations

Common configuration options

# Example .lynxrc settings ACCEPT_ALL_COOKIES:TRUE COOKIE_FILE:~/.lynx_cookies DEFAULT_INDEX_FILE:https://www.google.com STARTFILE:https://www.example.com USER_AGENT:Lynx/2.8.9 CHARACTER_SET:utf-8 ASSUME_CHARSET:iso-8859-1

Common configuration settings

Environment Variables

Useful environment variables

# Set HTTP proxy export http_proxy=http://proxy.example.com:8080 export https_proxy=http://proxy.example.com:8080 # Set home page export WWW_HOME=https://www.example.com # Set editor for forms export EDITOR=nano # Set display for external programs export DISPLAY=:0

Environment variables affecting lynx behavior

Advanced Usage

Authentication

HTTP authentication

# Basic authentication lynx -auth=username:password https://secure.example.com # Interactive authentication (prompted) lynx https://secure.example.com

Handle HTTP authentication

SSL/HTTPS

SSL options

# Accept SSL certificates (be cautious) lynx -accept_all_cookies -ssl_strict_check=FALSE https://self-signed.example.com # Normal HTTPS browsing lynx https://secure.example.com

Handle SSL/HTTPS connections

Proxy Support

Using proxies

# Set proxy via environment export http_proxy=http://proxy.example.com:8080 lynx https://www.example.com # SOCKS proxy (if supported) export http_proxy=socks5://proxy.example.com:1080 lynx https://www.example.com

Browse through proxy servers

Practical Use Cases

System Administration

Monitor web services

# Check if web service is responding if lynx -dump http://localhost:8080/health | grep -q "OK"; then echo "Service is healthy" else echo "Service may be down" fi # Monitor multiple services for service in web1.example.com web2.example.com; do status=$(lynx -dump "http://$service/status" 2>/dev/null | head -1) echo "$service: $status" done

Monitor web services and health checks

Download files

# Download files (interactive mode) lynx ftp://ftp.example.com/file.txt # For automated downloads, use wget or curl # lynx is better for browsing and finding download links lynx -listonly -dump https://downloads.example.com | grep "\.zip"

Browse and identify files for download

Content Analysis

SEO and content analysis

# Extract page title lynx -dump https://www.example.com | head -1 # Count words on page lynx -dump -nolist https://www.example.com | wc -w # Extract headings (approximate) lynx -dump https://www.example.com | grep -E "^[A-Z].*$" | head -10 # Check for specific keywords lynx -dump https://www.example.com | grep -i "keyword"

Analyze web page content and structure

Link analysis

# Count external links lynx -listonly -dump https://www.example.com | grep -c "http" # Find broken links (basic check) lynx -listonly -dump https://www.example.com | grep "http" | \ while read url; do if ! lynx -dump "$url" >/dev/null 2>&1; then echo "Broken: $url" fi done # Extract domain names from links lynx -listonly -dump https://www.example.com | \ grep -o 'https\?://[^/]*' | sort | uniq -c

Analyze links and link structure

Accessibility Testing

Text-only accessibility

# Test how page appears to screen readers lynx -dump https://www.example.com # Check navigation without images lynx https://www.example.com # Navigate using only keyboard # Test form accessibility lynx https://www.example.com/contact

Test website accessibility for text-based browsing

Scripting Examples

Website Monitoring Scripts

Website uptime checker

#!/bin/bash WEBSITE="$1" if [ -z "$WEBSITE" ]; then echo "Usage: $0 " exit 1 fi echo "Checking $WEBSITE..." if lynx -dump "$WEBSITE" >/dev/null 2>&1; then echo "✓ $WEBSITE is accessible" title=$(lynx -dump "$WEBSITE" | head -1) echo "Title: $title" else echo "✗ $WEBSITE is not accessible" exit 1 fi

Monitor website availability and basic functionality

Content change detector

#!/bin/bash URL="$1" CACHE_FILE="/tmp/$(echo $URL | tr '/' '_').cache" # Get current content CURRENT=$(lynx -dump -nolist "$URL" 2>/dev/null) if [ -f "$CACHE_FILE" ]; then PREVIOUS=$(cat "$CACHE_FILE") if [ "$CURRENT" != "$PREVIOUS" ]; then echo "Content changed on $URL" echo "Previous length: $(echo "$PREVIOUS" | wc -c)" echo "Current length: $(echo "$CURRENT" | wc -c)" else echo "No changes detected on $URL" fi else echo "First run - caching content" fi echo "$CURRENT" > "$CACHE_FILE"

Detect changes in web page content

Data Extraction Scripts

News headline extractor

#!/bin/bash echo "=== Latest Headlines ===" # Extract headlines from news sites lynx -dump -nolist https://news.ycombinator.com | \ grep -E "^[0-9]+\." | head -10 echo echo "=== Reddit Front Page ===" lynx -dump -nolist https://old.reddit.com | \ grep -E "^[0-9]+\." | head -5

Extract headlines and summaries from news websites

Price monitoring

#!/bin/bash PRODUCT_URL="$1" if [ -z "$PRODUCT_URL" ]; then echo "Usage: $0 " exit 1 fi echo "Monitoring prices on: $PRODUCT_URL" # Extract price information (site-specific) CONTENT=$(lynx -dump "$PRODUCT_URL") PRICE=$(echo "$CONTENT" | grep -o '\$[0-9,]*\.[0-9][0-9]' | head -1) if [ -n "$PRICE" ]; then echo "$(date): Current price: $PRICE" echo "$(date): $PRICE" >> price_history.log else echo "Could not extract price information" fi

Monitor product prices and track changes

Troubleshooting

Common Issues

Installation issues

# Install lynx on different systems # Ubuntu/Debian sudo apt-get install lynx # CentOS/RHEL/Fedora sudo yum install lynx # or sudo dnf install lynx # macOS (with Homebrew) brew install lynx # Check if lynx is installed which lynx lynx --version

Install lynx on different operating systems

Display and encoding issues

# Set character encoding lynx -assume_charset=utf-8 https://www.example.com # Force specific display charset lynx -display_charset=utf-8 https://www.example.com # Handle wide characters lynx -width=120 https://www.example.com

Handle character encoding and display issues

Network and proxy issues

# Debug network issues lynx -trace https://www.example.com # Bypass proxy for specific sites unset http_proxy https_proxy lynx https://www.example.com # Test with different user agent lynx -useragent="Mozilla/5.0" https://www.example.com

Troubleshoot network connectivity and proxy issues

Performance Issues

Slow loading pages

# Disable images and multimedia lynx -noprint -nolist https://heavy-site.example.com # Set timeout lynx -connect_timeout=10 https://slow-site.example.com # Use dump mode for faster processing lynx -dump https://www.example.com

Handle slow-loading or heavy websites

Comparison with Other Tools

lynx vs curl/wget

Feature lynx curl/wget
Purpose Web browsing and content viewing File downloading and HTTP requests
JavaScript No support No support
Forms Interactive support Manual POST data
Cookies Automatic handling Manual cookie jar
Content Rendering Text formatting Raw content

When to use each tool

# Use lynx for: # - Interactive web browsing in terminal # - Content extraction with formatting # - Accessibility testing # - Form interaction # Use curl for: # - API testing and HTTP requests # - File downloads # - Custom headers and authentication # - Precise HTTP control # Use wget for: # - Recursive downloads # - Mirror websites # - Resume interrupted downloads # - Background downloads

Choose the right tool for your specific needs

Best Practices

lynx Best Practices
  • Respect Robots.txt - Check robots.txt before automated scraping
  • Use Appropriate User-Agent - Identify your bot properly
  • Rate Limiting - Add delays between requests to avoid overloading servers
  • Handle Errors - Check exit codes and handle network failures gracefully
  • Cache Results - Store results to avoid repeated requests
  • Test Accessibility - Use lynx to test how your sites work without JavaScript

See also