How to Check a Website Header Using Linux Command Line

Checking the headers of a website can provide valuable information about the server, security policies, and other metadata. This is particularly useful for web developers, system administrators, and security professionals. The Linux command line offers several tools that allow users to inspect website headers easily and efficiently.

In this tutorial you will learn:

  • How to use the curl command to check website headers
  • How to use the wget command to inspect website headers
  • How to use the httpie command to retrieve website headers
  • How to use the lynx command to inspect headers
How to Check a Website Header Using Linux Command Line
How to Check a Website Header Using Linux Command Line
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Linux operating system
Software curl, wget, httpie, lynx
Other Internet connection
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Introduction to Methods for Checking Website Headers

There are several methods to check website headers using the Linux command line. Each method utilizes different tools that are pre-installed or easily installable on most Linux distributions. These methods will allow you to retrieve and inspect the headers returned by a web server when a request is made to a website.

  1. Using the curl Command: The curl command is a widely used tool for transferring data with URLs. It supports various protocols, including HTTP, HTTPS, FTP, and more. To check the headers of a website, you can use the following command:
    $ curl -I http://example.com

    This command fetches the headers of the specified URL. The -I option tells curl to fetch the headers only, without downloading the entire content. The output will include details such as HTTP status code, content type, server information, and more.

  2. Using the wget Command: The wget command is another powerful utility for retrieving files from the web. While it is primarily used for downloading files, it can also be used to fetch and display headers.
    $ wget --spider -S http://example.com

    In this command, the --spider option tells wget to check the URL without downloading the content, and the -S option displays the headers sent by the server. This method provides a detailed view of the headers, including the HTTP status code and other relevant information.



  3. Using the httpie Command: httpie is a user-friendly command-line HTTP client. It is designed for ease of use, allowing for simple and intuitive interaction with web services. Note that httpie needs to be installed first:
    $ sudo apt-get install httpie

    Once installed, you can use the following command to check headers:

    $ http -h GET http://example.com

    In this command, http is the command-line tool, -h specifies that only headers should be displayed, and GET is the HTTP method used. This method provides a clean and readable output of the headers, making it easy to interpret the information returned by the server.

    obtain website header using the httpie Command
    obtain website header using the httpie Command
  4. Using the lynx Command: lynx is a text-based web browser for the command line. It can be used to retrieve headers by making a request to the specified URL.
    $ lynx -head -dump http://example.com

    In this command, -head specifies that only the headers should be fetched, and -dump outputs the headers to the command line. This method provides a straightforward way to view the headers of a website using a text-based browser.

Conclusion

Checking website headers using the Linux command line is a straightforward process with the right tools. curl, wget, httpie, and lynx are all effective utilities that can help you retrieve and inspect headers for various purposes, such as debugging, monitoring, and security analysis. By mastering these commands, you can gain valuable insights into the behavior and configuration of web servers.



Comments and Discussions
Linux Forum