Bash Reissue And Repeat A Long Command Without Retyping It on a Linux, macOS & Unix

In Bash on Linux, macOS, and Unix, you can reissue and repeat a long command without retyping it by using the following methods:

  1. Using the up arrow key: Press the up arrow key to recall the previous command. You can scroll through previous commands using the up and down arrow keys. Once you have found the command you want to repeat, press Enter to reissue it.
  2. Using the “history” command: The “history” command shows a list of previous commands. You can find the command you want to repeat, and then type an exclamation point (!) followed by the command number:
    !<command_number>

    For example, if you want to repeat the fifth command in your history, you can type:

    !5
  3. Using the “!” followed by a command string: You can use the exclamation point (!) followed by a command string to repeat the most recent command that starts with that string. For example, if you want to repeat the most recent command that starts with “ls”, you can type:
    !ls

By using any of these methods, you can easily reissue and repeat a long command without retyping it.

Leave a Comment