How to Access Url from Linux Command Line

How to Access Url from Linux Command Line

The quickest way to answer how to access url from linux command line is to use curl or wget. If you want to see the page content or check a response, curl is usually the best choice. If you want to download a file or webpage, wget is often simpler. Both work well from a Linux terminal and can handle most HTTP and HTTPS URLs.

What it means to access a URL from the Linux command line

What it means to access a URL from the Linux command line

Accessing a URL from the Linux command line means sending an HTTP or HTTPS request to a web address without opening a graphical browser. Depending on your goal, you might want to:

  • View the page source or response body
  • Check whether a URL is reachable
  • See headers such as status code or redirect location
  • Download a file to disk
  • Test an API endpoint

Different tools are better for different tasks. The most common are curl and wget.

Use curl to fetch a URL

Use curl to fetch a URL

curl is the most flexible command-line tool for accessing URLs. It is especially useful when you want to inspect headers, status codes, redirects, or API responses.

Basic curl example

curl https://example.com

This prints the response body to your terminal. If the URL returns HTML, you will usually see the page source rather than a rendered web page.

Save the output to a file

curl -o page.html https://example.com

Use -o to save the content under a file name you choose.

Follow redirects

curl -L https://example.com

Many URLs redirect to another location. -L tells curl to follow those redirects automatically.

Show only headers

curl -I https://example.com

This fetches just the response headers, which is useful for checking status codes, content type, cache headers, or redirect targets.

Check the HTTP status code

curl -o /dev/null -s -w "%{http_code}
" https://example.com

This is a common way to verify whether a URL returns 200, 301, 404, or another status code.

Use wget to download a URL

wget is a strong choice when your main goal is downloading content. It is straightforward and works well for saving web pages or files from the terminal.

Basic wget example

wget https://example.com/file.zip

By default, wget saves the file using the original name from the URL.

Download a webpage

wget https://example.com

This downloads the response content to a local file, usually named after the remote path or saved as index.html depending on the server response and options used.

Save the file with a custom name

Save the file with a custom name
wget -O myfile.html https://example.com

Use -O when you want to choose the output filename yourself.

Follow redirects

wget --max-redirect=20 https://example.com

wget normally follows redirects, but this option can help if you need to adjust redirect behavior.

Check headers and status codes

If your goal is to verify whether a URL is alive, headers are often more useful than full page content.

GoalCommandTypical result
View page contentcurl https://example.comShows body content in terminal
Download a filewget https://example.com/file.zipSaves file locally
Check headers onlycurl -I https://example.comShows response headers
Check status code onlycurl -o /dev/null -s -w "%{http_code}
" https://example.com
Prints HTTP status code

Common status codes include 200 for success, 301 or 302 for redirects, 403 for forbidden access, and 404 for not found.

Follow redirects and handle HTTPS

Some URLs do not serve content directly from the first address you type. They may redirect from http to https, or from one domain to another. That is normal.

Follow redirects with curl

curl -L https://example.com

If you skip -L, curl may show only the redirect response instead of the final content.

Handle HTTPS certificate checks

Most of the time, Linux tools validate HTTPS certificates automatically. If a certificate problem appears, it may mean the server certificate is invalid, missing, expired, or not trusted by your system.

For troubleshooting only, you can test without certificate verification in curl:

curl -k https://example.com

This bypasses certificate validation, but you should avoid it unless you understand the security tradeoff.

Choose between curl and wget

If you are not sure which tool to use, this rule of thumb helps: use curl for inspection and automation, and use wget for downloading.

If you want to…UseWhy
Inspect a responsecurlBetter for headers, status codes, and APIs
Download a filewgetSimple and convenient for saving content
Follow redirects and debug requestscurlMore control over the request
Mirror or recursively fetch contentwgetDesigned for file retrieval and site downloading

In practice, many Linux users keep both installed because they solve slightly different problems.

Practical examples

Here are a few common patterns you can copy and adapt.

Check whether a page exists

curl -o /dev/null -s -w "%{http_code}
" https://example.com/page

Download a PDF

wget https://example.com/files/manual.pdf

Fetch a JSON API response

curl https://api.example.com/status

Inspect response headers from an API

curl -I https://api.example.com/status

Save the response body to a specific file

Save the response body to a specific file
curl -L -o output.txt https://example.com/data.txt

Troubleshooting common errors

Command not found

If Linux says curl: command not found or wget: command not found, the tool is not installed. On many distributions, you can install it with your package manager, such as apt, dnf, or pacman.

SSL or certificate errors

Certificate errors usually point to a server-side certificate issue or a local trust problem. Check whether your system clock is correct, because a wrong date can also trigger HTTPS failures.

Redirect loops

If a URL keeps redirecting, the site may be misconfigured or may require a specific scheme such as HTTPS. Try the final destination URL directly, or inspect redirects with:

curl -I -L https://example.com

Permission or write errors

If a download fails because the destination file cannot be created, check file permissions and the current directory. Try saving to a writable location such as your home directory.

Unexpected HTML instead of a file

Sometimes a URL points to a webpage rather than a downloadable file. In that case, the server may return HTML content instead of binary data. Use curl -I or inspect the browser URL to confirm what the server is serving.

Frequently Asked Questions About how to access url from linux command line

How do I access a URL from Linux terminal?

Use curl URL to print the response in the terminal, or wget URL to download it. For most cases, curl is the quickest way to inspect a URL.

What is the command to open a URL in Linux command line?

There is no single universal “open” command for URLs in the terminal. For text-based access, use curl or wget. If you want to open a URL in a graphical browser from the terminal, that depends on your desktop environment.

How do I download a webpage using wget?

Run wget https://example.com. If you want to control the saved filename, use wget -O filename.html https://example.com.

How do I check a URL response code in Linux?

A common method is curl -o /dev/null -s -w "%{http_code}
" URL
. This prints only the HTTP status code, such as 200 or 404.

What is the difference between curl and wget?

curl is better for inspecting responses, headers, and APIs. wget is better for downloading files and simple retrieval tasks. They overlap, but their strengths are slightly different.

Can I access HTTPS URLs from the Linux command line?

Yes. Both curl and wget support HTTPS URLs. If certificate validation fails, the issue is usually with the certificate, system trust store, or local clock.

Conclusion

If you want to know how to access url from linux command line, start with curl for inspection and wget for downloads. Use curl -I for headers, curl -L for redirects, and wget when you want to save a file quickly. Once you understand those basics, you can check status codes, troubleshoot HTTPS issues, and work with URLs entirely from the terminal.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *