Links2 - Command-Line Web Browser Utility

Explore the capabilities of Links2, a powerful command-line web browser. Learn how to browse, dump page content, set user agents, enable numbered links, and more with practical examples.

Links2 - Command-Line Web Browser

Links2 is a powerful, text-based web browser that offers a Lynx-like experience in character mode. It's a versatile tool for developers and users who prefer working within the terminal. This guide explores various ways to utilize Links2 for browsing, content extraction, and customization.

Browse Web Pages Directly

The most straightforward use of Links2 is to launch it and immediately navigate to a specified web address. This is ideal for quick checks or when you need to access a site without opening a graphical browser.

# Launch and browse immediately to the provided web address.
links2 duckduckgo.co.uk

Dump Formatted Page Content

Links2 can extract and display the formatted content of a web page directly to your standard output (STDOUT). This is incredibly useful for scraping web content or analyzing page structure without rendering it visually.

# Dump the formatted result (not source) of a given page to STDOUT.
links2 -dump duckduckgo.co.uk

Control Output Width

When using the -dump option, you can also specify the desired maximum line length for the output. This helps in formatting the dumped content to fit your terminal or preferred viewing width.

# Specify the desired maximum line length, in characters.
links2 -dump -width 80 duckduckgo.co.uk

Spoof User Agent

Some websites restrict access based on the browser's User-Agent string. Links2 allows you to spoof this string, making it appear as if you are browsing from a different browser, such as Firefox. This can help in accessing sites that might otherwise block standard text browsers.

# Spoof the UA (UserAgent) to mimic a Mozilla Firefox 5.0 browser.
links2 -http.fake-user-agent 'Mozilla/5.0' duckduckgo.co.uk

Enable Do Not Track

Respecting user privacy, Links2 supports the "Do Not Track" feature. By enabling this option, you can signal to websites that you do not wish to be tracked during your browsing session.

# Enable the 'Do Not Track' option.
links2 -http.do-not-track 1 duckduckgo.co.uk

One of the most convenient features of Links2 is the ability to display numbered links on a page. This allows for quick and precise navigation by simply typing the corresponding number followed by Enter, significantly speeding up browsing.

# Enable numbered links for easier and quicker browsing.
links2 -html-numbered-links 1 duckduckgo.co.uk

Custom Shell Function for Quick Searches

For frequent searches, you can create a custom shell function to streamline the process. This example defines a function l2 that allows you to search DuckDuckGo by simply typing l2 followed by your search query.

# A Shell function to quickly access and search with DDG.
l2(){ links2 http://duckduckgo.com/?q="$*"; }

# Example usage: l2 Perl

External Resources