The general syntax to use is as follows:
!!:gs/old/new
!! runs the last command again, while :gs/old/new replaces instances of the text “old” with “new” within the last command.
For example, here’s a simple change directory command with an error in the path:
cd /System/Library/CoerServices/Dock.app/Contents/
Notice “CoerServices” should be “CoreServices”, but rather than type out the entire command and path again, you can enter the following:
!!:gs/Coer/Core/
And suddenly you’re in the proper directory.
This is obviously extremely useful when you’ve discovered errors floating in command line syntax somewhere, but it’s also perfect for toggling settings on and off through things like defaults write commands by replacing “no” with “yes” and so forth:
!!:gs/no/yes
You can also place sudo in front of !! to run the previous command as root.
Post a Comment