The Unix Beginners Level

The Unix Beginner Level


##=Harmless.
All commands with this symbol before them are safe to try out at your own terminal, and you are encouraged to do so as you go along.
!!=Dangerous.
These commands can cause damage if you don't know what you're doing. We suggest you become familiar with them before experimenting.

All others, you use at your own risk.


Subjects:


Logging In

If you are logging in from an X-terminal, the first thing you should see is what is called a chooser menu. It comes in various formats, depending on the software your terminal is using, but generally looks like a window containing a list of meaningless names that all end with .ucolick.org, our domain name. You may or may not already know that these names are hosts, or servers, on our network which allow users to log in.

Currently, helios, theirs, sol, ra, and bigdog are the public machines which are available to anyone with a Lick account. The other hosts are owned privately, and require special request and approval to obtain accounts on. Clicking on the host of your choice should bring up the login window, consisting of the name of the host, as well as a username and password prompt.

All usernames in Unix are entirely lowercase, so if you know you are typing in the correct password, but are still unable to login (probably receiving the response "incorrect password"), there is a chance that you have accidentally hit the caps lock key on your keyboard. Believe it or not, this is a common problem among new users, and you won't be the first to encounter it - but it should be the first thing you check for when having trouble logging in, or unlocking your screen, due to an incorrect password.

When correctly logged in you should be presented with a square window titled "login" or otherwise. From here you can type commands to start up the desired applications. This is called your xterm, because it mocks the look of an old-style terminal. If you wish to bring up an additional xterm, you can request one by typing xterm :

##[229] jess@sol:/u/jess% xterm &
[4] 24051
[230] jess@sol:/u/jess% 
as shown above. The ampersand should follow all commands which are intended to bring up a new application in a separate window. This will put the job in the background.

Logging Out

When you are ready to leave, you can log out by typing one of many commands:
!![230] jess@sol:/u/jess% logout 
!![230] jess@sol:/u/jess% exit
!![230] jess@sol:/u/jess% lo
Note: Only do this after you have closed each application you started since logging in. To be safest, you should close them each successively in the opposite order as that in which you opened them.

Once you are logged in, it is possible to log in to another machine without logging out. This is called a remote login.


Windows

If you are using fvwm, the favorite window manager at Lick, there are a few methods you can employ to control your xterm, and make it more friendly. Menus can be accessed by holding down the CONTROL key on your keyboard, and clicking one of the three mouse buttons (referred to as "mouse1", "mouse2", and "mouse3") inside the xterm.

Scrollbars & Fonts

You do not need to be concerned with the mouse1 menu at this time. The mouse2 menu allows you to create a scrollbar in your xterm as the first option, which can also be maneuvered with your three mouse buttons. The mouse3 menu provides font changes to make your typeface more readable.

Moving

The top of your xterm or other application, which usually contains two boxes, or icons, on the right, and one on the left, and the title in the center with white background, is referred to as the titlebar. By clicking your first mouse button on the titlebar of any window you can bring it to the front of the screen, whereas clicking the third mouse button there will push it to the back.

To move a Unix window, simply click the title bar with the first mouse button, and drag it to the desired location. To shrink or enlarge it, position your cursor on one of the corners, click with mouse1, and extend it in any direction.

Menus

Holding down the CONTROL key once again, but this time clicking the mouse buttons in the background of your screen, will bring up more menus. The mouse1 menu, in this case, allows you to access various utilities of popular use, and the mouse3 menu allows you to quickly access applications you already have running.

If none of these things seem to work, you probably do not have fvwm. You can ask syscrits to show you how to install it (if you want these features).


Usernames

A username, also called login name, is the unique name by which you have an account on a particular network, in this case Lick. This string of lowercase characters, in Unix, is usually derived from your first or last name, or a combination of both. It is from where your email will be sent, and where it will arrive.

To see what your username is, type whoami (i.e., who am i):

[206] jess@sol:/u/jess% whoami
jess
[207] jess@sol:/u/jess% 

