<html lang="en"> <head> <title>Commands For History - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Command-Line-Editing.html#Command-Line-Editing" title="Command Line Editing"> <link rel="prev" href="Commands-For-Completion.html#Commands-For-Completion" title="Commands For Completion"> <link rel="next" href="Customizing-readline.html#Customizing-readline" title="Customizing readline"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="Commands-For-History"></a> <p> Next: <a rel="next" accesskey="n" href="Customizing-readline.html#Customizing-readline">Customizing readline</a>, Previous: <a rel="previous" accesskey="p" href="Commands-For-Completion.html#Commands-For-Completion">Commands For Completion</a>, Up: <a rel="up" accesskey="u" href="Command-Line-Editing.html#Command-Line-Editing">Command Line Editing</a> <hr> </div> <h4 class="subsection">2.4.5 Commands For Manipulating The History</h4> <p><a name="index-command-history-129"></a><a name="index-input-history-130"></a><a name="index-history-of-commands-131"></a> Octave normally keeps track of the commands you type so that you can recall previous commands to edit or execute them again. When you exit Octave, the most recent commands you have typed, up to the number specified by the variable <code>history_size</code>, are saved in a file. When Octave starts, it loads an initial list of commands from the file named by the variable <code>history_file</code>. <p>Here are the commands for simple browsing and searching the history list. <dl> <dt><kbd><LFD></kbd><dt><kbd><RET></kbd><dd>Accept the current line regardless of where the cursor is. If the line is non-empty, add it to the history list. If the line was a history line, then restore the history line to its original state. <br><dt><kbd>C-p</kbd><dd>Move `up' through the history list. <br><dt><kbd>C-n</kbd><dd>Move `down' through the history list. <br><dt><kbd>M-<</kbd><dd>Move to the first line in the history. <br><dt><kbd>M-></kbd><dd>Move to the end of the input history, i.e., the line you are entering! <br><dt><kbd>C-r</kbd><dd>Search backward starting at the current line and moving `up' through the history as necessary. This is an incremental search. <br><dt><kbd>C-s</kbd><dd>Search forward starting at the current line and moving `down' through the history as necessary. </dl> <p>On most terminals, you can also use the up and down arrow keys in place of <kbd>C-p</kbd> and <kbd>C-n</kbd> to move through the history list. <p>In addition to the keyboard commands for moving through the history list, Octave provides three functions for viewing, editing, and re-running chunks of commands from the history list. <!-- history src/oct-hist.cc --> <p><a name="doc_002dhistory"></a> <div class="defun"> — Command: <b>history</b><var> options<a name="index-history-132"></a></var><br> <blockquote><p>If invoked with no arguments, <code>history</code> displays a list of commands that you have executed. Valid options are: <dl> <dt><code>-w </code><var>file</var><dd>Write the current history to the file <var>file</var>. If the name is omitted, use the default history file (normally <samp><span class="file">~/.octave_hist</span></samp>). <br><dt><code>-r </code><var>file</var><dd>Read the file <var>file</var>, appending its contents to the current history list. If the name is omitted, use the default history file (normally <samp><span class="file">~/.octave_hist</span></samp>). <br><dt><var>n</var><dd>Display only the most recent <var>n</var> lines of history. <br><dt><code>-q</code><dd>Don't number the displayed lines of history. This is useful for cutting and pasting commands using the X Window System. </dl> <p>For example, to display the five most recent commands that you have typed without displaying line numbers, use the command <kbd>history -q 5</kbd>. </p></blockquote></div> <!-- edit_history src/oct-hist.cc --> <p><a name="doc_002dedit_005fhistory"></a> <div class="defun"> — Command: <b>edit_history</b> [<var>first</var>] [<var>last</var>]<var><a name="index-edit_005fhistory-133"></a></var><br> <blockquote><p>If invoked with no arguments, <code>edit_history</code> allows you to edit the history list using the editor named by the variable <samp><span class="env">EDITOR</span></samp><!-- /@w -->. The commands to be edited are first copied to a temporary file. When you exit the editor, Octave executes the commands that remain in the file. It is often more convenient to use <code>edit_history</code> to define functions rather than attempting to enter them directly on the command line. By default, the block of commands is executed as soon as you exit the editor. To avoid executing any commands, simply delete all the lines from the buffer before exiting the editor. <p>The <code>edit_history</code> command takes two optional arguments specifying the history numbers of first and last commands to edit. For example, the command <pre class="example"> edit_history 13 </pre> <p class="noindent">extracts all the commands from the 13th through the last in the history list. The command <pre class="example"> edit_history 13 169 </pre> <p class="noindent">only extracts commands 13 through 169. Specifying a larger number for the first command than the last command reverses the list of commands before placing them in the buffer to be edited. If both arguments are omitted, the previous command in the history list is used. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002drun_005fhistory.html#doc_002drun_005fhistory">run_history</a>. </p></blockquote></div> <!-- run_history src/oct-hist.cc --> <p><a name="doc_002drun_005fhistory"></a> <div class="defun"> — Command: <b>run_history</b> [<var>first</var>] [<var>last</var>]<var><a name="index-run_005fhistory-134"></a></var><br> <blockquote><p>Similar to <code>edit_history</code>, except that the editor is not invoked, and the commands are simply executed as they appear in the history list. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dedit_005fhistory.html#doc_002dedit_005fhistory">edit_history</a>. </p></blockquote></div> <p class="noindent">Octave also allows you customize the details of when, where, and how history is saved. <!-- saving_history src/oct-hist.cc --> <p><a name="doc_002dsaving_005fhistory"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>saving_history</b> ()<var><a name="index-saving_005fhistory-135"></a></var><br> — Built-in Function: <var>old_val</var> = <b>saving_history</b> (<var>new_val</var>)<var><a name="index-saving_005fhistory-136"></a></var><br> — Built-in Function: <b>saving_history</b> (<var>new_val, "local"</var>)<var><a name="index-saving_005fhistory-137"></a></var><br> <blockquote><p>Query or set the internal variable that controls whether commands entered on the command line are saved in the history file. <p>When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dhistory_005fcontrol.html#doc_002dhistory_005fcontrol">history_control</a>, <a href="doc_002dhistory_005ffile.html#doc_002dhistory_005ffile">history_file</a>, <a href="doc_002dhistory_005fsize.html#doc_002dhistory_005fsize">history_size</a>, <a href="doc_002dhistory_005ftimestamp_005fformat_005fstring.html#doc_002dhistory_005ftimestamp_005fformat_005fstring">history_timestamp_format_string</a>. </p></blockquote></div> <!-- history_control src/oct-hist.cc --> <p><a name="doc_002dhistory_005fcontrol"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>history_control</b> ()<var><a name="index-history_005fcontrol-138"></a></var><br> — Built-in Function: <var>old_val</var> = <b>history_control</b> (<var>new_val</var>)<var><a name="index-history_005fcontrol-139"></a></var><br> <blockquote><p>Query or set the internal variable that specifies how commands are saved to the history list. The default value is an empty character string, but may be overridden by the environment variable <samp><span class="env">OCTAVE_HISTCONTROL</span></samp><!-- /@w -->. <p>The value of <code>history_control</code> is a colon-separated list of values controlling how commands are saved on the history list. If the list of values includes <code>ignorespace</code>, lines which begin with a space character are not saved in the history list. A value of <code>ignoredups</code> causes lines matching the previous history entry to not be saved. A value of <code>ignoreboth</code> is shorthand for <code>ignorespace</code> and <code>ignoredups</code>. A value of <code>erasedups</code> causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored. If <code>history_control</code> is the empty string, all commands are saved on the history list, subject to the value of <code>saving_history</code>. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dhistory_005ffile.html#doc_002dhistory_005ffile">history_file</a>, <a href="doc_002dhistory_005fsize.html#doc_002dhistory_005fsize">history_size</a>, <a href="doc_002dhistory_005ftimestamp_005fformat_005fstring.html#doc_002dhistory_005ftimestamp_005fformat_005fstring">history_timestamp_format_string</a>, <a href="doc_002dsaving_005fhistory.html#doc_002dsaving_005fhistory">saving_history</a>. </p></blockquote></div> <!-- history_file src/oct-hist.cc --> <p><a name="doc_002dhistory_005ffile"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>history_file</b> ()<var><a name="index-history_005ffile-140"></a></var><br> — Built-in Function: <var>old_val</var> = <b>history_file</b> (<var>new_val</var>)<var><a name="index-history_005ffile-141"></a></var><br> <blockquote><p>Query or set the internal variable that specifies the name of the file used to store command history. The default value is <samp><span class="file">~/.octave_hist</span></samp>, but may be overridden by the environment variable <samp><span class="env">OCTAVE_HISTFILE</span></samp><!-- /@w -->. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dhistory_005fsize.html#doc_002dhistory_005fsize">history_size</a>, <a href="doc_002dsaving_005fhistory.html#doc_002dsaving_005fhistory">saving_history</a>, <a href="doc_002dhistory_005ftimestamp_005fformat_005fstring.html#doc_002dhistory_005ftimestamp_005fformat_005fstring">history_timestamp_format_string</a>. </p></blockquote></div> <!-- history_size src/oct-hist.cc --> <p><a name="doc_002dhistory_005fsize"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>history_size</b> ()<var><a name="index-history_005fsize-142"></a></var><br> — Built-in Function: <var>old_val</var> = <b>history_size</b> (<var>new_val</var>)<var><a name="index-history_005fsize-143"></a></var><br> <blockquote><p>Query or set the internal variable that specifies how many entries to store in the history file. The default value is <code>1024</code>, but may be overridden by the environment variable <samp><span class="env">OCTAVE_HISTSIZE</span></samp><!-- /@w -->. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dhistory_005ffile.html#doc_002dhistory_005ffile">history_file</a>, <a href="doc_002dhistory_005ftimestamp_005fformat_005fstring.html#doc_002dhistory_005ftimestamp_005fformat_005fstring">history_timestamp_format_string</a>, <a href="doc_002dsaving_005fhistory.html#doc_002dsaving_005fhistory">saving_history</a>. </p></blockquote></div> <!-- history_timestamp_format_string src/oct-hist.cc --> <p><a name="doc_002dhistory_005ftimestamp_005fformat_005fstring"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>history_timestamp_format_string</b> ()<var><a name="index-history_005ftimestamp_005fformat_005fstring-144"></a></var><br> — Built-in Function: <var>old_val</var> = <b>history_timestamp_format_string</b> (<var>new_val</var>)<var><a name="index-history_005ftimestamp_005fformat_005fstring-145"></a></var><br> — Built-in Function: <b>history_timestamp_format_string</b> (<var>new_val, "local"</var>)<var><a name="index-history_005ftimestamp_005fformat_005fstring-146"></a></var><br> <blockquote><p>Query or set the internal variable that specifies the format string for the comment line that is written to the history file when Octave exits. The format string is passed to <code>strftime</code>. The default value is <pre class="example"> "# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@HOST>" </pre> <p>When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrftime.html#doc_002dstrftime">strftime</a>, <a href="doc_002dhistory_005ffile.html#doc_002dhistory_005ffile">history_file</a>, <a href="doc_002dhistory_005fsize.html#doc_002dhistory_005fsize">history_size</a>, <a href="doc_002dsaving_005fhistory.html#doc_002dsaving_005fhistory">saving_history</a>. </p></blockquote></div> <!-- EDITOR src/defaults.cc --> <p><a name="doc_002dEDITOR"></a> <div class="defun"> — Built-in Function: <var>val</var> = <b>EDITOR</b> ()<var><a name="index-EDITOR-147"></a></var><br> — Built-in Function: <var>old_val</var> = <b>EDITOR</b> (<var>new_val</var>)<var><a name="index-EDITOR-148"></a></var><br> — Built-in Function: <b>EDITOR</b> (<var>new_val, "local"</var>)<var><a name="index-EDITOR-149"></a></var><br> <blockquote><p>Query or set the internal variable that specifies the editor to use with the <code>edit_history</code> command. The default value is taken from the environment variable <samp><span class="env">EDITOR</span></samp><!-- /@w --> when Octave starts. If the environment variable is not initialized, <samp><span class="env">EDITOR</span></samp><!-- /@w --> will be set to <code>"emacs"</code>. <p>When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dedit_005fhistory.html#doc_002dedit_005fhistory">edit_history</a>. </p></blockquote></div> </body></html>