Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 1.1 KB

bash-bang.md

File metadata and controls

28 lines (19 loc) · 1.1 KB

Bash Bang Commands

To save retyping a command, Bash's Bang(!) commands allow us to re-run all or part of the previous command.

Run Last

Enter !! to repeat the last command. !cmd will also repeat the last command beginning with cmd.

Print Bang

You can also print the resulting bang command before you run it by appending :p to the end of your bang.

Repeat from History

history will give you a historical list of all the commands in the current buffer with a numerical identifier. Use !<command-number> to rerun a particular command from history.

Glossary

Here's a list of some common bang commands:

  • !:0 - the name of the previous command
  • !:1 - the first parameter of the previous command
  • !:* - all the parameters of the previous command
  • !:$ - the last parameter of the previous command
  • !! - the entire previous command

(via this StackOverflow answer)

Use Cases

Re-running with elevated access - sudo !! 😎

Create and change into directory - mkdir directory && cd $_