Q: I am using an old Dell laptop running Linux that my Dad gave me and the arrow keys do not work.  Is there a way to execute the last command I ran since I can’t use the up arrow.  Also is there a way to scroll through my history without the up arrow?

A: Yes, as with anything Linux there are multiple ways of doing it.  Let’s explore a couple and talk about their downsides.

First and most simple is using the double bang (exclamation point). This will execute your last command instantly.

!!

The one major flaw with this is it will execute the command without letting you read it, which is different from the way scrolling up with the arrow would work.

To get the same effect as using the up arrow once, which is showing the last command run without executing it, you can use CTRL+P.

Another option you have is using the history a little better.  You can run the following to run your last command:

!-1

Or change the number, and run any of your last commands.  For example changing the 1 to a 2 will run the second from last command.

[[email protected] ~]$ cat /etc/redhat-release
Fedora release 25 (Twenty Five)
[[email protected] ~]$ echo "ANOTHER COMMAND"
ANOTHER COMMAND
[[email protected] ~]$ !-2
cat /etc/redhat-release
Fedora release 25 (Twenty Five)
[[email protected] ~]$

Another option you have is to list out the history, then running the number of the command you want, like so:

[[email protected] ~]$ history
1  cat /etc/redhat-release
2  echo “ANOTHER COMMAND”
3  echo “Putorius is Curious”
4  uname -r
5  date
6  history
[[email protected] ~]$ !4
uname -r
4.13.10-100.fc25.x86_64

This is all made possible by using bash history. To learn more read our “Basics of Bash History” tutorial.