<html lang="en"> <head> <title>Commands For History - Untitled</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Untitled"> <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-113"></a><a name="index-input-history-114"></a><a name="index-history-of-commands-115"></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. <!-- oct-hist.cc --> <p><a name="doc_002dhistory"></a> <div class="defun"> — Command: <b>history</b><var> options<a name="index-history-116"></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>, replacing the current history list with its contents. 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> <!-- 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-117"></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 <code>EDITOR</code><!-- /@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> <!-- 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-118"></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. <!-- 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-119"></a></var><br> — Built-in Function: <var>old_val</var> = <b>saving_history</b> (<var>new_val</var>)<var><a name="index-saving_005fhistory-120"></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. <!-- 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>. </p></blockquote></div> <!-- 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-121"></a></var><br> — Built-in Function: <var>old_val</var> = <b>history_file</b> (<var>new_val</var>)<var><a name="index-history_005ffile-122"></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 <code>OCTAVE_HISTFILE</code><!-- /@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> <!-- 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-123"></a></var><br> — Built-in Function: <var>old_val</var> = <b>history_size</b> (<var>new_val</var>)<var><a name="index-history_005fsize-124"></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 <code>OCTAVE_HISTSIZE</code><!-- /@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> <!-- 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-125"></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-126"></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> <!-- 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> <!-- 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-127"></a></var><br> — Built-in Function: <var>old_val</var> = <b>EDITOR</b> (<var>new_val</var>)<var><a name="index-EDITOR-128"></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 <code>EDITOR</code><!-- /@w --> when Octave starts. If the environment variable is not initialized, <code>EDITOR</code><!-- /@w --> will be set to <code>"emacs"</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_002dedit_005fhistory.html#doc_002dedit_005fhistory">edit_history</a>. </p></blockquote></div> </body></html>