Each user has one, but you may not always know which user one belongs to. To find this out, you can type finger, followed by the username:

[198] jess@sol:/u/jess% finger tra
Login name: tra                         In real life: Ted Asocks
Directory: /u/tra                       Shell: /usr/local/bin/tcsh
Last login Tue Jun 11 13:14 on ttyq6 from lo8ncd:0
Unread mail since Fri Jun 21 11:54:59 1996
No Plan.
[199] jess@sol:/u/jess% 
for user accounts within Lick. There is also a local command, called locate, whereby one can do just the opposite - that is find a username from a person's real name. This checks the campus phonebook, and so will only work for people who have listings there:
[205] jess@sol:/u/jess% locate tabasz
  Name:   Tabasz, John                   Telephone ext: 3697                
      :   Electronics Technician        
      :                                 
  Unit:   U C O/Lick Observatory        
Office:   164 Nat Sci 2                  
 Email:   tabasz@ucolick.org                                

[206] jess@sol:/u/jess% 
This time use the person's last name, or the first few letters of such.


Home Directory

When you acquire an account with Lick Observatory, you are automatically assigned a login directory. It is called

       /u/username/   
where user_name is your assigned username. This is also known as your home directory, and is where you automatically start out whenever you login. Although it may appear that you are in a different directory depending on which host you login on, in reality, you should have only one home directory. It is the top of the structure which holds your subdirectories and files. What is a file, you ask?


Files

Files, in the computing sense, are collections of bits that go together. Files come in two kinds from the average user point of view: ASCII or plain text files, and binary files. Ascii (pronounced "asky") files contain only letters and numerals, what we call the "printable" characters. Binary files contain information encoded in a nonprintable way.

Binary files are not meant to be read (by humans, that is), and when you try to do so you are likely to get a message such as "This is a binary file... read it anyway?" or "******** filenamehere: Not a text file ********". These are good warnings, as if you ignore them and proceed to view the file, you will probably strain your eyes!

Ascii files, then, are the files you prepare with plain text editors such as vi, emacs, axe, etc. or with mail. They are also the kind of files you can look at using more, less, and cat. They are like the kind of document you could have typed on a typewriter, and they are a large percentage of all the files you will deal with.

This brings us to the question of how to view a file. You will find there are many alternatives for this purpose. The most basic of ways to look at a file is cat. The cat command will send the file you request to standard out (the default of standard out is to print out on your xterm, but you may change that at anytime using the | [pipe] and redirect commands) - no more, no less. It will dump the contents of the file on your xterm, in other words.

If you wish to get a little fancier, and limit what is fed to your standard out to what you can see on your screen, or do a little editing, you will want to at least use more or less.

Let's say there is a file called names, which contains a listing of all the people who work in your office. If you want to see who is in your office, cat will be sufficent:

##[225]jess@helios:/u/jess% cat names
Edna Sandberg
JoAnn Thomas
Kimberly Gabert
Kimberly Durham
Maureen McLean
Susan Fellows
Marlene Couture
Gill Casey
Mary Jo Belli
Linda Smith
Jessica Ellner

[226]jess@helios:/u/jess%

But if the list were longer, then you would probably be better off using more or less, due to their scrolling and searching capabilities, whereas cat would run the contents of the file off the screen, leaving you with only the last screenful viewable. If you had a random listing of all Lick employees, called lick, for instance:
[62]jess@helios:/u/jess% more lick
 Hubickyj                       Olenka               
 Trublood                       Bill                 
 Fulbright                      Jon                  
 Dave                           Romeel               
 Churchill                      Chris                
 Bryden                         Geoffrey             
 Hoffman                        Robert               
 Holbrook                       Jarita               
 Hufnagel                       Beth                 
 Keane                          Michael              
 MacFadyen                      Andrew               
 Schroder                       Linda                
 Shetrone                       Matthew              
 Trager                         Scott                
 Turner                         Neal                 
 Wu                             Katherine            
 Ruiz                           Teresita             
 Ruiz                           Rosalina             
 Schultz                        Angie                
 Vogt                           Nicole               
 Bivens                         Michele              
 Cadman                         Robert               
