Manoj Rao bio photo

Manoj Rao

Your Average Common Man

Email Twitter Github

layout: post title: “Bash - Productivity Tricks/Hacks” excerpt: “Bash” tags: [Bash, Linux, Terminal, Console] comments: false – In earlier posts, I have shared my productivity tricks with Emacs and Git. In this post, I will share some of the commonly used shell tricks that have helped me be/stay productive.

Command History

Search for a previously run command

history | grep <pattern>

OR

Ctrl-R <pattern>

Repeat Last Command

Repeating the most recent command

UP arrow then ENTER

OR

!!

Repeat Last Command Starting With …

!<starting pattern>

Reopen the last file with vim that contains a long filename which you can’t remember

!v

If you want to be sure that the last command starting with v is indeed vim and not vscode (Ugh) then you can examine to make sure the last command was OK.

!v:p

Repeat the Last Command With New Arguments

ls foo
ls bar

OR

ls foo
!!:0 bar

Repeat Last Arguments With New Command

vim /tmp/foo.txt
emacs /tmp/foo.txt

OR

vim /tmp/foo.txt
^vim^emacs

Hold Result Of Command

find . -name "blahblah.txt"
# found in here/there/everywhere/blahblah.txt
rm here/there/everywhere/blahblah.txt

OR

rm `find . -name "blahblah.txt"`

# same as

rm $(find . -name "blahblah.txt")

Bring Your Own Cause

If you think any info here has remotely helped you consider dropping a penny for this cause, just click me . You can visit https://www.bbc.com/news/world-asia-india-52672764 Unfortunately, there are plenty of sad things happening all over the world, if you have a different cause or charity you'd rather support please do. And if you did make a donation, please drop a note to me (annotated) or leave a comment here (anonymous is OK!) and I will use that as motivation to write more useful content here.

If you like topics such as this then please consider subscribing to my podcast. I talk to some of the stalwarts in tech and ask them what their favorite productivity hacks are:

Available on iTunes Podcast

Visit Void Star Podcast’s page on iTunes Podcast Portal. Please Click ‘Subscribe’, leave a comment.

Get it iTunes