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 2018-10-10 18:26:54.

Contact us

For help or to comment, email the UITS Support Center.