Linux command
exclamation 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Repeat the last command
!!
Repeat last command starting with string
![string]
Repeat command number N from history
![N]
Repeat Nth last command
!-[N]
Substitute and repeat
^[old]^[new]
Use last argument of previous command
[command] !$
说明
! (history expansion) allows reusing and modifying previous commands. It's a shell feature (bash, zsh) that expands references to command history before execution. Common patterns: - sudo !! - Rerun last command with sudo - !$ - Last argument of previous command - !!:s/foo/bar/ - Repeat last command with substitution - !vim - Run most recent vim command History expansion happens before other expansions, allowing powerful command reuse with modifications.
参数
- !!
- The previous command
- !n
- Command line number n
- !-n
- Current command minus n
- !string
- Most recent command starting with string
- !?string?
- Most recent command containing string
- !#
- Current command line typed so far
FAQ
What is the exclamation command used for?
! (history expansion) allows reusing and modifying previous commands. It's a shell feature (bash, zsh) that expands references to command history before execution. Common patterns: - sudo !! - Rerun last command with sudo - !$ - Last argument of previous command - !!:s/foo/bar/ - Repeat last command with substitution - !vim - Run most recent vim command History expansion happens before other expansions, allowing powerful command reuse with modifications.
How do I run a basic exclamation example?
Run `!!` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does !! do in exclamation?
The previous command