caret
Shell history substitution and regex anchor character
TLDR
Quick substitution on last command
$ ^[old]^[new]
Repeat last command replacing text$ ^typo^fixed
Start of line anchor (regex)$ grep "^start" [file]
Negation in character class (regex)$ grep "[^0-9]" [file]
SYNOPSIS
^old^new[^]
DESCRIPTION
^ in shell has multiple meanings:History substitution: ^old^new is a shortcut for !!:s/old/new/, replacing text in the previous command. Quick fix for typos without retyping.Regular expression anchor: ^ matches the start of a line. ^hello matches lines starting with "hello".Character class negation: [^abc] matches any character except a, b, or c.Exponentiation: In $((...)) and some languages, ^ may be XOR or exponent (use ******** in bash for exponent).
PARAMETERS
^old^new
Replace first occurrence of old with new in the previous command and execute it.^old^new^
Same substitution; the trailing ^ is optional unless appending additional text.!!:s/old/new/
Equivalent long-form history substitution syntax.!!:gs/old/new/
Replace all occurrences of old with new in the previous command.
CAVEATS
^old^new only replaces the first occurrence. For global replacement, use !!:gs/old/new/.In some shells/contexts, ^ may need escaping or behave differently.The caret substitution must be at the start of the command line.
