479 lines
6.5 KiB
HTML
479 lines
6.5 KiB
HTML
<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="book1.htm"><LINK
|
|
REL="UP"
|
|
TITLE="Shell Tips"
|
|
HREF="c1195.htm"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="Shell Tips"
|
|
HREF="c1195.htm"><LINK
|
|
REL="NEXT"
|
|
TITLE="Other Key combinations"
|
|
HREF="x1877.htm"></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="c1195.htm"
|
|
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="x1877.htm"
|
|
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
|
|
>The command-line history</H1
|
|
><P
|
|
></P
|
|
><DIV
|
|
CLASS="VARIABLELIST"
|
|
><DL
|
|
><DT
|
|
>Using the command history</DT
|
|
><DD
|
|
><P
|
|
><A
|
|
NAME="AEN1719"
|
|
></A
|
|
>Use the up and down key's to scroll <A
|
|
NAME="AEN1721"
|
|
></A
|
|
>through previously typed commands. Press [Enter] to execute <A
|
|
NAME="AEN1723"
|
|
></A
|
|
>them or use the left and right arrow <A
|
|
NAME="AEN1725"
|
|
></A
|
|
>keys to edit<A
|
|
NAME="AEN1727"
|
|
></A
|
|
> the command first. Also see <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>history</I
|
|
></SPAN
|
|
> (below).</P
|
|
></DD
|
|
><DT
|
|
>The history command</DT
|
|
><DD
|
|
><P
|
|
>The<SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
> history <A
|
|
NAME="AEN1735"
|
|
></A
|
|
></I
|
|
></SPAN
|
|
> command can be used to list Bash's log <A
|
|
NAME="AEN1737"
|
|
></A
|
|
>of the commands you have typed:</P
|
|
><P
|
|
>This log <A
|
|
NAME="AEN1740"
|
|
></A
|
|
>is called the “history”. To access <A
|
|
NAME="AEN1742"
|
|
></A
|
|
>it type:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>history n</PRE
|
|
><P
|
|
>This will only list the last <A
|
|
NAME="AEN1746"
|
|
></A
|
|
><SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>n</I
|
|
></SPAN
|
|
> commands. Type “history” (without options) to see the the entire history <A
|
|
NAME="AEN1749"
|
|
></A
|
|
>list.<A
|
|
NAME="AEN1751"
|
|
></A
|
|
></P
|
|
><P
|
|
>You can also type <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!n</I
|
|
></SPAN
|
|
><A
|
|
NAME="AEN1755"
|
|
></A
|
|
> to execute command number<A
|
|
NAME="AEN1757"
|
|
></A
|
|
> n. Use <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!!<A
|
|
NAME="AEN1760"
|
|
></A
|
|
></I
|
|
></SPAN
|
|
> to execute the last command you typed.</P
|
|
><P
|
|
><SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!-n<A
|
|
NAME="AEN1764"
|
|
></A
|
|
> </I
|
|
></SPAN
|
|
>will execute the command n times <A
|
|
NAME="AEN1766"
|
|
></A
|
|
>before (in other words <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!-1</I
|
|
></SPAN
|
|
> is equivalent <A
|
|
NAME="AEN1769"
|
|
></A
|
|
>to <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!!</I
|
|
></SPAN
|
|
>). </P
|
|
><P
|
|
><SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!string<A
|
|
NAME="AEN1774"
|
|
></A
|
|
> </I
|
|
></SPAN
|
|
>will execute the last command starting <A
|
|
NAME="AEN1776"
|
|
></A
|
|
>with that “string” and <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>!?string?</I
|
|
></SPAN
|
|
> will execute the last command containing the word “string”. For example:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>!cd</PRE
|
|
><P
|
|
>Will re-run the command that you last typed starting with “cd”.</P
|
|
><P
|
|
></P
|
|
><P
|
|
><SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>“ commandName <A
|
|
NAME="AEN1784"
|
|
></A
|
|
>!*”</I
|
|
></SPAN
|
|
> will execute the “commandName” with any arguments <A
|
|
NAME="AEN1786"
|
|
></A
|
|
>you used on your last command. This maybe useful if you make a spelling <A
|
|
NAME="AEN1788"
|
|
></A
|
|
>mistake, for example. If you typed:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>emasc /home/fred/mywork.java /tmp/testme.java</PRE
|
|
><P
|
|
>In an attempt <A
|
|
NAME="AEN1792"
|
|
></A
|
|
>to execute emacs <A
|
|
NAME="AEN1794"
|
|
></A
|
|
>on the above two files this will obviously fail.<A
|
|
NAME="AEN1796"
|
|
></A
|
|
> So what you can do is type:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>emacs !*</PRE
|
|
><P
|
|
>This will execute emacs <A
|
|
NAME="AEN1800"
|
|
></A
|
|
>with the arguments <A
|
|
NAME="AEN1802"
|
|
></A
|
|
>that you last typed on the command-line.<A
|
|
NAME="AEN1804"
|
|
></A
|
|
> In other words this is equivalent <A
|
|
NAME="AEN1806"
|
|
></A
|
|
>to typing:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>emacs /home/fred/mywork.java /tmp/testme.java</PRE
|
|
></DD
|
|
><DT
|
|
>Searching through the Command History (
|
|
<B
|
|
CLASS="KEYCAP"
|
|
>CTRL</B
|
|
>-<B
|
|
CLASS="KEYCAP"
|
|
>R</B
|
|
>
|
|
<A
|
|
NAME="AEN1814"
|
|
></A
|
|
>
|
|
)</DT
|
|
><DD
|
|
><P
|
|
><A
|
|
NAME="AEN1818"
|
|
></A
|
|
>Use the CTRL-R key <A
|
|
NAME="AEN1820"
|
|
></A
|
|
>to perform<A
|
|
NAME="AEN1822"
|
|
></A
|
|
> a “reverse-i-search”. For example, if you wanted to use the command you used the last time you used <SPAN
|
|
CLASS="emphasis"
|
|
><I
|
|
CLASS="EMPHASIS"
|
|
>snort</I
|
|
></SPAN
|
|
><A
|
|
NAME="AEN1825"
|
|
></A
|
|
>, 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 <A
|
|
NAME="AEN1832"
|
|
></A
|
|
>window <A
|
|
NAME="AEN1834"
|
|
></A
|
|
>is:</P
|
|
><PRE
|
|
CLASS="SCREEN"
|
|
>(reverse-i-search)`':</PRE
|
|
><P
|
|
>After you have typed what you are looking for, use the
|
|
<B
|
|
CLASS="KEYCAP"
|
|
>CTRL</B
|
|
>-<B
|
|
CLASS="KEYCAP"
|
|
>R</B
|
|
>
|
|
<A
|
|
NAME="AEN1841"
|
|
></A
|
|
>
|
|
key combination<A
|
|
NAME="AEN1843"
|
|
></A
|
|
> to scroll <A
|
|
NAME="AEN1845"
|
|
></A
|
|
>backward through the history.<A
|
|
NAME="AEN1847"
|
|
></A
|
|
> </P
|
|
><P
|
|
>Use
|
|
<B
|
|
CLASS="KEYCAP"
|
|
>CTRL</B
|
|
>-<B
|
|
CLASS="KEYCAP"
|
|
>R</B
|
|
>
|
|
<A
|
|
NAME="AEN1853"
|
|
></A
|
|
>
|
|
repeatedly<A
|
|
NAME="AEN1855"
|
|
></A
|
|
> to find <A
|
|
NAME="AEN1857"
|
|
></A
|
|
>every reference <A
|
|
NAME="AEN1859"
|
|
></A
|
|
>to the string <A
|
|
NAME="AEN1861"
|
|
></A
|
|
>you've entered.<A
|
|
NAME="AEN1863"
|
|
></A
|
|
> Once you've found <A
|
|
NAME="AEN1865"
|
|
></A
|
|
>the command you're looking for, use [Enter] to execute it. </P
|
|
><P
|
|
>Alternatively,<A
|
|
NAME="AEN1868"
|
|
></A
|
|
> using the right or left arrow keys<A
|
|
NAME="AEN1870"
|
|
></A
|
|
> will place <A
|
|
NAME="AEN1872"
|
|
></A
|
|
>the command on an actual command-line <A
|
|
NAME="AEN1874"
|
|
></A
|
|
>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="c1195.htm"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="book1.htm"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="x1877.htm"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>Shell Tips</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="c1195.htm"
|
|
ACCESSKEY="U"
|
|
>Up</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>Other Key combinations</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |