Getting Started with UNIX

This is the first in a series of elementary tutorials on the UNIX operating system.

Contents


Introduction

What is UNIX? It is a prime example of what's called a command-line operating system. All computers require an operating system (OS), a set of very basic programs that control the inner workings of the computer. When you boot your machine (i.e., turn it on), you load the OS into the computer's memory. Without an operating system, your computer would be a lifeless pile of metal, plastic, and silicon.

Initially, all operating systems were command-line OSs, controlled by commands typed at a command line. For example, CP/M, DOS, and VMS are historically well-known examples of command-line operating systems. Indeed, if you've ever used DOS on a PC, then you're in for a pleasant surprise, since UNIX has a lot in common with DOS. If you've never used a command-line operating system, you're still in for a surprise...but perhaps not a pleasant one. To control a computer running UNIX, you have to remember many command names, some with a rather arcane syntax. I keep a small notebook handy to record new UNIX commands (yes, I'm still learning, even after many years), and you might want to do the same.


Recording a session

Another way to help you learn UNIX is to record a session in a file, which you can then view or print at your leisure. I find this very helpful when trying to remember what I did weeks or even months ago. Of course, if you use UNIX every day, then you won't need to record every session, since we tend to remember the details of repetitive tasks. But if you use UNIX sporadically or intermittently, then it's a good idea to record those initial, marathon sessions for future reference.

So let's try that. At the UNIX command line, type the following commands (but not the percent sign % or the comments at the right):
% script session1 # begin recording session
% cd # change directory to home directory
% pwd # display present working directory
% ls # list files in the current directory
% w # list users currently logged in
% finger # list users currently logged in
% ^d # end recording session
Note that
% ^d  
is shorthand notation for "control-d", which means you should hold down the control key and press the letter "d". In UNIX, pressing ^d usually signifies the end of something, such as terminal input or, in this case, session recording. Now type
% more session1 # display contents of file session1
to display the contents of the file "session1". Lo and behold, everything you typed at the keyboard and everything UNIX displayed on the screen as a result of your commands has been recorded in the file "session1". As you progress through this tutorial, bear this technique in mind. It's a good way to keep a record of what you've done while logged in to your UNIX account.


Contents

Logging in and out

The previous exercise implicitly required you to login to a UNIX host. To do so, you need a username and a password, which will be given to you by your system administrator. After connecting to the host (which is beyond the scope of this tutorial), the system will prompt you with
Username:  
to which you answer
Username: trscavo  
but of course you must substitute your username for "trscavo". Whether or not you type your username correctly, UNIX will respond with
Password:  
after which you type your password. (Note: As you type your password, the characters will not be echoed on the screen.) If you type your username and password correctly, UNIX will display some system messages (when appropriate) and finally a system prompt. Since this prompt is configurable, it varies from system to system. On one system, it might look like
freeside:~>  
while on another system, it would appear as
forbin:/home/u511/depend/trscavo 1 %
Get to know your system prompt well...it represents the UNIX command line that we've been talking about.

Important note: Throughout this tutorial we will denote the UNIX system prompt as a percent sign % for both convenience and historical reasons. So when you see
% finger  
you know you're supposed to type the command finger at the UNIX prompt (without the percent sign, of course).


Contents

Simple commands

All command-line operating systems are fussy, but UNIX is particularly so. Generally speaking, UNIX commands are case sensitive, that is, it matters whether you type upper or lowercase alphabetic characters. For example, UNIX considers the letters "A" and "a" as two distinct characters. An exception to this rule is e-mail addresses, which are case insensitive; but case matters for just about everything else, so be careful what you type. Your password, especially, must be typed exactly as it was given to you by your system adiminstrator (you can always change it, of course, but more on that later).

Okay, good, you've successfully logged in to your UNIX host. Now you need to know how to logout. This is done by typing
% logout # terminate current UNIX connection
at the UNIX command line. Please remember to logout when you're finished, otherwise the next person who sits at your terminal will be logged in to your account. This represents a potential security problem, so protect yourself and your system by logging out when finished. Finally, don't give your password to anyone!

Okay, enough warnings. Some simple commands that you can try are
% w # display info about current users
and
% finger # display finger info about current users
These commands display information about the users currently logged in to your system. It's fun (and informative) to see how many people are logged in at any given time, and what they're doing. The w command, for example, gives the output

     5:35pm  up 7 days, 20:11, 11 users,  load average: 0.25, 0.16, 0.11
  User     tty      from             login@  idle   JCPU   PCPU  what
  mgjenks  ttyp0    ethergate        5:31pm            2      1  pine
  besolins ttyp6    ethergate        5:08pm            3      1  lynx
  emho     ttyp1    198.36.22.68    11:17am  6:17      3      2  pine
  pdrake   ttyp2    ethergate        5:06pm     9      6      5  lynx
  cactus   ttyp3    ppp68-166.dial.n 5:34pm     1      1         screen -r
  jlbehr   ttyp4    198.36.22.74     5:22pm            1      1  -tcsh
  beaucham ttyp5    ethergate        4:39pm            1         telnet 128.194.4
  lynx     ttyp7    198.36.25.75    12:48pm  4:23     10     10  (lynx)
  trscavo  ttyp8    ethergate        5:35pm            1         w
  djwake   ttypb    198.36.23.66     2:33pm  2:30      1      1  -tcsh
  pmacee   ttype    198.36.25.12     8:30am  8:41      1      1  (tcsh)lnetd)
while the finger command produces the output
   Login    Name                 Tty  Idle  Login Time   Office     Office Phone
  beaucham Beauchame Branch Lib  p5        Jan 17 16:39 (ethergate)
  besolins Bonnie Solinski       p6        Jan 17 17:08 (ethergate)
  cactus   Christopher Blizzard  p3     2  Jan 17 17:34 (ppp68-166.dial.n)
  djwake   Dan Wake              pb  2:32  Jan 17 14:33 (198.36.23.66)
  emho     Em Ho                 p1  6:19  Jan 17 11:17 (198.36.22.68)
  jlbehr   Jason Behr            p4        Jan 17 17:22 (198.36.22.74)
  lynx                           p7  4:24  Jan 17 12:48 (198.36.25.75)
  mgjenks  Martha G. Jenks       p0        Jan 17 17:31 (ethergate)
  pdrake   Paula Drake           p2    10  Jan 17 17:06 (ethergate)
  pmacee   Patricia M. Acee      pe  8:42  Jan 17 08:30 (198.36.25.12)
  trscavo  Tom Scavo             p8        Jan 17 17:35 (ethergate)
You can learn a lot about UNIX just by studying the output of the w and finger commands! The finger command is especially useful since, unlike the w command, it lets you query other UNIX hosts besides the login host. Other examples of the finger command will be found elsewhere in this tutorial.


Contents

Command summary

% script <filename> # begin recording session
...  
% ^d # end recording session
   
% cd # change directory to home directory
% pwd # display present working directory
% ls # list files in the current directory
% more <filename> # display contents of file <filename>
% w # display info about current users
% finger # display finger info about current users
% logout # terminate current UNIX connection

The next in this series of tutorial documents is entitled "Navigating Directories with UNIX".