caret
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).
EXAMPLES
$ # Fix typo in previous command
$ echo "helo world"
helo world
$ ^helo^hello
echo "hello world"
hello world
# Regex: lines starting with #
grep "^#" config.txt
# Regex: non-digits
grep "[^0-9]" file.txt
$ echo "helo world"
helo world
$ ^helo^hello
echo "hello world"
hello world
# Regex: lines starting with #
grep "^#" config.txt
# Regex: non-digits
grep "[^0-9]" file.txt
HISTORY SUBSTITUTION
^old^new
Replace first occurrence of "old" with "new" in previous command and execute^old^new^
Same, trailing ^ is optional!!:s/old/new/
Equivalent using full history syntax
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.


