Command History and Recall

Each time you execute a command, the entire command line is saved in a command history list. You can display the saved commands, search the list, modify commands, and rerun commands. The command history is available at the command prompt and in a special command history window. You can choose to use either a local or global command history.


If you need additional history information (time stamp, return code, run time, and the current working directory when the command was executed, see Extended Command History.


Command History Keys:




Recall the previous (or most recent) command, or the most recent command that matches a partial command line.



Recall the next (or oldest) command, or the oldest command that matches a partial command line.


Display a popup window of the command history (or all entries matching a partial command line).


Fill in the rest of the command line from the previous command, beginning at the current cursor position.


Delete the currently displayed history list entry, erase the command line, and display the previous (matching) history list entry.


Display the last entry in the history list.


Save the current command line in the history list without executing it, and then clear the command line.


Copy the current command line to the end of the history list even if it has not been altered, then execute it.


As the first character in a line:  Do not save the current line in the history list when it is executed, nor store it in the CMDLINE environment variable.


Note: The keystrokes shown above are the default values. See Key Mapping Directives for details on how to assign different keystrokes.


The simplest use of the command history list is to repeat a command exactly. For example, you might enter the command


dir a:*.wks;*.doc


to see some of the files on drive A. You might move some new files to drive A and then want to repeat the DIR command. Just press Up repeatedly to scan back through the history list. When the DIR command appears, press Enter to execute it again. You can also view the command history in a window.


After you have found a command, you can edit it before pressing Enter. You will appreciate this feature when you have to execute a series of commands that differ only slightly from each other. You can also view and manage the command history list with the HISTORY command.


The history list is normally "circular". If you move to the latest command in the list and then press Up once more, you'll see the oldest command in the list. Similarly, if you move to the first command in the list and then press Up once more, you'll see the last command in the list. You can disable this feature and make command history recall stop at the beginning or end of the list by turning off History Wrap on the "History" tab of the configuration dialog.


You can search the command history list to find a previous command quickly using command completion. Just enter the first few characters of the command you want to find and press Up. You only need to enter enough characters to identify the command that you want to find. For example, to find a DIR command, enter DI and then press Up. If you press Up a second time, you will see the previous command that matches. The system will beep if there are no matching commands. The search process stops as soon as you type one of the editing keys, whether or not the line is changed. At that point, the line you're viewing becomes the new line to match if you press Up again.


The command history search supports wildcards. For example, you can search for a previous command that contained the string foo by typing *foo* on the command line and pressing the up or down keys.


You can specify the size of the command history list on the Command Line tab of the configuration dialog. When the list is full, the oldest commands are discarded to make room for new ones. You can also use the Minimum Length option to enable or disable history saves and to specify the shortest command line that will be saved.


You can prevent any command line from being saved in the history by beginning it with an at sign (@) or by including it in the contents of the HistoryExclude variable.


When you execute a command from the history, that command remains in the history list in its original position. The command is not copied to the end of the list (unless you modify it). If you want each command to be copied or moved to the end of the list when it is reexecuted, select Copy to End or Move to End on the "History" tab of the configuration dialogs. If you select either of these options, the list entry identified as "current" (the entry from which commands are retrieved when you press Ctrl-Up) is also adjusted to refer to the end of the history list after each recalled command is executed.


Use F3 when your new command is different from your previous one by just a character or two at the beginning. For example, suppose you want to execute a DIR on several file names then use DEL to delete those same files. After the DIR is complete type DEL and press F3; the rest of the command line will be completed for you. Check that it's correct, and then press Enter to delete the files. F3 also retrieves the entire previous command (like Up) if nothing has been typed on the line.


Use Ctrl-E to "get your bearings" by returning to the end of the list if you've scrolled around so much that you aren't sure where you are any more.


Use Ctrl-K to save some work when you've typed a long command and then realize that you weren't quite ready. For example, if you forget to change directories and notice it after a command is typed or mostly typed, but before you press Enter, just press Ctrl-K to save the command without executing it. Use the CD or CDD command to change to the right directory, press Up twice to retrieve the command you saved, make any final changes to it, and press Enter to execute it.


Use Ctrl-Enter to organize the history list for repetitive tasks. Instead of searching through the command history for the next command in a sequence, you can place all of the necessary commands next to each other and make them easier to repeat.