SysTutorials

Converting HTML to Plain Text on Linux

· updated April 13, 2026

You have several options for converting HTML files to plain text, each with different strengths depending on your use case.

html2text

The most straightforward tool is html2text, available on most distributions:

html2text input.html

The converted text prints to stdout. Redirect to a file if needed:

html2text input.html > output.txt

Install it via your package manager:

# Debian/Ubuntu
sudo apt install html2text

# Fedora/RHEL
sudo dnf install html2text

# Arch
sudo pacman -S html2text

Useful options include:

Example with multiple options:

html2text --body-width 100 --ignore-links input.html > output.txt

lynx

lynx is a text-based web browser that can dump HTML to plain text:

lynx -dump -nolist input.html > output.txt

Key flags:

Install with:

# Debian/Ubuntu
sudo apt install lynx

# Fedora/RHEL
sudo dnf install lynx

# Arch
sudo pacman -S lynx

w3m

Another text browser option:

w3m -dump input.html > output.txt
# Debian/Ubuntu
sudo apt install w3m

# Fedora/RHEL
sudo dnf install w3m

# Arch
sudo pacman -S w3m

pandoc

For more sophisticated conversions (especially when converting between multiple formats), use pandoc:

pandoc input.html -t plain -o output.txt

Pandoc is particularly useful if you need to convert to other formats later (Markdown, reStructuredText, etc.). It handles complex HTML better than simpler tools:

# Install
sudo apt install pandoc  # Debian/Ubuntu
sudo dnf install pandoc  # Fedora/RHEL

Command-line processing with sed/awk

For quick one-off conversions or integrating into scripts, strip HTML tags with basic text processing:

sed 's/<[^>]*>//g' input.html > output.txt

This removes all HTML tags but doesn’t handle entities (&nbsp;, &lt;, etc.). For better handling:

sed 's/<[^>]*>//g; s/&nbsp;/ /g; s/&lt;/</g; s/&gt;/>/g; s/&amp;/\&/g' input.html

Choosing a tool

For most cases, html2text is the right choice. It’s fast, handles most HTML correctly, and doesn’t require interpreting JavaScript or rendering complex layouts.

2026 Best Practices

This article extends “Converting HTML to Plain Text on Linux” with practical guidance. Modern development practices emphasize security, performance, and maintainability. Follow these guidelines to build robust, production-ready systems.

2026 Comprehensive Guide for Linux

This article extends “Converting HTML to Plain Text on Linux” with advanced techniques and best practices for 2026. Following modern guidelines ensures reliable, maintainable, and secure systems.

Advanced Implementation Strategies

For complex deployments involving linux, consider Infrastructure as Code for reproducible environments, container-based isolation for dependency management, and CI/CD pipelines for automated testing and deployment.

Security and Hardening

Security should be built into workflows from the start. Use strong authentication methods, encrypt sensitive data, and follow the principle of least privilege for access controls.

Performance Optimization

Troubleshooting Methodology

Follow a systematic approach to debugging: reproduce issues, isolate variables, check logs, test fixes. Keep detailed logs and document solutions found.

Best Practices

Resources and Further Reading

For more information on linux, consult official documentation and community resources. Stay updated with the latest tools and frameworks.

← All posts