How to repeat the last command in Linux without using the arrow keys: Well sometimes you want to repeat the previous command on the command line when working with Linux systems and that too without using arrow keys then there is no particular way to do that but here at troubleshooter we have listed all the various ways to do exactly this.
To repeat commands you can normally use the old csh! history operator “!!” (without quotes) for the most recent command, if you want to just repeat the prior command then you can use !-2, !foo for the most recent starting with the subsrting “foo.” You can also use the fc command or just use :p to print the history operator suggestion.
How to repeat the last command in Linux without using the arrow keys
Let’s see some of the ways to recall commands at the shell prompt:
Method 1: For csh or any shell implementing csh-like history substitution
!! Then press Enter OR !-1 Then press Enter Or Ctrl+P then press Enter
Note: !! or !-1 will not auto expand for you and until you execute them it might be too late.
If using bash, you can put bind space:magic-space into ~/.bashrc then after the command press space will auto expand them inline.
Method 2: Use Emacs key bindings
Most shells that have a command line edition feature that supports Emacs key bindings:
Up Ctrl+P Down Ctrl+N Left Ctrl+B Right Ctrl+F Home Ctrl+A End Ctrl+E Delete Ctrl+D
Also Read: Fix Bash Syntax Error Near Unexpected Token
Method 3: Use CTRL + P then CTRL + O
Pressing CTRL + P will let you switch to the last command and pressing CTRL + O will let you execute the current line. Note: CTRL + O can be used as many times as you want.
Method 3: Using the fc command
fc -e : -1 For example: $ echo "Troubleshooter" Troubleshooter $ fc -e : -1 echo "Troubleshooter" Troubleshooter
Also read, How to Restore files from lost+found
Method 4: Use !<beginning of command>
For csh or any shell implementing csh-like history substituion (tcsh, bash, zsh), you can use the !<beginning of command> to call the last command beginning with <beginning of command>
For example: $ tail example.txt $ less file.txt $ !ta !ta would execute tail example.txt
Method 5: In case of using MAC you can the key
You can bind ?+R to 0x0C 0x10 0x0d. This will clear the terminal and run the last command.
That’s it you have successfully learned How to repeat the last command in Linux without using the arrow keys but if you still have any questions regarding this post feel free to ask them in the comment’s section.