↑ ↓ select, Enter open, Esc close

Read the canonical tag of a page with curl

Adjust the values, the command updates live
user@server
curl -s https://example.com/ | tr '\n' ' ' | grep -oiE '<link[^>]*canonical[^>]*>'

Loads the HTML, joins it into a single line and prints the <link rel="canonical"> element. The canonical should point to the page’s own reachable URL with status 200, not to a redirect, a staging domain or the http variant. More than one line in the output indicates duplicate canonicals, which Google then ignores.

Note: A canonical can also be sent as an HTTP header Link: <...>; rel="canonical", which curl -sI {{URL}} | grep -i '^link:' shows.

Also searched as

  • check canonical url of a page
  • show rel canonical command line
  • find wrong canonical tag
  • what is the canonical url of this page

Related one-liners

All in SEO checks

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.