348 lines
5.6 KiB
HTML
348 lines
5.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
||
<HTML
|
||
><HEAD
|
||
><TITLE
|
||
>The command-line history</TITLE
|
||
><META
|
||
NAME="GENERATOR"
|
||
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
||
REL="HOME"
|
||
TITLE="GNU/Linux Command-Line Tools Summary"
|
||
HREF="index.html"><LINK
|
||
REL="UP"
|
||
TITLE="Shell Tips"
|
||
HREF="shell-tips.html"><LINK
|
||
REL="PREVIOUS"
|
||
TITLE="General Shell Tips"
|
||
HREF="general-shell-tips.html"><LINK
|
||
REL="NEXT"
|
||
TITLE="Other Key combinations"
|
||
HREF="other-key-combinations.html"></HEAD
|
||
><BODY
|
||
CLASS="SECT1"
|
||
BGCOLOR="#FFFFFF"
|
||
TEXT="#000000"
|
||
LINK="#0000FF"
|
||
VLINK="#840084"
|
||
ALINK="#0000FF"
|
||
><DIV
|
||
CLASS="NAVHEADER"
|
||
><TABLE
|
||
SUMMARY="Header navigation table"
|
||
WIDTH="100%"
|
||
BORDER="0"
|
||
CELLPADDING="0"
|
||
CELLSPACING="0"
|
||
><TR
|
||
><TH
|
||
COLSPAN="3"
|
||
ALIGN="center"
|
||
>GNU/Linux Command-Line Tools Summary</TH
|
||
></TR
|
||
><TR
|
||
><TD
|
||
WIDTH="10%"
|
||
ALIGN="left"
|
||
VALIGN="bottom"
|
||
><A
|
||
HREF="general-shell-tips.html"
|
||
ACCESSKEY="P"
|
||
>Prev</A
|
||
></TD
|
||
><TD
|
||
WIDTH="80%"
|
||
ALIGN="center"
|
||
VALIGN="bottom"
|
||
>Chapter 4. Shell Tips</TD
|
||
><TD
|
||
WIDTH="10%"
|
||
ALIGN="right"
|
||
VALIGN="bottom"
|
||
><A
|
||
HREF="other-key-combinations.html"
|
||
ACCESSKEY="N"
|
||
>Next</A
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><HR
|
||
ALIGN="LEFT"
|
||
WIDTH="100%"></DIV
|
||
><DIV
|
||
CLASS="SECT1"
|
||
><H1
|
||
CLASS="SECT1"
|
||
><A
|
||
NAME="THE-COMMAND-LINE-HISTORY"
|
||
></A
|
||
>4.2. The command-line history</H1
|
||
><P
|
||
></P
|
||
><DIV
|
||
CLASS="VARIABLELIST"
|
||
><DL
|
||
><DT
|
||
>Using the command history</DT
|
||
><DD
|
||
><P
|
||
>Use the up and down key's to scroll through previously typed commands. Press [Enter] to execute them or use the left and right arrow keys to edit the command first. Also see <EM
|
||
>history</EM
|
||
> (below).</P
|
||
></DD
|
||
><DT
|
||
>The history command</DT
|
||
><DD
|
||
><P
|
||
>The<EM
|
||
> history </EM
|
||
> command can be used to list Bash's log of the commands you have typed:</P
|
||
><P
|
||
>This log is called the “history”. To access it type:</P
|
||
><TABLE
|
||
BORDER="1"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="90%"
|
||
><TR
|
||
><TD
|
||
><FONT
|
||
COLOR="#000000"
|
||
><PRE
|
||
CLASS="SCREEN"
|
||
>history n</PRE
|
||
></FONT
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>This will only list the last <EM
|
||
>n</EM
|
||
> commands. Type “history” (without options) to see the the entire history list.</P
|
||
><P
|
||
>You can also type <EM
|
||
>!n</EM
|
||
> to execute command number n. Use <EM
|
||
>!!</EM
|
||
> to execute the last command you typed.</P
|
||
><P
|
||
><EM
|
||
>!-n </EM
|
||
>will execute the command n times before (in other words <EM
|
||
>!-1</EM
|
||
> is equivalent to <EM
|
||
>!!</EM
|
||
>). </P
|
||
><P
|
||
><EM
|
||
>!string </EM
|
||
>will execute the last command starting with that “string” and <EM
|
||
>!?string?</EM
|
||
> will execute the last command containing the word “string”. For example:</P
|
||
><TABLE
|
||
BORDER="1"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="90%"
|
||
><TR
|
||
><TD
|
||
><FONT
|
||
COLOR="#000000"
|
||
><PRE
|
||
CLASS="SCREEN"
|
||
>!cd</PRE
|
||
></FONT
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>Will re-run the command that you last typed starting with “cd”.</P
|
||
><P
|
||
></P
|
||
><P
|
||
><EM
|
||
>“ commandName !*”</EM
|
||
> will execute the “commandName” with any arguments you used on your last command. This maybe useful if you make a spelling mistake, for example. If you typed:</P
|
||
><TABLE
|
||
BORDER="1"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="90%"
|
||
><TR
|
||
><TD
|
||
><FONT
|
||
COLOR="#000000"
|
||
><PRE
|
||
CLASS="SCREEN"
|
||
>emasc /home/fred/mywork.java /tmp/testme.java</PRE
|
||
></FONT
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>In an attempt to execute emacs on the above two files this will obviously fail. So what you can do is type:</P
|
||
><TABLE
|
||
BORDER="1"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="90%"
|
||
><TR
|
||
><TD
|
||
><FONT
|
||
COLOR="#000000"
|
||
><PRE
|
||
CLASS="SCREEN"
|
||
>emacs !*</PRE
|
||
></FONT
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>This will execute emacs with the arguments that you last typed on the command-line. In other words this is equivalent to typing:</P
|
||
><TABLE
|
||
BORDER="1"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="90%"
|
||
><TR
|
||
><TD
|
||
><FONT
|
||
COLOR="#000000"
|
||
><PRE
|
||
CLASS="SCREEN"
|
||
>emacs /home/fred/mywork.java /tmp/testme.java</PRE
|
||
></FONT
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
></DD
|
||
><DT
|
||
>Searching through the Command History (
|
||
<B
|
||
CLASS="KEYCAP"
|
||
>CTRL</B
|
||
>-<B
|
||
CLASS="KEYCAP"
|
||
>R</B
|
||
>
|
||
|
||
)</DT
|
||
><DD
|
||
><P
|
||
>Use the CTRL-R key to perform a “reverse-i-search”. For example, if you wanted to use the command you used the last time you used <EM
|
||
>snort</EM
|
||
>, you would type:</P
|
||
><P
|
||
><B
|
||
CLASS="KEYCAP"
|
||
>CTRL</B
|
||
>-<B
|
||
CLASS="KEYCAP"
|
||
>R</B
|
||
> then type “snort”.</P
|
||
><P
|
||
>What you will see in the console window is:</P
|
||
><TABLE
|
||
BORDER="1"
|
||
BGCOLOR="#E0E0E0"
|
||
WIDTH="90%"
|
||
><TR
|
||
><TD
|
||
><FONT
|
||
COLOR="#000000"
|
||
><PRE
|
||
CLASS="SCREEN"
|
||
>(reverse-i-search)`':</PRE
|
||
></FONT
|
||
></TD
|
||
></TR
|
||
></TABLE
|
||
><P
|
||
>After you have typed what you are looking for, use the
|
||
<B
|
||
CLASS="KEYCAP"
|
||
>CTRL</B
|
||
>-<B
|
||
CLASS="KEYCAP"
|
||
>R</B
|
||
>
|
||
|
||
key combination to scroll backward through the history. </P
|
||
><P
|
||
>Use
|
||
<B
|
||
CLASS="KEYCAP"
|
||
>CTRL</B
|
||
>-<B
|
||
CLASS="KEYCAP"
|
||
>R</B
|
||
>
|
||
|
||
repeatedly to find every reference to the string you've entered. Once you've found the command you're looking for, use [Enter] to execute it. </P
|
||
><P
|
||
>Alternatively, using the right or left arrow keys will place the command on an actual command-line so you can edit it.</P
|
||
><P
|
||
></P
|
||
></DD
|
||
></DL
|
||
></DIV
|
||
></DIV
|
||
><DIV
|
||
CLASS="NAVFOOTER"
|
||
><HR
|
||
ALIGN="LEFT"
|
||
WIDTH="100%"><TABLE
|
||
SUMMARY="Footer navigation table"
|
||
WIDTH="100%"
|
||
BORDER="0"
|
||
CELLPADDING="0"
|
||
CELLSPACING="0"
|
||
><TR
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="left"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="general-shell-tips.html"
|
||
ACCESSKEY="P"
|
||
>Prev</A
|
||
></TD
|
||
><TD
|
||
WIDTH="34%"
|
||
ALIGN="center"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="index.html"
|
||
ACCESSKEY="H"
|
||
>Home</A
|
||
></TD
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="right"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="other-key-combinations.html"
|
||
ACCESSKEY="N"
|
||
>Next</A
|
||
></TD
|
||
></TR
|
||
><TR
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="left"
|
||
VALIGN="top"
|
||
>General Shell Tips</TD
|
||
><TD
|
||
WIDTH="34%"
|
||
ALIGN="center"
|
||
VALIGN="top"
|
||
><A
|
||
HREF="shell-tips.html"
|
||
ACCESSKEY="U"
|
||
>Up</A
|
||
></TD
|
||
><TD
|
||
WIDTH="33%"
|
||
ALIGN="right"
|
||
VALIGN="top"
|
||
>Other Key combinations</TD
|
||
></TR
|
||
></TABLE
|
||
></DIV
|
||
></BODY
|
||
></HTML
|
||
> |