Logo

dev-resources.site

for different kinds of informations.

Bash and exclamation marks !!!!

Published at
8/18/2022
Categories
bash
cheatsheet
terminal
shortcut
Author
sanixdarker
Categories
4 categories in total
bash
open
cheatsheet
open
terminal
open
shortcut
open
Author
11 person written this
sanixdarker
open
Bash and exclamation marks !!!!

In case you didn't know, exclamation marks play an important role in the bash workflow, especially for your command history!

Example

ok... let me explain this weird thing, actually it's simple :

  • The first part of the command will take the first command item from the second most recent command you wrote, then concatenate to "add" and the second item of the most recent command, git add second_folder.

  • For the second part, it's a substitution command of "status" by "checkout" for the second command that i wrote, in reverse order on my bash history; it will take as arguments, those that i gave to my second command in the same order.
    That said, the output of this command will be:
    git checkout second_folder

Pretty NEAT right !?

So let's talk about it, the ! invokes history expansion, a feature that originally appeared in the C shell, back in the days before you could count on terminals to have arrow keys. It's especially useful if you add the current command number to the prompt (PS1="\!$ ") so you can quickly look at your screen to get numbers for past commands.

So, am not going to go deep inside possibilities here but just give some cool cheat-sheets from exclamations marks when you're on your terminal !

This is a pretty short list of the cool ones :

  • !! run the latest command,

     # Ex :
     $ apt-get update
     $ sudo !!
    
  • !-3 run the third command in the reverse order from my bash history; this is also available for positive values such as the first command, from your ~/.bash_history -> !1

  • !* get arguments passed to the most recent command ran,

     # Ex :
     $ touch filex, test4, example
     $ chmod 777 !*
    
  • !ls to run a command from your history starting with ls

With these 4 items, you can basically play/mix around with your bash history and get great stuffs like the one up there with a substitution string.

Thanks for reading, feel free to like and/or subscribe for more 🐼.

shortcut Article's
30 articles in total
Favicon
How to Fetch URL Content, Set It into a Dictionary, and Extract Specific Keys in iOS Shortcuts
Favicon
How to Post Articles to Dev.to Using iOS Shortcuts
Favicon
Create a Shortcut to Post Markdown Files to GitHub
Favicon
How to Save and Open PDFs in Files App with Shortcuts: Specify Path and Filename for Better Access
Favicon
πŸš€ Meet IntelliText: The Power Tool for Text Automation You Didn’t Know You Needed
Favicon
Essential Shortcuts for Linux Terminal 2024 πŸ’₯
Favicon
iOS 18 - Using ChatGPT powered TapAI shortcut with Apple Notes, Reminders & Calendar for automation
Favicon
Setting App Time Limits on iOS Using Shortcuts
Favicon
Arc Shortcuts: Windows
Favicon
Visual code extension to copy multiple values
Favicon
Easy Guide to Becoming a Software Developer in 2024
Favicon
VSCode productive shortcut keys
Favicon
Sublime Text Shortcut Keys – Boost Productivity with Key Phrases
Favicon
Apple Notes Monostyle Text Keyboard Shortcut
Favicon
How Do I Permanently Remove a Shortcut Virus from My USB?
Favicon
Mastering Windows Shortcuts: Boosting Productivity and Efficiency
Favicon
Create a desktop entry for postman in ubuntu
Favicon
Windows Shortcut ::
Favicon
How to duplicate a browser tab
Favicon
5 Shortcuts to make tab navigation easier on your browser
Favicon
Custom Alias / Shortcut in macΒ Terminal
Favicon
Bash and exclamation marks !!!!
Favicon
Keyboard Shortcut: Emoji πŸ˜‰
Favicon
35 atalhos customizados VS Code para aumentar sua produtividade
Favicon
15+ Command Line Hot Keys You Didn't Know About
Favicon
Shortcut to shut down Mac
Favicon
Shortcut keys to shut down Mac (MacBook Pro, Mini ...)
Favicon
set up keyboard shortcut to open terminal on mac
Favicon
How to implement a search shortcut (OpenSearch) on any website
Favicon
10 Practical shortcuts to be faster !

Featured ones: