DEV Community

Discussion on: 5 Handy Bash Tricks in 2 Minutes

Collapse
 
zeddotes profile image
zeddotes • Edited

To piggyback on the last one there, if you history:

$ history

the output should be a numerical list of commands you've entered in the past, like so:

10016  git status
10017  git commit
10018  git push origin master

If I wanted to run git status again (ie, repeat command 10016 from history), I could do something like this:

$ !10016

Collapse
 
jacobherrington profile image
Jacob Herrington (he/him)

That's a great trick! Thanks!

Collapse
 
zeddotes profile image
zeddotes • Edited

You could also pipe history too! Which could allow you to grep (and more) within your history:

$ history | grep "status"

10005  git status
10008  git status
10011  git status
10014  git status
10016  git status

:)

Thread Thread
 
ianturton profile image
Ian Turton

ctrl-r status will walk back up your history looking at each time the command line contained status - just hit return when you find the command you need.