summaryrefslogtreecommitdiff
path: root/devdocs/bash/bash-history-builtins.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/bash/bash-history-builtins.html
new repository
Diffstat (limited to 'devdocs/bash/bash-history-builtins.html')
-rw-r--r--devdocs/bash/bash-history-builtins.html27
1 files changed, 27 insertions, 0 deletions
diff --git a/devdocs/bash/bash-history-builtins.html b/devdocs/bash/bash-history-builtins.html
new file mode 100644
index 00000000..df5a5261
--- /dev/null
+++ b/devdocs/bash/bash-history-builtins.html
@@ -0,0 +1,27 @@
+<h1 class="section">Bash History Builtins</h1> <p>Bash provides two builtin commands which manipulate the history list and history file. </p> <dl compact> <dt id="index-fc"><span><code>fc</code></span></dt> <dd>
+<div class="example"> <pre class="example">fc [-e ename] [-lnr] [first] [last]
+fc -s [pat=rep] [command]
+</pre>
+</div> <p>The first form selects a range of commands from <var>first</var> to <var>last</var> from the history list and displays or edits and re-executes them. Both <var>first</var> and <var>last</var> may be specified as a string (to locate the most recent command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the current command number). </p> <p>When listing, a <var>first</var> or <var>last</var> of 0 is equivalent to -1 and -0 is equivalent to the current command (usually the <code>fc</code> command); otherwise 0 is equivalent to -1 and -0 is invalid. </p> <p>If <var>last</var> is not specified, it is set to <var>first</var>. If <var>first</var> is not specified, it is set to the previous command for editing and -16 for listing. If the <samp>-l</samp> flag is given, the commands are listed on standard output. The <samp>-n</samp> flag suppresses the command numbers when listing. The <samp>-r</samp> flag reverses the order of the listing. Otherwise, the editor given by <var>ename</var> is invoked on a file containing those commands. If <var>ename</var> is not given, the value of the following variable expansion is used: <code>${FCEDIT:-${EDITOR:-vi}}</code>. This says to use the value of the <code>FCEDIT</code> variable if set, or the value of the <code>EDITOR</code> variable if that is set, or <code>vi</code> if neither is set. When editing is complete, the edited commands are echoed and executed. </p> <p>In the second form, <var>command</var> is re-executed after each instance of <var>pat</var> in the selected command is replaced by <var>rep</var>. <var>command</var> is interpreted the same as <var>first</var> above. </p> <p>A useful alias to use with the <code>fc</code> command is <code>r='fc -s'</code>, so that typing ‘<samp>r cc</samp>’ runs the last command beginning with <code>cc</code> and typing ‘<samp>r</samp>’ re-executes the last command (see <a href="aliases">Aliases</a>). </p> </dd> <dt id="index-history"><span><code>history</code></span></dt> <dd>
+<div class="example"> <pre class="example">history [n]
+history -c
+history -d offset
+history -d start-end
+history [-anrw] [filename]
+history -ps arg
+</pre>
+</div> <p>With no options, display the history list with line numbers. Lines prefixed with a ‘<samp>*</samp>’ have been modified. An argument of <var>n</var> lists only the last <var>n</var> lines. If the shell variable <code>HISTTIMEFORMAT</code> is set and not null, it is used as a format string for <var>strftime</var> to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line. </p> <p>Options, if supplied, have the following meanings: </p> <dl compact> <dt><span><code>-c</code></span></dt> <dd>
+<p>Clear the history list. This may be combined with the other options to replace the history list completely. </p> </dd> <dt><span><code>-d <var>offset</var></code></span></dt> <dd>
+<p>Delete the history entry at position <var>offset</var>. If <var>offset</var> is positive, it should be specified as it appears when the history is displayed. If <var>offset</var> is negative, it is interpreted as relative to one greater than the last history position, so negative indices count back from the end of the history, and an index of ‘<samp>-1</samp>’ refers to the current <code>history -d</code> command. </p> </dd> <dt><span><code>-d <var>start</var>-<var>end</var></code></span></dt> <dd>
+<p>Delete the range of history entries between positions <var>start</var> and <var>end</var>, inclusive. Positive and negative values for <var>start</var> and <var>end</var> are interpreted as described above. </p> </dd> <dt><span><code>-a</code></span></dt> <dd>
+<p>Append the new history lines to the history file. These are history lines entered since the beginning of the current Bash session, but not already appended to the history file. </p> </dd> <dt><span><code>-n</code></span></dt> <dd>
+<p>Append the history lines not already read from the history file to the current history list. These are lines appended to the history file since the beginning of the current Bash session. </p> </dd> <dt><span><code>-r</code></span></dt> <dd>
+<p>Read the history file and append its contents to the history list. </p> </dd> <dt><span><code>-w</code></span></dt> <dd>
+<p>Write out the current history list to the history file. </p> </dd> <dt><span><code>-p</code></span></dt> <dd>
+<p>Perform history substitution on the <var>arg</var>s and display the result on the standard output, without storing the results in the history list. </p> </dd> <dt><span><code>-s</code></span></dt> <dd>
+<p>The <var>arg</var>s are added to the end of the history list as a single entry. </p> </dd> </dl> <p>If a <var>filename</var> argument is supplied when any of the <samp>-w</samp>, <samp>-r</samp>, <samp>-a</samp>, or <samp>-n</samp> options is used, Bash uses <var>filename</var> as the history file. If not, then the value of the <code>HISTFILE</code> variable is used. </p> <p>The return value is 0 unless an invalid option is encountered, an error occurs while reading or writing the history file, an invalid <var>offset</var> or range is supplied as an argument to <samp>-d</samp>, or the history expansion supplied as an argument to <samp>-p</samp> fails. </p> </dd> </dl><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br>
+ <a href="https://www.gnu.org/software/bash/manual/html_node/Bash-History-Builtins.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Bash-History-Builtins.html</a>
+ </p>
+</div>