re: Helpful Terminal Commands for Beginners! VIEW POST

FULL DISCUSSION
 

When it comes to shell history, you're doing yourself a grave injustice if all you're using is !!. Other fun ones are:

!<number>: Repeat command from your history (you can see the available command-history using fc -l (or fc -l 1 to see all the contents of your history)
!! <extra stuff>: Re-execute last command, tacking on <extra stuff> at the end of it
<extra stuff>!!: Re-execute last command, tacking on <extra stuff> at the beginning of it ...which is great if you executed something as a regular users that turns out to have needed to be run with sudo
!!:s/<SEARCH>/<REPLACE>: Re-execute last command, replacing first substring <SEARCH> with <REPLACE>
!!:s/<SEARCH>/<REPLACE>: Re-execute last command, replacing all substring <SEARCH>es with <REPLACE>es

 

I didn’t know about the search and replace functionality of !!

That is going to be extreeeemely useful for me personally haha, thank you for sharing!

 

Yeah. BASH is pretty much "take the best from KSH93 and TCSH ...plus, in recent years, a few others". So, it has a lot of features in it. Used to be, when I was tutoring junior systems administrators, all they really new about was filec. Most were astounded when I'd show them all of the wonders of BASH ...even though my preferred shell was still KSH.

Bash is kind of to shells what English is to language. =)

code of conduct - report abuse