Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  1. What is Linux and Why We Use It
  2. Purpose of this Guide
  3. SSH and LinuxLab
  4. Windows Subsystem for Linux
  5. Installing Linux with Virtualbox
  6. Do not fear the CLI

...

Chapter1.Getting started with Linux

...

**Table of Contents**

<span class="sect1">[1.1. User interfaces in Linux: graphical and
command line](#user_interfaces)</span>

<span class="sect1">[1.2. Graphical user interfaces (GUIs) for
Linux](#linux_gui)</span>

<span class="sect1">[1.3. Accessing the Linux CLI through a GUI's
terminal window](#terminal)</span>

<span class="sect1">[1.4. Shells, the shell prompt, and your home
directory](#shells)</span>

<span class="sect1">[1.5. Key differences between Windows/Mac OS X and
Linux](#key_differences)</span>

<span class="sect1">[1.6. Understanding the tables of commands and
options](#tables)</span>

This chapter provides some background information on user interfaces in
Linux.

The most important information is the orientation to the command line in
<a href="#terminal" class="xref" title="1.3.Accessing the Linux CLI through a GUI&#39;s terminal window">Section1.3, “Accessing the Linux CLI through a GUI's terminal window”</a>
and the sections that follow.

References to further reading on Linux can be found in
<a href="#more_on_linux" class="xref" title="A.2.More on Linux">SectionA.2, “More on Linux”</a>.

<span id="user_interfaces"></span>1.1.User interfaces in Linux: graphical and command line
------------------------------------------------------------------------------------------

![\[Tip\]](images/tip.png)

Tip

If you're using
SSH,<sup>\[<a href="#ftn.ssh_note" class="footnoteref">2</a>\]</sup> you
can skip to
<a href="#shells" class="xref" title="1.4.Shells, the shell prompt, and your home directory">Section1.4, “Shells, the shell prompt, and your home directory”</a>.

Recall that graphical applications are unavailable while you're using
SSH, unless you're using X
tunneling.<sup>\[<a href="#ftn.x_tunneling_note" class="footnoteref">3</a>\]</sup>

Fundamentally, there are two different ways to work with the Linux
operating system:

-   through a graphical user interface
    (GUI),<sup>\[<a href="#ftn.id452777" id="id452777" class="footnote">5</a>\]</sup>
    in which the user uses a mouse to manipulate windows.

-   through the command line interface
    (CLI),<sup>\[<a href="#ftn.id452798" id="id452798" class="footnote">6</a>\]</sup>
    in which the user types commands at a prompt.

As suggested by the title, this guide focuses on the use of the CLI.

Discussion of GUIs is restricted to
<a href="#linux_gui" class="xref" title="1.2.Graphical user interfaces (GUIs) for Linux">Section1.2, “Graphical user interfaces (GUIs) for Linux”</a>,
<a href="#terminal" class="xref" title="1.3.Accessing the Linux CLI through a GUI&#39;s terminal window">Section1.3, “Accessing the Linux CLI through a GUI's terminal window”</a>,
and
<a href="#gui_alternatives" class="xref" title="AppendixB.Graphical alternatives">AppendixB, <em>Graphical alternatives</em></a>.

<span id="linux_gui"></span>1.2.Graphical user interfaces (GUIs) for Linux<sup>\[<a href="#ftn.id452843" id="id452843" class="footnote">7</a>\]</sup>
-----------------------------------------------------------------------------------------------------------------------------------------------------

If your primary use of Linux is not via an SSH
connection,<sup>\[<a href="#ftn.ssh_note" class="footnoteref">2</a>\]</sup>
your first experience with Linux will probably be with a graphical user
interface called a <span class="emphasis">*desktop
environment*</span>,<sup>\[<a href="#ftn.id452881" id="id452881" class="footnote">8</a>\]</sup>
which is often used in place of the lower-level command line-based
approach.

There are two particularly popular desktop environments for
Linux:<sup>\[<a href="#ftn.id452921" id="id452921" class="footnote">9</a>\]</sup>

-   <a href="http://www.gnome.org/" class="ulink">GNOME</a> (in which
    the menus are located at the top of the screen)

-   <a href="http://www.kde.org/" class="ulink">KDE</a> or the K Desktop
    Environment (in which the K menu is located in the lower-left corner
    of the screen)

As explained in the next section, even if you're using a GUI, you can
still access the CLI.

  

------------------------------------------------------------------------

<sup>\[<a href="#id452843" id="ftn.id452843" class="para">7</a>\]</sup>
All of these GUIs use the
<a href="http://www.x.org/" class="ulink">X Window System</a> (also
called X) as their underlying windowing system. Wikipedia has an
<a href="http://en.wikipedia.org/wiki/X_window_manager" class="ulink">article</a>
that surveys the window managers that are compatible with X, as well as
an
<a href="http://en.wikipedia.org/wiki/X_Window_System" class="ulink">article</a>
about X itself.

<sup>\[<a href="#id452881" id="ftn.id452881" class="para">8</a>\]</sup>
Instead of a desktop environment, the GUI in use could be a window
manager, such as <a href="http://fluxbox.org/" class="ulink">Fluxbox</a>
or
<a href="http://www.enlightenment.org/" class="ulink">Enlightenment</a>.
A discussion of window managers is beyond the scope of this guide,
although Wikipedia has an
<a href="http://en.wikipedia.org/wiki/Window_manager" class="ulink">article</a>
about them. Note that one component of a desktop environment is a window
manager, as Wikipedia's
<a href="http://en.wikipedia.org/wiki/Desktop_environment" class="ulink">article</a>
on desktop environments explains.

<sup>\[<a href="#id452921" id="ftn.id452921" class="para">9</a>\]</sup>
While the <a href="http://www.xfce.org/" class="ulink">Xfce</a> desktop
environment is also commonly used, it's not as widespread as GNOME and
KDE, so this guide doesn't cover it.

<span id="terminal"></span>1.3.Accessing the Linux CLI through a GUI's terminal window
--------------------------------------------------------------------------------------

When you're using a GUI (in our case, a desktop environment), you can
access the CLI through a <span class="emphasis">*terminal
window*</span>, or terminal.

The procedure for bringing up a terminal varies depending on which
desktop environment you are
using.<sup>\[<a href="#ftn.id452988" id="id452988" class="footnote">10</a>\]</sup>

-   If you're using GNOME, select the Applications menu from the top of
    the screen, then the Accessories submenu, then the Terminal
    application.

    You can also press Alt-F2 and type **`gnome-terminal`** at the
    prompt.

-   If you're using KDE, select the K menu from the lower-left corner of
    the screen, then the System menu, then the Konsole application.

    You can also press Alt-F2 and type **`konsole`** at the prompt.

-   If you're using a desktop environment other than GNOME or KDE,
    you'll need to consult the documentation for that environment.

  

------------------------------------------------------------------------

<sup>\[<a href="#id452988" id="ftn.id452988" class="para">10</a>\]</sup>
Desktop environments, including GNOME and KDE, are discussed in
<a href="#linux_gui" class="xref" title="1.2.Graphical user interfaces (GUIs) for Linux">Section1.2, “Graphical user interfaces (GUIs) for Linux”</a>.

<span id="shells"></span>1.4.Shells, the shell prompt, and your home directory
------------------------------------------------------------------------------

Once you open a terminal (or connect to a server via secure shell
\[SSH\]),<sup>\[<a href="#ftn.ssh_note" class="footnoteref">2</a>\]</sup>
you type in commands to interact with a program known as a <span
class="emphasis">*shell*</span>.<sup>\[<a href="#ftn.id453068" id="id453068" class="footnote">11</a>\]</sup>
Although GNU Bash (the Bourne Again Shell) is the most popular shell for
Linux, some Linux servers and the computers in some Linux computer labs
use tcsh as the default
shell.<sup>\[<a href="#ftn.tcsh_note" id="tcsh_note" class="footnote">12</a>\]</sup>
If you're interested in trying the Bash shell, see
<a href="#changing_to_bash" class="xref" title="A.3.2.Changing your shell temporarily to Bash">SectionA.3.2, “Changing your shell temporarily to Bash”</a>.

Once the shell starts up, you’ll see the <span class="emphasis">*shell
prompt*</span>, which indicates that the shell is ready for you to type
a command.

Here is the prompt that I see when I log in to the
<a href="http://www.cec.wustl.edu/" class="ulink">CEC</a>'s `grid`
server: `[jg18@grid ~]$ `

Thus, the format being used is:
`[username@host_machine current_directory]$ `

In addition, your current directory will initially be your <span
class="emphasis">*home
directory*</span>,<sup>\[<a href="#ftn.home_dir_note" id="home_dir_note" class="footnote">13</a>\]</sup>
as is indicated by the tilde (`~`) in the prompt
above.<sup>\[<a href="#ftn.id453187" id="id453187" class="footnote">14</a>\]</sup>

  

------------------------------------------------------------------------

<sup>\[<a href="#id453068" id="ftn.id453068" class="para">11</a>\]</sup>
The shell is covered in depth in
<a href="#shell" class="xref" title="Chapter3.Basic shell commands and related utilities">Chapter3, <em>Basic shell commands and related utilities</em></a>.

<sup>\[<a href="#tcsh_note" id="ftn.tcsh_note" class="para">12</a>\]</sup>
For learning more about tcsh, Wikipedia's
<a href="http://en.wikipedia.org/wiki/Tcsh" class="ulink">article</a>
might be informative. You can also learn more by typing **`man tcsh`**,
using the manual (man) pages that you'll learn about in
<a href="#man" class="xref" title="2.1.Manual (&quot;man&quot;) pages">Section2.1, “Manual ("man") pages”</a>.

<sup>\[<a href="#home_dir_note" id="ftn.home_dir_note" class="para">13</a>\]</sup>
Like the `C:\Documents and Settings\Your Username` directory in Windows
or the `/Users/Your_Username` directory in Mac OS X, your home directory
in Linux stores your personal files and settings. If you're a student,
your home directory is probably the top-level directory for the
long-term disk space (that is, not your "roaming profile") that your
school allocates for your use.

<sup>\[<a href="#id453187" id="ftn.id453187" class="para">14</a>\]</sup>
The symbol `~` is listed in
<a href="#symbols_table" class="xref" title="Table3.2.Common symbols from the file system">Table3.2, “Common symbols from the file system”</a>.

<span id="key_differences"></span>1.5.Key differences between Windows/Mac OS X and Linux
----------------------------------------------------------------------------------------

Before you start working with the Linux CLI, you should be aware of some
important differences between Linux and operating systems with which
you're more familiar.

Unlike Windows or Mac OS X, Linux has a case-sensitive file system. This
means that `home`, `Home`, and `HOME` would all be names for different
directories. Similarly, as you will see in
<a href="#navigating_fs" class="xref" title="3.2.Navigating the file system">Section3.2, “Navigating the file system”</a>,
you type <span class="command">**cd**</span> to change directories:
typing **`CD`** or **`Cd`** instead will not work.

When you're working with the CLI, you’ll soon discover what Eric Raymond
calls the “Rule of Silence: When a program has nothing surprising to
say, it should say
nothing.”<sup>\[<a href="#ftn.id453267" id="id453267" class="footnote">15</a>\]</sup>
When a command finishes running (say, if you create a directory `foo`
using <span class="command">**mkdir**</span>), <span
class="emphasis">*there will be no confirmation message*</span> of
something like

    directory ‘foo’ created

Rather, there will only be a message if there’s a problem, as in

    mkdir: cannot create directory `foo': File exists

Although you might use spaces in file and directory names in Windows or
Mac OS X (such as `Paper due tomorrow.doc`), <span class="bold">**don't
use spaces in file or directory names in Linux**</span>. Use underscores
(the `_` character, usually on the same key as `-`) in a file or
directory name (such as `Paper_due_tomorrow.doc`) instead of spaces. In
fact, it's best if the only characters that you use in file and
directory names are letters, numbers, hyphens (`-`), underscores (`_`),
and periods (`.`), although you shouldn't start a file or directory name
with a period, since, as noted in
<a href="#navigating_fs" class="xref" title="3.2.Navigating the file system">Section3.2, “Navigating the file system”</a>,
doing so makes the file or directory hidden.

When you use a command that would make some permanent change in the file
system (such as deleting files or renaming a file such that it would
replace a pre-existing file), the system will not ask you

    Are you sure?

You will only be prompted for confirmation if you explicitly ask for it,
such as by using the `-i` command option that is mentioned in
<a href="#manipulating_table" class="xref" title="Table3.3.Commands for manipulating the file system">Table3.3, “Commands for manipulating the file system”</a>.

Similarly, the Linux CLI has no Trash or Recycle Bin for files that you
decide to delete but might want to restore later. Deleted files are
simply deleted.

  

------------------------------------------------------------------------

<sup>\[<a href="#id453267" id="ftn.id453267" class="para">15</a>\]</sup>
From Eric Raymond's <span class="emphasis">*The Art of Unix
Programming*</span> (Boston: Addison-Wesley, 2003). Found online at
<a href="http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2878450" class="ulink">http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2878450</a>.

<span id="tables"></span>1.6.Understanding the tables of commands and options
-----------------------------------------------------------------------------

Throughout this guide are tables summarizing many of the most commonly
used Linux commands and command options. Most table entries, like the
one in the example below, follow a format similar to that used by
Linux's built-in manual
pages.<sup>\[<a href="#ftn.man_note" id="man_note" class="footnote">16</a>\]</sup>
Some table entries, such as those found in
<a href="#emacs" class="xref" title="5.2.GNU Emacs">Section5.2, “GNU Emacs”</a>,
use a different format, although the differences are explained where
relevant.

Since most commands have many options available, only a few options will
be listed. To view all options for a given command, check the command's
manual
page.<sup>\[<a href="#ftn.man_note" class="footnoteref">16</a>\]</sup>
Square brackets (that is, `[]`) around an item indicate that it's an
optional argument for the command.

<span id="table_entry_example"></span>

**Example1.1.How to read a table entry**

Given the command synopsis

`ls` \[`-a`\] \[`-l`\] \[path\]

<span class="command">**ls**</span> is the command, `-a` and `-l` are
some of the options available for <span class="command">**ls**</span>,
and `path` is an optional argument for <span
class="command">**ls**</span>.

  

  

------------------------------------------------------------------------

<sup>\[<a href="#man_note" id="ftn.man_note" class="para">16</a>\]</sup>
Manual pages are discussed in
<a href="#man" class="xref" title="2.1.Manual (&quot;man&quot;) pages">Section2.1, “Manual ("man") pages”</a>.

  

------------------------------------------------------------------------

<sup>\[<a href="#id452777" id="ftn.id452777" class="para">5</a>\]</sup>
See the Wikipedia
<a href="http://en.wikipedia.org/wiki/Graphical_user_interface" class="ulink">article</a>
on GUIs to learn more.

...

Table of Contents

1.1. User interfaces in Linux: graphical and command line

1.2. Graphical user interfaces (GUIs) for Linux

1.3. Accessing the Linux CLI through a GUI's terminal window

1.4. Shells, the shell prompt, and your home directory

1.5. Key differences between Windows/Mac OS X and Linux

1.6. Understanding the tables of commands and options

This chapter provides some background information on user interfaces in Linux.

The most important information is the orientation to the command line in Section1.3, “Accessing the Linux CLI through a GUI's terminal window” and the sections that follow.

References to further reading on Linux can be found in SectionA.2, “More on Linux”.

1.1.User interfaces in Linux: graphical and command line

Image Added

Tip

If you're using SSH,[2] you can skip to Section1.4, “Shells, the shell prompt, and your home directory”.

Recall that graphical applications are unavailable while you're using SSH, unless you're using X tunneling.[3]

Fundamentally, there are two different ways to work with the Linux operating system:

  • through a graphical user interface (GUI),[5] in which the user uses a mouse to manipulate windows.

  • through the command line interface (CLI),[6] in which the user types commands at a prompt.

As suggested by the title, this guide focuses on the use of the CLI.

Discussion of GUIs is restricted to Section1.2, “Graphical user interfaces (GUIs) for Linux”, Section1.3, “Accessing the Linux CLI through a GUI's terminal window”, and AppendixB, Graphical alternatives.

1.2.Graphical user interfaces (GUIs) for Linux[7]

If your primary use of Linux is not via an SSH connection,[2] your first experience with Linux will probably be with a graphical user interface called a desktop environment,[8] which is often used in place of the lower-level command line-based approach.

There are two particularly popular desktop environments for Linux:[9]

  • GNOME (in which the menus are located at the top of the screen)

  • KDE or the K Desktop Environment (in which the K menu is located in the lower-left corner of the screen)

As explained in the next section, even if you're using a GUI, you can still access the CLI.

...

[7] All of these GUIs use the X Window System (also called X) as their underlying windowing system. Wikipedia has an article that surveys the window managers that are compatible with X, as well as an article about X itself.

[8] Instead of a desktop environment, the GUI in use could be a window manager, such as Fluxbox or Enlightenment. A discussion of window managers is beyond the scope of this guide, although Wikipedia has an article about them. Note that one component of a desktop environment is a window manager, as Wikipedia's article on desktop environments explains.

[9] While the Xfce desktop environment is also commonly used, it's not as widespread as GNOME and KDE, so this guide doesn't cover it.

1.3.Accessing the Linux CLI through a GUI's terminal window

When you're using a GUI (in our case, a desktop environment), you can access the CLI through a terminal window, or terminal.

The procedure for bringing up a terminal varies depending on which desktop environment you are using.[10]

  • If you're using GNOME, select the Applications menu from the top of the screen, then the Accessories submenu, then the Terminal application.

    You can also press Alt-F2 and type gnome-terminal at the prompt.

  • If you're using KDE, select the K menu from the lower-left corner of the screen, then the System menu, then the Konsole application.

    You can also press Alt-F2 and type konsole at the prompt.

  • If you're using a desktop environment other than GNOME or KDE, you'll need to consult the documentation for that environment.

...

[10] Desktop environments, including GNOME and KDE, are discussed in Section1.2, “Graphical user interfaces (GUIs) for Linux”.

1.4.Shells, the shell prompt, and your home directory

Once you open a terminal (or connect to a server via secure shell [SSH]),[2] you type in commands to interact with a program known as a shell.[11] Although GNU Bash (the Bourne Again Shell) is the most popular shell for Linux, some Linux servers and the computers in some Linux computer labs use tcsh as the default shell.[12] If you're interested in trying the Bash shell, see SectionA.3.2, “Changing your shell temporarily to Bash”.

Once the shell starts up, you’ll see the shell prompt, which indicates that the shell is ready for you to type a command.

Here is the prompt that I see when I log in to the CEC's grid server: [jg18@grid ~]$

Thus, the format being used is: [username@host_machine current_directory]$

In addition, your current directory will initially be your home directory,[13] as is indicated by the tilde (~) in the prompt above.[14]

...

[11] The shell is covered in depth in Chapter3, Basic shell commands and related utilities.

[12] For learning more about tcsh, Wikipedia's article might be informative. You can also learn more by typing man tcsh, using the manual (man) pages that you'll learn about in Section2.1, “Manual ("man") pages”.

[13] Like the C:\Documents and Settings\Your Username directory in Windows or the /Users/Your_Username directory in Mac OS X, your home directory in Linux stores your personal files and settings. If you're a student, your home directory is probably the top-level directory for the long-term disk space (that is, not your "roaming profile") that your school allocates for your use.

[14] The symbol ~ is listed in Table3.2, “Common symbols from the file system”.

1.5.Key differences between Windows/Mac OS X and Linux

Before you start working with the Linux CLI, you should be aware of some important differences between Linux and operating systems with which you're more familiar.

Unlike Windows or Mac OS X, Linux has a case-sensitive file system. This means that home, Home, and HOME would all be names for different directories. Similarly, as you will see in Section3.2, “Navigating the file system”, you type cd to change directories: typing CD or Cd instead will not work.

When you're working with the CLI, you’ll soon discover what Eric Raymond calls the “Rule of Silence: When a program has nothing surprising to say, it should say nothing.”[15] When a command finishes running (say, if you create a directory foo using mkdir), there will be no confirmation message of something like

directory ‘foo’ created

Rather, there will only be a message if there’s a problem, as in

mkdir: cannot create directory `foo': File exists

Although you might use spaces in file and directory names in Windows or Mac OS X (such as Paper due tomorrow.doc), don't use spaces in file or directory names in Linux. Use underscores (the _ character, usually on the same key as -) in a file or directory name (such as Paper_due_tomorrow.doc) instead of spaces. In fact, it's best if the only characters that you use in file and directory names are letters, numbers, hyphens (-), underscores (_), and periods (.), although you shouldn't start a file or directory name with a period, since, as noted in Section3.2, “Navigating the file system”, doing so makes the file or directory hidden.

When you use a command that would make some permanent change in the file system (such as deleting files or renaming a file such that it would replace a pre-existing file), the system will not ask you

Are you sure?

You will only be prompted for confirmation if you explicitly ask for it, such as by using the -i command option that is mentioned in Table3.3, “Commands for manipulating the file system”.

Similarly, the Linux CLI has no Trash or Recycle Bin for files that you decide to delete but might want to restore later. Deleted files are simply deleted.

...

[15] From Eric Raymond's The Art of Unix Programming (Boston: Addison-Wesley, 2003). Found online at http://www.catb.org/~esr/writings/taoup/html/ch01s06.html#id2878450.

1.6.Understanding the tables of commands and options

Throughout this guide are tables summarizing many of the most commonly used Linux commands and command options. Most table entries, like the one in the example below, follow a format similar to that used by Linux's built-in manual pages.[16] Some table entries, such as those found in Section5.2, “GNU Emacs”, use a different format, although the differences are explained where relevant.

Since most commands have many options available, only a few options will be listed. To view all options for a given command, check the command's manual page.[16] Square brackets (that is, []) around an item indicate that it's an optional argument for the command.


Example1.1.How to read a table entry

Given the command synopsis

ls [-a] [-l] [path]

ls is the command, -a and -l are some of the options available for ls, and path is an optional argument for ls.

...

[16] Manual pages are discussed in Section2.1, “Manual ("man") pages”.

...

[5] See the Wikipedia article on GUIs to learn more.

[6] See the Wikipedia article on the CLI to learn more.

...