Command Line (Shell) Interface
The ssh ("secure shell")
protocol provides a text-based session to a remote host,
with no graphics and no mouse support. Interaction with the
system consists of typing commands and viewing the system's
responses in a terminal window.
(Modern Unix and Linux systems also provide a graphical
user interface with mouse support via the X Window protocol.
It's overkill for our purposes, but if you already know how to use it
and are set up for it, feel free to do so.)
Commands
Linux and other Unix-like platforms provide a rich
environment with many applications and development tools. Hence
there are hundreds of commands available to the user. However, for
our purposes, all you need to know for Perl programming are a few
commands for managing files.
Only the most common modes of usage are described here. Most of
the commands have a number of options that affect their behavior.
For full details, use the man command. Many commands
also support a --help option that displays a synopsis of
the available options.
- logout
- Logs you off and disconnects you from the system. On most
platforms, exit and ctrl-D
does the same thing.
- ls
- Lists the files in your current directory. With a -l
argument, gives a more detailed listing of file properties. The form
ls DIR, where DIR is a directory,
lists the files in that directory.
- rm FILE1 FILE2 ...
- Deletes the named files. Warning #1: Use with caution!
You might not be prompted for confirmation, and once a file is
gone, it's gone. Warning #2: Do not type
rm *. The * character is a "wildcard" that
matches every filename (except for files whose names begin with
"."), so this will delete all your
non-hidden files. To be prompted for confirmation, run rm
with the -i option.
- more FILE
- Displays the contents of a file, one screenful at a time.
Hit the spacebar to advance to the next screenful. Type
q to abort the listing, h or
? for additional options.
The more command can be used as a filter
to paginate the output of other programs. For example, type
last | more to see the output of the last
command one screen at a time.
- cp FILE1 FILE2
- cp FILES DIR
- The first form copies FILE1 to FILE2. The second form makes new
copies of all files in the list in the specified directory.
- mv FILE1 FILE2
- mv FILES DIR
- The first form renames ("moves") FILE1 to FILE2. The second form
moves each file in the list to the specified directory.
- cd DIR
- Changes your current working directory to the one specified.
The cd
command without arguments returns you to your "home" directory.
- mkdir DIR
- Creates a directory. This will fail if the directory exists.
- rmdir DIR
- Removes the directory. To succeed, the directory must be empty.
- pico FILE
- Runs the pico text editor, which allows you to modify the
specified file (and create it if it doesn't already exist).
Note: Pico is a full-screen editor. No mouse support, but
you should be able to use the arrow keys to move the cursor around,
and the PageUp and PageDown keys to scroll. Pico displays a
command menu at the bottom of the screen. The notations like
^X that you see there denote control
characters, generated by holding down the Ctrl key while
you type the character. One of the Pico commands will give you
online help.
Note: The pico editor is easy to learn
and should be just fine for the relatively short Perl programs
you'll be writing, but its limited functionality make it
unsuitable for medium to large scale projects. For that, you
should learn to use one or both of the standard editors
vi and emacs.
- perl OPTIONS FILES
- Runs the Perl interpreter, where the files contain Perl source code.
A useful option is -w ("warnings"),
which will cause the interpreter to print warning messages about
what it thinks is questionable code.
Note: Another way
to run Perl programs is described in a later section of these
notes.
- man COMMAND
- Displays online documentation ("manual entry") about the given
command, including
a list of all possible arguments and their effects. For example,
man ls gives detailed documentation on the
ls command, and man man displays
documentation on the man command itself.
- info COMMAND
- Similar to man, but presents documentation in a
more structured format. Some commands have more detailed
info entries than man entries;
on the other hand, some don't have info entries
at all. Try both. Type info info for instructions
on how to use the info facility.
- mail
- The basic Unix mail program. You can use it to read and send
email messages.
- pine
- A more full-featured, screen-oriented email program.
- who
- Shows who is currently logged in.
- last
- Shows who's logged in recently, and the times they logged in
and out.
Special Keys
When in terminal mode, you are communicating with the
shell and applications through a piece of software called a terminal
controller. Normally, the controller simply passes on keys that you
press to the application that you are running. However, certain keys are
intercepted by the controller and produce special effects:
- ctrl-D
- Produces an EOF (end-of-file) condition on keyboard input.
Warning: When typed at the shell command prompt,
this might have the effect of logging you off and disconnecting
you.
- ctrl-C
- Sends a terminate signal to the application. Normally, this
causes the program to terminate. This is a good way to abort a program
that is caught in an infinite loop.
- ctrl-Z
- Sends a suspend signal to the application. This suspends the
application but does not terminate it. The application can be resumed
later using the fg command or by other means. Warning:
The system will resist logging you off if you have suspended tasks.
(You'll see the message ""There are stopped jobs.") You
should exit from any stopped jobs before logging off.
- Backspace
- Moves the cursor one space to the left, erasing the last character
typed. (Note: Depending on the ssh client you are running,
you might need to type some other key to get this effect. Possibilties
include delete, ctrl-delete, and ctrl-backspace.)
- ctrl-U
- Erases the current line of input, moving the cursor to the beginning
of the line.
- ctrl-W
- Erases the last word typed, moving the cursor to the beginning of
the word.
Caveat: The above describes
the default behavior of
these keys. But programs can modify the effects of any of
the above keys. Hence
these keys may have different effects in different applications. In
particular, some of them work differently in the pico
editor.
Running Perl programs.
Basically, to run a Perl program, first create the source file using
a text editor such as pico. Then run the Perl
interpreter with the source file as input. This second step can be
done in two ways:
- Run the perl command with the source file as
argument. This method was described earlier.
- Make the first line of the source file a "shebang"
line that looks like this:
#!/usr/bin/perl
Change the mode of the source file to "executable".
Then type ./FILENAME (replacing FILENAME
with the name of your source file) to run the program. This method
is described in detail in the first two sections of
Nik Silver's Perl Tutorial. Note that for our platform, the
correct shebang line is the one given above, not the one given
in the tutorial. Also, if you want warnings always to be enabled
(probably a good idea), use the shebang line
#!/usr/bin/perl -w
You may find it useful to name your Perl source files to end in
.pl, to distinguish them from other types of files,
but this is not required. Perl will accept
any filename.