Post

Curl Cheatsheet

get website header responses

1
curl -I http://example.com

Find a string

To search for a specific string within the website content, you can pipe the output of curl to grep. grep is a command-line tool used for searching text patterns. For example, to search for the string “example” in the website content, you can use:

1
curl https://example.com | grep "example"

By default, grep is case-sensitive. If you want to perform a case-insensitive search, you can use the -i flag like this:

1
2
curl https://example.com | grep -i "example"

If you want to extract more specific information or format the output differently, you can use awk for more advanced text processing. For instance, to extract and print the lines containing the word “example” along with line numbers, you can use:

1
curl https://example.com | awk '/example/{print NR, $0}'

Check URL redirect is working

You can use this to check if http is redirecting to https. Or any other redirect. The response will contain the end point url.

  • The location header in the response should be the https version.
  • The status code should be 301 or 302
1
curl -I http://yourdomain.com

Bypass the cache

1
curl -I -H "Cache-Control: no-cache" http://yourdomain.com
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.