--More--(25%)
might have a more desirable result than cat. Hitting [return] with both more and less will scroll the text up, and k will scroll it down. There are many other ways to view files, such as head or tail, as well as sort them. Yet neither cat nor more or less used alone give you the ability to edit your files, or change them in any way, and that is where your standard text editors come in (e.g. vi, emacs, axe).


File Names

In Unix, there are basically no restrictions on the length of your filenames, but there are a few rules about the characters you stick in them, and it is important to pay attention to these, or you may encounter difficulties when trying to retrieve your files. Avoid filenames with a space ( ), an asterisk (*), a dash (-), a dollar sign ($), or an ampersand (&). To be truly safe, the only punctuation you should include in filenames are underscores (_) and dots (. ). The unsafe characters, which have multiple meanings in Unix, are called metacharacters or "magic characters" and you don't want them in file or directory names.

If, for some reason, you neglect to follow these rules, there IS an out (besides calling for help). If you accidentally use spaces in your filename, you can change it by utilizing the double quotes. To access other files named improperly, use the backslash in front of the metacharacter. For example:

-To change a file called "filewithspa ce" to "filewithoutspace"-

mv "/u/kelly/filewithspa ce" /u/kelly/filewithoutspace

or:

-To change a file called "filewith-dash" to "filewithoutdash"-

mv /u/kelly/filewith\-dash /u/kelly/filewithoutdash

If you follow the above instructions, you will have effectively renamed your file .


List Command

To see a list of your files, use the ls command.

This is how it looks when performed in a typical home directory:

##[216]kelly@theirs:/u/kelly% ls  
Danforth        SAVE.xsession*  cmd.log         errorb          mail.record
Mail/           Time Spent      core            lien            time
POLog           XESS.SAVE       enq             log             tmp/
[217]kelly@theirs:/u/kelly%

Command Arguments

The default of ls is to simply give you an alphabetized list of all the basic files in your current directory, excluding dotfiles . But, you have the power to change that. Like most other commands, ls has many options, or arguments, which are also called flags . A flag is simply a string, or a combination of characters (with no spaces), that, when used with a command, tells it to do something other than what it is defaulted for.

It is fairly safe to assume that a flag should be preceded by a "-", but as a few ancient unix commands are used otherwise, the only way to be sure is to either try it out yourself, or consult the man page. Let's say that you want to see more than just the names of the files in your current directory. You might find the -l (l=long) flag useful. This will provide you with a more detailed listing:

##[217]kelly@theirs:/u/kelly% ls -l
total 124910
-rw-r--r--  1 kelly        6986 Apr  5 11:27 Danforth
drwx------  2 kelly         512 May 26 12:15 Mail/
-rw-r--r--  1 kelly       43675 Apr 11 12:05 POLog
-rwxr--r--  1 kelly        3001 Oct 24  1994 SAVE.xsession*
-rw-r--r--  1 kelly       19042 Apr 10 09:53 Time Spent
-rw-r--r--  1 kelly         301 Feb  8 10:44 XESS.SAVE
-rw-r--r--  1 kelly    122459435 Dec 13 11:54 cmd.log
-rw-r--r--  1 kelly     8585648 Dec 21 10:40 core
-rw-------  1 kelly        1094 Sep 23  1994 enq
-rw-r--r--  1 kelly     4984833 Dec 12 09:11 errorb
-rw-r--r--  1 kelly        3009 May 19 11:39 lien
-rw-r--r--  1 kelly        2367 Apr 10 09:09 log
-rw-------  1 kelly       32537 Nov 15  1994 mail.record
-rw-r--r--  1 kelly        2707 Apr 10 10:21 time
drwxr-xr-x  2 kelly         512 May 26 09:46 tmp/
##[219]kelly@theirs:/u/kelly% 

