old-www/LDP/intro-linux/html/sect_02_02.html

854 lines
14 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Absolute basics</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Introduction to Linux"
HREF="index.html"><LINK
REL="UP"
TITLE="Quickstart"
HREF="chap_02.html"><LINK
REL="PREVIOUS"
TITLE="Logging in, activating the user interface and
logging out"
HREF="sect_02_01.html"><LINK
REL="NEXT"
TITLE="Getting help"
HREF="sect_02_03.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"
>Introduction to Linux: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="sect_02_01.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 2. Quickstart</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="sect_02_03.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="sect_02_02"
></A
>2.2. Absolute basics</H1
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_02_02_01"
></A
>2.2.1. The commands</H2
><P
>These are the quickies, which we need to get started; we will discuss them later in more detail.</P
><DIV
CLASS="table"
><A
NAME="tab_02_01"
></A
><P
><B
>Table 2-1. Quickstart commands</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Meaning</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>ls</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><P
>Displays a list of files in the current working directory, like the <B
CLASS="command"
>dir</B
> command in DOS</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cd <TT
CLASS="filename"
>directory</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><P
>change directories</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>passwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>change the password for the current user</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>file <TT
CLASS="filename"
>filename</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>display file type of file with name <TT
CLASS="filename"
>filename</TT
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>cat <TT
CLASS="filename"
>textfile</TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>throws content of <TT
CLASS="filename"
>textfile</TT
> on the screen</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>pwd</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>display present working directory</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>exit</B
> or <B
CLASS="command"
>logout</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>leave this session</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>man <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>read man pages on <B
CLASS="command"
>command</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>info <TT
CLASS="parameter"
><I
>command</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>read Info pages on <B
CLASS="command"
>command</B
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="command"
>apropos <TT
CLASS="parameter"
><I
>string</I
></TT
></B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>search the <EM
>whatis</EM
> database for strings</TD
></TR
></TBODY
></TABLE
></DIV
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_02_02_02"
></A
>2.2.2. General remarks</H2
><P
>You type these commands after the prompt, in a terminal window in graphical mode or in text mode, followed by <B
CLASS="keycap"
>Enter</B
>.</P
><P
>Commands can be issued by themselves, such as <B
CLASS="command"
>ls</B
>. A command behaves different when you specify an <EM
>option</EM
>, usually preceded with a dash (-), as in <B
CLASS="command"
>ls -a</B
>. The same option character may have a different meaning for another command. GNU programs take long options, preceded by two dashes (--), like <B
CLASS="command"
>ls --all</B
>. Some commands have no options.</P
><P
>The argument(s) to a command are specifications for the object(s) on which you want the command to take effect. An example is <B
CLASS="command"
>ls <TT
CLASS="parameter"
><I
>/etc</I
></TT
></B
>, where the directory <TT
CLASS="filename"
>/etc</TT
> is the argument to the <B
CLASS="command"
>ls</B
> command. This indicates that you want to see the content of that directory, instead of the default, which would be the content of the current directory, obtained by just typing <B
CLASS="command"
>ls</B
> followed by <B
CLASS="keycap"
>Enter</B
>. Some commands require arguments, sometimes arguments are optional.</P
><P
>You can find out whether a command takes options and arguments, and which ones are valid, by checking the online help for that command, see <A
HREF="sect_02_03.html"
>Section 2.3</A
>.</P
><P
>In Linux, like in UNIX, directories are separated using forward slashes, like the ones used in web addresses (URLs). We will discuss directory structure in-depth later.</P
><P
>The symbols . and .. have special meaning when directories are concerned. We will try to find out about those during the exercises, and more in the next chapter.</P
><P
>Try to avoid logging in with or using the system administrator's account, <EM
>root</EM
>. Besides doing your normal work, most tasks, including checking the system, collecting information etc., can be executed using a normal user account with no special permissions at all. If needed, for instance when creating a new user or installing new software, the preferred way of obtaining root access is by switching user IDs, see <A
HREF="sect_03_02.html#sect_03_02_01"
>Section 3.2.1</A
> for an example.</P
><P
>Almost all commands in this book can be executed without system administrator privileges. In most cases, when issuing a command or starting a program as a non-privileged user, the system will warn you or prompt you for the root password when root access is required. Once you're done, leave the application or session that gives you root privileges immediately.</P
><P
>Reading documentation should become your second nature. Especially in the beginning, it is important to read system documentation, manuals for basic commands, HOWTOs and so on. Since the amount of documentation is so enormous, it is impossible to include all related documentation. This book will try to guide you to the most appropriate documentation on every subject discussed, in order to stimulate the habit of reading the man pages.</P
></DIV
><DIV
CLASS="sect2"
><H2
CLASS="sect2"
><A
NAME="sect_02_02_03"
></A
>2.2.3. Using Bash features</H2
><P
>Several special key combinations allow you to do things easier and faster with the GNU shell, <SPAN
CLASS="application"
>Bash</SPAN
>, which is the default on almost any Linux system, see <A
HREF="sect_03_02.html#sect_03_02_03_02"
>Section 3.2.3.2</A
>. Below is a list of the most commonly used features; you are strongly suggested to make a habit out of using them, so as to get the most out of your Linux experience from the very beginning.</P
><DIV
CLASS="table"
><A
NAME="tab_02_02"
></A
><P
><B
>Table 2-2. Key combinations in Bash</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Key or key combination</TH
><TH
ALIGN="LEFT"
VALIGN="MIDDLE"
>Function</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>A</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Move cursor to the beginning of the command line.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>C</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>End a running program and return the prompt, see <A
HREF="chap_04.html"
>Chapter 4</A
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>D</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Log out of the current shell session, equal to typing <B
CLASS="command"
>exit</B
> or <B
CLASS="command"
>logout</B
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>E</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Move cursor to the end of the command line.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>H</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Generate backspace character.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>L</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Clear this terminal.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>R</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Search command history, see <A
HREF="sect_03_03.html#sect_03_03_03_04"
>Section 3.3.3.4</A
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Ctrl</B
>+<B
CLASS="keycap"
>Z</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Suspend a program, see <A
HREF="chap_04.html"
>Chapter 4</A
>.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>ArrowLeft</B
> and <B
CLASS="keycap"
>ArrowRight</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Move the cursor one place to the left or right on the command line, so that you can insert characters at other places than just at the beginning and the end.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>ArrowUp</B
> and <B
CLASS="keycap"
>ArrowDown</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Browse history. Go to the line that you want to repeat, edit details if necessary, and press <B
CLASS="keycap"
>Enter</B
> to save time.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Shift</B
>+<B
CLASS="keycap"
>PageUp</B
> and <B
CLASS="keycap"
>Shift</B
>+<B
CLASS="keycap"
>PageDown</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Browse terminal buffer (to see text that has "scrolled off" the screen).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Tab</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Command or filename completion; when multiple choices are possible, the system will either signal with an audio or visual bell, or, if too many choices are possible, ask you if you want to see them all.</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
><B
CLASS="keycap"
>Tab</B
> <B
CLASS="keycap"
>Tab</B
></TD
><TD
ALIGN="LEFT"
VALIGN="MIDDLE"
>Shows file or command completion possibilities.</TD
></TR
></TBODY
></TABLE
></DIV
><P
>The last two items in the above table may need some extra explanations. For instance, if you want to change into the directory <TT
CLASS="filename"
>directory_with_a_very_long_name</TT
>, you are not going to type that very long name, no. You just type on the command line <B
CLASS="command"
>cd dir</B
>, then you press <B
CLASS="keycap"
>Tab</B
> and the shell completes the name for you, if no other files are starting with the same three characters. Of course, if there are no other items starting with <SPAN
CLASS="QUOTE"
>"d"</SPAN
>, then you might just as wel type <B
CLASS="command"
>cd d</B
> and then <B
CLASS="keycap"
>Tab</B
>. If more than one file starts with the same characters, the shell will signal this to you, upon which you can hit <B
CLASS="keycap"
>Tab</B
> twice with short interval, and the shell presents the choices you have:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>your_prompt&#62;</TT
> <B
CLASS="command"
>cd st</B
>
starthere stuff stuffit
</PRE
></FONT
></TD
></TR
></TABLE
><P
>In the above example, if you type <SPAN
CLASS="QUOTE"
>"a"</SPAN
> after the first two characters and hit <B
CLASS="keycap"
>Tab</B
> again, no other possibilities are left, and the shell completes the directory name, without you having to type the string <SPAN
CLASS="QUOTE"
>"rthere"</SPAN
>:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>your_prompt&#62;</TT
> <B
CLASS="command"
>cd starthere</B
>
</PRE
></FONT
></TD
></TR
></TABLE
><P
>Of course, you'll still have to hit <B
CLASS="keycap"
>Enter</B
> to accept this choice.</P
><P
>In the same example, if you type <SPAN
CLASS="QUOTE"
>"u"</SPAN
>, and then hit <B
CLASS="keycap"
>Tab</B
>, the shell will add the <SPAN
CLASS="QUOTE"
>"ff"</SPAN
> for you, but then it protests again, because multiple choices are possible. If you type <B
CLASS="keycap"
>Tab</B
> <B
CLASS="keycap"
>Tab</B
> again, you'll see the choices; if you type one or more characters that make the choice unambiguous to the system, and <B
CLASS="keycap"
>Tab</B
> again, or <B
CLASS="keycap"
>Enter</B
> when you've reach the end of the file name that you want to choose, the shell completes the file name and changes you into that directory - if indeed it is a directory name.</P
><P
>This works for all file names that are arguments to commands.</P
><P
>The same goes for command name completion. Typing <B
CLASS="command"
>ls</B
> and then hitting the <B
CLASS="keycap"
>Tab</B
> key twice, lists all the commands in your <TT
CLASS="varname"
>PATH</TT
> (see <A
HREF="sect_03_02.html#sect_03_02_01"
>Section 3.2.1</A
>) that start with these two characters:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>&#13;<TT
CLASS="prompt"
>your_prompt&#62;</TT
> <B
CLASS="command"
>ls</B
>
ls lsdev lspci lsraid lsw
lsattr lsmod lspgpot lss16toppm
lsb_release lsof lspnp lsusb
</PRE
></FONT
></TD
></TR
></TABLE
></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="sect_02_01.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="sect_02_03.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Logging in, activating the user interface and
logging out</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="chap_02.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Getting help</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>