Sometimes I have to run a command many times in a row, for example, to see if the service is running, and it becomes tedious to move my hands away from the usual input position, to repeatedly press the Up and Enter keys. Is there a way to run the previous command without the Up and Enter keys, perhaps using a complex shell script?
I tried the following, but this is unsatisfactory because it cannot perform aliases and it is a bit slower.
history | tail -2 | head -1 | cut -d' ' -f4- | cat > prev_command.txt
sleep .01
chmod 777 prev_command.txt
eval prev_command.txt
rm prev_command.txt
Ideally, I will have an alias for this script, so I can type something like "prev" on the command line and press Enter to run the previous command again.
source
share