Now you are given much more information, such as the date the file was last touched, meaning edited or in some way changed, and the amount of blocks the file is using. Column 3 is even kind enough to tell you who owns it. Ownership cannot be determined by the user, but is automatically given to the file's creator. Group ownership, on the other hand, can be adjusted by the owner.


File Permissions

You are probably wondering what the first column is all about in the ls -l output, and what possible meaning all those 'r's, 'w's, 'x's, and '-'s could have to you. These 10 characters contain some surprisingly helpful information, called permissions.

Permissions are what give you the right to access files and directories in particular ways. r=read, w=write, x=execute, and -=the absence of any permission . Have you ever gotten the error message "permission denied" when you tried to read a file, or enter a directory? These seemingly innocent characters are responsible.

The first character tells what type of file you are looking at, and is generally either a 'd' for directory, or a '-' for an ordinary file. The remaining nine characters determine who can manipulate the file, and how. The first three of these refer to the owner's permissions, the second three to the group's, and the last three to all other users'.

When a user has read (r) permission, they are allowed to view the file, but not make any changes to it. If they are given write (w) permission as well, they can actually edit the file. Execute permission (x) allows them to enter a directory, or execute a file.

As you can see, there are ten characters in this first field resulting from the ls -l command. The default set of file permissions, or umask, on most systems, is to give the owner read and write permission, and everyone else read alone. The owner of the file can change the permissions on it, as well as the group. This is all done with two simple commands called chmod (for "change mode"), and chgrp (for "change group"). S/he can even change the default umask, if desired.


Other examples of ls flags are r which would instruct it to reverse the sort and show time before core, and t to sort by time last modified ( latest first) rather than by name. But, what happens if you want to see a list of your files with those that haven't been touched recently first, along with the amount of space they are taking up, for easy removal?

No problem, just combine the arguments. In most cases, only one dash is required when using multiple flags. But for various reasons, there are exceptions in which each flag will need its own '-' and a space between it and the preceding and following flag. Again, when in doubt, refer to the manpage. In this case, however, that is not necessary:

##[123]kelly@theirs:/u/kelly% ls -lrt
total 124910
-rw-------  1 kelly        1094 Sep 23  1994 enq
-rwxr--r--  1 kelly        3001 Oct 24  1994 SAVE.xsession*
-rw-------  1 kelly       32537 Nov 15  1994 mail.record
-rw-r--r--  1 kelly     4984833 Dec 12 09:11 errorb
-rw-r--r--  1 kelly    122459435 Dec 13 11:54 cmd.log
-rw-r--r--  1 kelly     8585648 Dec 21 10:40 core
-rw-r--r--  1 kelly         301 Feb  8 10:44 XESS.SAVE
-rw-r--r--  1 kelly        6986 Apr  5 11:27 Danforth
-rw-r--r--  1 kelly        2367 Apr 10 09:09 log
-rw-r--r--  1 kelly       19042 Apr 10 09:53 Time Spent
-rw-r--r--  1 kelly        2707 Apr 10 10:21 time
-rw-r--r--  1 kelly       43675 Apr 11 12:05 POLog
-rw-r--r--  1 kelly        3009 May 19 11:39 lien
drwxr-xr-x  2 kelly         512 May 26 09:46 tmp/
drwx------  2 kelly         512 May 26 12:15 Mail/
##[124]kelly@theirs:/u/kelly% 


File Organization

Once you have a lot of files, you will want to begin organizing them. This can be done by placing them in directories, or categories, named according to the type of files they contain. Directories are special files, whose contents are information about other files; information which the files themselves do not contain. The 'other' files are considered to be in the directory. The entire structure is similar to that of a physical drawer of folders (analagous to directories), each of which hold their own files. The difference being that in Unix, the directories do not actually contain the files, they merely contain information about them, and numbers that reference them, which are called inodes.

In order to create your own directory, use the command mkdir. For example:

[226]jess@helios:/u/jess% mkdir personnel
[227]jess@helios:/u/jess%

There will be no output, but you will have created a directory called personnel - within the directory you are currently in. You will recognize a directory when you do the ls command because its name will be followed by a /. That is, if you use the -F argument, which here at Lick we have aliased to ls so that directories will be automatically marked with a /:

[215] jess@sol:/usr/local/examples% ls -F
ADC.contents            cshell                  projects.list
Accounting_Verification divzer.F                resources/
DATusage.ps             edt_x11                 rmail.hlp
GENERIC.xfax_settings   emacs.hlp               shellscripts/
LOEN.cshrc              emacs.mouse             sorrydave.au
Makefile                emacs.tex               sw.html
NewAcct/                fax.beginners           ta.doc
README                  lickpre@                ta.doc.
Xess3                   netlib/                 thesis-latex/
banner.xtt              news.html               tmp/
color_print             nssdc/                  vista.txt
commands                paper-latex/            wgas@
compress.usage          printing.hlp
[216] jess@sol:/usr/local/examples% 
In the output above, for example, you can see that the NewAcct, netlib, nssdc, paper-latex, resources, thesis-latex, and tmp files are directories.

NAVIGATION

To organize your files, you will first have to know how to get around. A very useful command for navigating will be the cd command, which stands for change directory. At the top of the Unix Hierarchy is the /, which is the root directory, and all other directories are considered to be below it.

If you were to follow the cd command with an explicit fully-specified location, you would go directly there:

##[186]jess@helios:/u/jess% cd /u/jess/personnel
[187]jess@helios:/u/jess/personnel%


The magic string .. means up one level in the tree directory. If you were to type:

##[187]jess@helios:/u/jess/personnel% cd ..
[188]jess@helios:/u/jess%

it would take you back.

If you are already in the directory which contains the directory you want to travel to, you may just type the name relative to where you are. It is not necessary to type the entire path (such as /u/jess/personnel/pay.schedule). Do as follows:

##[190]jess@helios:/u/jess/personnel% cd pay.schedule
[191]jess@helios:/u/jess/personnel/pay.schedule% 

and you will descend into the specified directory.

Typing the cd command by itself will usually take you back to your home directory:

[192]jess@helios:/u/jess/personnel/pay.schedule% cd
[193]jess@helios:/u/jess% 
pwd

Now that you are moving around so much, it won't be long before you lose track of where you are. To find out the exact directory you are currently in, use the pwd command (print working directory):

##[225] jess@sol:/u/jess/personnel/pay.schedule% pwd
/amd/borg/home/home1/jess/personnel/pay.schedule
##[226] jess@sol:/u/jess/personnel/pay.schedule% 
Unfortunately, you will likely find much of the results garbage at this point, since pwd reports where you truly are, meaning on what machine, and on what disk drive, the files actually rest. Since all that is not important right now, only pay attention to the last part, which tells you the current directory - in this case, pay.schedule, within personnel, within jess (my home directory).

It is inevitable that your files will get out of hand, and you will end up with unwanted files. In order to get rid of them, you will need to clean up using the rm and mv commands. As you have probably guessed, rm means remove, and mv means move. To delete a file called august.pay, just type "rm august.pay", and you will be prompted for a confirmation as below:

!![194]jess@helios:/u/jess/personnel/pay.schedule% rm august.pay
rm: remove august.pay? y
[195]jess@helios:/u/jess/personnel/pay.schedule%
Moving files to different locations is just as easy using the mv command. To move september.pay from /u/jess/personnel/pay.schedule/september.pay to /u/jess/personnel/work.schedule/september.pay, do the following:

[201]jess@helios:/u/jess/personnel/pay.schedule% mv september.pay /u/jess/personnel/work.schedule/september.pay
[202]jess@helios:/u/jess/personnel/pay.schedule%

or, to put to use the shortcuts we have explained, you could accomplish the same thing by doing this:

[205]jess@helios:/u/jess/personnel/pay.schedule% mv september.pay ../work.schedule/september.pay
[206]jess@helios:/u/jess/personnel/pay.schedule%


