Bang (!) Commands
Hint in some shells you can hit space after the bang command and the command in full will populate
Befehle
!!:
Run the previous command. sudo !! is very helpful
!:0:
The first word of the last command
!$:
The last word of the previous command. Example, mkdir /tmp/foo , then run cd !$ to change directory to the one you've just created
!foo:
Run the previous command starting with foo
!foo:p:
Print the previous command starting with foo
!!:s/foo/bar:
Substitute foo with bar within the previous command
^foo^bar:
Same as above, runs the previous command replacing foo with bar
!comm:s/foo/bar :
This will search for commands starting with comm, replace foo with bar and execute the command. Can be appended with :p to print out the command before running
!n:
Will run command n in the history, replace with whatever number you want from the output of the history command. !1 will run the first command. !-1 will run the previous command, same as !!
$_:
Variable for the last argument in the previous command.
$():
Will run whatever is in the () as a subshell and return the result before running the rest of the command
Zurück zur Übersicht