In Unix, how can I reissue a long command without retyping it?

In Unix, you can use the history command to view a list of the commands that can be reissued. At the shell prompt, enter:

 history

You will then see a list of previous commands that you have entered. For example, you may see something like the following:

 1 trn 2 mailx -s "Here's the Usenet file" jjones@foo.com < ucs.news 3 lynx 4 mv myfile.txt newfile.txt 5 trn 6 history

To reissue a command in csh, tcsh, or bash, enter ! (the exclamation point) followed by the number of the command you would like to repeat. For example, if you would like to reissue command number 2, you would enter:

 !2

If you are using ksh, enter r followed by a space and the number of the command you would like to repeat. For example, if you would like to reissue command number 2, you would enter:

 r 2

Either of the above methods will work in zsh.

If you are using bash or tcsh, you may be able to scroll through the command history simply by using the up and down arrow keys at the shell prompt. Once you have found the command that you would like to reissue, press Enter to execute it.

For more information, read the man page for your shell.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document abdj in the Knowledge Base.
Last modified on 2017-05-16 11:51:33.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.