COPY COMMAND

Sometimes you may wish to duplicate a file; to do this use the cp command as follows:

##[209]jess@helios:/u/jess/personnel/pay.schedule% cp february.pay march.pay
[210]jess@helios:/u/jess/personnel/pay.schedule%
and now march.pay will have the same contents as february.pay.

You can also use the cp command to copy a file to a new location:

##[210]jess@helios:/u/jess/personnel/pay.schedule% cp march.pay /u/cc/march.pay

Once you work with the cp and mv commands, you will surely discover many more uses for them.


Printing

To print your files, use the command lpr, which will send the specified file to your default printer. If you are in the business office and you type:

##[218]jess@helios:/u/jess/personnel/pay.schedule% lpr march.pay
the file march.pay should be printed from the lobo printer.

To check if your file made it, or further, to see what files are currently on the print queue (in other words, are either being printed or waiting in line to be printed), and their status, use lpq:

##[219]jess@helios:/u/jess/personnel/pay.schedule% lpq
lobo is ready and printing
Rank   Owner      Job  Files                                 Total Size
active jess       205  march.pay                             2904 bytes

If you happen to change your mind after you've already told the file to print, you may have a chance to remove it from the queue. That is, if you catch it in time. Simply type lprm (like the rm command), and then the job# of your file. You will get a message similar to this:

[220]jess@helios:/u/jess/personnel/pay.schedule% lprm 205
theirs.ucolick.org: dfA205helios.ucolick.org dequeued

theirs.ucolick.org: cfA205helios.ucolick.org dequeued

if you have successfully removed the file, and it will stop printing.

If your file happens to be especially large, ie. bigger than 1 Megabyte, you need to use the command lpr -s on the machine that hosts the printer.


Passwords

When you initially acquire a user account at UCO/Lick, you will be assigned a username and an accompanying password. Do not share your password with anybody under any circumstances. Your original password is considered temporary, and should be changed soon after your first login, if not immediately. After that, it will be given an expiration date (generally six monthes), by which time you will need to change it again. This may seem unnecessary, but for security reasons, it is essential. If you fail to change your password by the designated date, you will be unable to login.

There are a few rules involved in changing your password, but once you learn them, they are very easy. The most important thing to know is that you must be on the host bigdog when you change it, and this will affect the other machines overnight. In other words, if you change your password on bigdog today, and log out, you should log back in using your new password, but if you then login to helios, you will need to use your old one until the next morning.

You can login to bigdog directly, or remotely.

Once you have logged in to bigdog, simply type the command passwd. You will be prompted to type your old password and, after you do so, you will be given a choice of picking your new password, or having one generated for you. Feel free to choose p for pick, and create your own, but be certain you think of a safe one. It should be eight characters, NOT a word that can be found in the dictionary, NOT include your name, and hard to crack. Try combining two words, or mispelling one, and as an extra precaution, you may want to include misplaced capital letters. For example, do not use Director, but dureckTir is okay. Actually, since it is referenced in this document, dureckTir is not okay, but you get the idea.


Mail

Sending and receiving e-mail is probably the foremost activity for which you will be using your computer account. First of all, you will want to know your email address. This is

username
to anyone mailing to you from a UCO/Lick account, or

username@ucolick.org
for the rest of UCSC and offsite senders.

Once you begin getting mail, which should be announced by "You have new mail." appearing in your login window, you have several choices on how to read it. The default, and most basic, is mail. The mail command will start this up, and allow you to read your email, send it, and organize it to a degree. Anything much more complex, however, and you will need one of the other mailers. The most common among these is elm, whose title is also the command, and will popup in a separate xterm, or "window", and permit one to use their preferred editor for messages. Tkmail - which uses a graphical user interface (GUI) has been recently introduced to Lick users, and quickly become a favorite as well.


Proceed to Level 2?

Return to the Index?


Comments/Questions/Suggestions to:

NICS
UCO/Lick Observatory
University of California
Santa Cruz, CA 95064
1 831 459 2303