Last Updated: February 25, 2016
·
832
· searsaw

Stop Typing in Long Commands in Linux!

Ever typed in a long command in Linux and then wanted to use it again? However, it was an hour ago when you used it and pressing up through tons of commands would be pointless. Instead of doing that, lets just look at our history!

Type in the following into your prompt:

history

This will show you all the commands you have typed in. When I do it on my machine currently, it shows me the past 500+ commands. Next to each command is a number. That is the number of that command. Just type in the number of that command with a ! before it, and Linux will run that command after you press [Enter]. For example:

!534

This will run a phpunit --testsuite Models on my machine right now. Pretty cool, huh!

To make it even easier to use, pipe the history command into grep to narrow down your results, like so:

history | grep phpunit

Now I will only see the phpunit commands I have run. Thanks, Linux!

1 Response
Add your response

Ctrl + R.

over 1 year ago ·