Israel Science and Technology Directory

Internet Linkcheck Usage

Introduction

Linkcheck is run in a terminal with the simple command linkcheck, followed by a series of options that can be seen by entering linkcheck --help. In the examples below, the website searched is "localhost/". You can replace this with the URL of a website.

Hyperlinks that point to another page in the same website or domain are called internal links. The default operation mode of Linkcheck is checking only internal links within the directory specified. The code below will scan all the subdirectories within the localhost/.

linkcheck localhost/

Limiting the range of checking

The range of checking can be limited to a directory by specifying the directory name after localhost/. Example: localhost/Documents/.

See below for using --skip-file option under the section Checking external links

Redirecting Linkcheck report to a file

The default output of Linkcheck is the terminal screen. If your website includes many files in many sub-directories, the output may be too long to analyze directly on screen. The output of Linkcheck can be directed to a file using the standard Linux method of output redirection. For example, to redirect linkcheck's output to a file named lc-report.txt in your /home/username directory, add the command for redirection:

linkcheck localhost/ > /home/$USER/lc-report.txt

If you want to visualize the process simultaneously on the terminal as well, you can use the tee command as follows: linkcheck ... | tee report.txt

To check links to external (remote) sites, Linkcheck should be run with two options:
-e specifying to check external sites; and
--show‑redirects instructing to include redirected links in the report.
The full command:

linkcheck -e --show-redirects localhost/

To prevent linkcheck from examining a URL, add the URL into a file named skip.txt and place this file in the Home directory of the user. To read this file, enter the following command:

linkcheck --skip-file skip.txt localhost/

The list in skip.txt may include Regular Expressions. Example: The regular expression ^.*\.zip$ tells linkcheck to skip all files with a zip extension.

Important: Recent versions of Linkcheck may scan URLs found within <script> tags, which can lead to repetitive appearance of "broken" or "redirected" reports for third-party services like Google AdSense or Tag Manager. To exclude these, you can add these to your skip.txt file. Terminate the URL with an asterisk "*". Examples:
https://www.googletagmanager.com/*
https://pagead2.googlesyndication.com/*

Linkcheck command with full options

The command below will scan both internal and external sites, and redirect Linkcheck's output to a file named lc-report.txt in your /home/$USER directory:

linkcheck -e --show-redirects localhost/ > /home/$USER/lc-report.txt

If you wish, you can add to this command an optional filename to skip, as explained above.

Next step: Analyzing Linkcheck results

ADVERTISEMENT