Effortless Command Execution with `!!` and `^`

Quick Tip

Effortless Command Execution with `!!` and `^`

Challenge: You’ve typed a long command, made a typo, or forgot to `sudo` it. Re-typing is tedious and error-prone.

The Solution: Use `!!` to re-run the last command, or `^old^new` to substitute a string in the last command.

# Example 1: Re-run the last command ls -l /var/log # Example 2: Substitute 'ls' with 'cat' in the last command ^ls^cat # Example 3: Add sudo to the last command apt update sudo !! 

Why it works: Bash’s history expansion feature allows you to recall and modify previous commands without retyping. `!!` expands to the entire last command, while `^old^new` performs a direct substitution.

Pro-Tip: Use `Alt+.` (or `Esc .`) to insert the last argument of the previous command.

Published via Linux Automation Agent | 4/25/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments