CS 1371 Lab 2:
Introduction to  UNIX


Cluster Locations

If, for whatever reason, you find yourself unable to work on your assignments from your room, there are several public computer clusters from which you can access the applications required to complete your assignment.

You can find out more about these OIT clusters here.
For more exact locations of the above buildings, please refer to http://gtalumni.org/campusmap/.
 
 

Basic UNIX

Although you may be sitting in front of a Windows or Macintosh machine, school computing resources are networked on UNIX machines. This means, for example, that the email you send out from your computer travels though a network of UNIX machines before it arrives at its destination.

Similarly, email that is sent to you travels though a UNIX network and ends up on a UNIX-based computer system called "acme". If you wish to read your email or work on one of these UNIX machines, you need to log in to them. This is accomplished by running the program an SSH program. SSH is secure, that is, your network traffic is encrypted so other people cannot spy on it. This is the recommended client, as you will most likely need to transfer files to your acme account when building your webpage.

Connecting to Acme

You have two ways to connect to acme (i.e. in order to do this lab): you may choose to open a SSH session and use a UNIX based text editor to build your html page, or you may choose to use something like notepad and transfer your file(s) to acme using WinSCP. The next few sections will give you an introduction to the UNIX environment and outline the types of file permissions your webpage needs to be visible to the World Wide Web.
Note: Opening a SSH session and using WinSCP for file transfer were discussed in Lab 0.

NOTE: "Acme" is actually three computers: acmex, acmey, and acmez. The three computers all share the same resources, so it does not matter which one you use.

WinSCP

You will need WinSCP to complete this lab. The HTML file(s) you create and any pictures you incorporate will need to be transfered from your computer to acme. Please refer back to Lab 0, the Prelab, to read more about how file permissions work in WinSCP.

SSH session

If you decide to give pico, a UNIX based text editor, a try, you will need to open up a SSH session. Lab 0 covered how to install SecureCRT and connect to acme. The intructions below cover how to navigate and change file permissions in the UNIX environment.

Man Pages

So what is there to do in this UNIX environment? There are literally thousands of available UNIX commands that you can type at the command prompt, and you need to learn some of them. Each command is a combination of flags, options, and arguments that can be entered. It would take many reams of paper to print out a full description of all the commands with their options, so get familiar with the UNIX "man pages". The man pages are online manuals for all the commands and document all possible   flags and arguments available for use. To invoke the man pages, simply type:
man <command you want info on>
A good starting point is actually to type:
man man
If you know what you want to do but not what the command is called, use
apropos <word you want to search for>
or
man -k <word you want to search for>
These commands will search all the man pages for any mention of the word you wanted to search for.

UNIX File Organization

To use computers effectively, you need to have a general idea of how the files are organized. If you have used a Windows system before, you are already familiar with the concept of files and folders. UNIX has the very same structure, but you will have to settle for reading text instead of looking at windows.

Let us begin with a simple analogy. Pretend you are writing a collection of short stories, and you write a part of a story every day. You put each part on its own sheet of paper. Let us call this paper a file.

You store all the parts of a story together in story folders. Then you organize the stories into a few different topics, putting them into topic folders. Finally, you have one folder for the entire book. These folders are called directories.

Files and directories are stored similarly on computers. They are organized in a tree-like structure, with directories, subdirectories, and files. For example, you may make directories for hw1, hw2, and hw3 in your account and store your homework answers in those directories. Your webpages will be stored in a special directory called public_html. You must know how to navigate and organize these directory trees in the UNIX environment.
 
 

Basic UNIX commands

Now that you've logged onto the acme system and you know how to get some basic information on its commands, here is a set of useful, basic commands

.
 
  ls This command gives you a directory listing. It is very similar to DOS's dir command. It lists all the files and subdirectories contained in the directory you are currently working in. Like many commands in UNIX, this command   has many options and arguments that can be used to show more information. 

One of the most useful options is the -F flag. Try typing: 

ls -F

and you'll see that there are some characters at the end of some of the file names. Read the man pages for ls to find out what the -F flag does. 

You can also use this command to list only a subset of information in the current directory. Let's say that you want to look through the current directory for all files starting with the letters "da". To do this, you would perform a wildcard search: 

ls blah*

The character '*' indicates a wildcard. This means that the operating system will look through the current directory to find any filenames that start with the letters "blah" and list them, no matter what the filenames end with. 

  cd This command will change your working directory. For instance, if you were looking at the "Part1" folder in the example from the UNIX File Organization section, and you wanted to open the "Lion" folder, you could type 

cd Lion

to make the "Lion" folder the current one. If you type 

cd ..

it will move you up one directory (back to Part1, in this case). If you type 

cd

alone, it will take you back to your home directory -- the one you start out in whenever you log in.  Also, typing

~

automatically stands for your home directory. Therefore cd   ~ will get you there, and pico ~/filename.txt will let you edit, for instance, "filename.txt" in your home directory.

  rm This command allows you to remove a file from your account. The format is: 

rm filename

which would remove the file called "filename" from your account. Please note that it does not remove directories that are located inside the current directory without proper flags. Please consult the man pages for more information about the flag s. 

Unlike Windows and Macintosh, there is no "Garbage" folder or "Recycle Bin". When you remove a file, it is a permanent decision, so be careful when using this command (OIT does backup all student accounts nightly, but they will only restore files in extreme circumstances)! 

rm supports wildcard arguments, much like ls does. To use the last example, let's say that you wanted to remove all files inside the current directory starting with "da". Simply type 

rm da*

and all files starting with "da" will be removed. As was noted above, this can be somewhat dangerous. You might delete some files that you don't mean to if they also fit your criteria. To counteract that, we recommend that you use the -i option when performing mass deletions. This option tells UNIX to ask you if you want to delete each file that it is about to delete. The dialog would look something similar to this: 

%prompt% > rm -i da*

Remove daniel? (y/n) y

Remove daniel.txt (y/n) n

Remove daniel.doc(y/n) y

%prompt% >

After this command is completed, both daniel and daniel.doc will be removed from your directory. daniel.txt will remain. 

Note that using rm -r will recursively delete directories with subdirectories, so that you don't have to delete all the files manually.

pwd
This command will print out the current "working directory." (i.e. what directory you are in right now)
passwd
(Not to be confused with pwd) This lets you change your gt account password. You are required to change your password every 80-90 days, and you will be plagued with daily e-mails if you do not change it, or if you change it to something that can be easily guessed (yes, OIT *will* try to crack your password!). Make sure your password is at least 6-8 characters long and includes both lowercase and uppercase letters, as well as numbers.
mkdir This command will create a directory.
rmdir This command will remove an empty directory. Use rm -r to delete all the files first.
  mv This command allows you to move a file to a new location or give a file a new name. To rename a file, the format is: 

mv old_filename new_filename

In this case, "old_filename" is the old name of the file, and "new_filename" is the name of the new file. For example, 

mv homework1.backup homework1

would rename "homework1.backup" to "homework1". Note that if you already had a file called "homework1", you would have erased it and replaced it with the contents of homework1.backup! 

To move a file into a directory, the format is: 

mv filename directory_name

where "filename" is the name of the file you are moving, and "directory_name" is the name of the directory that you want to put the file in. 

  cp This command allows you to copy a file to a new location, without erasing the old location. If you wish to copy entire directories, use the -r flag, like this:

cp -r ~/public_html/images .

This command means: "Copy all files in my home directory under public_html/images, to *this* current directory (the . dot always means "current directory" by the way)"

  more This command allows you to view the contents of any text file without altering the contents of the file. 

more my_file

displays the contents of the file one screenful at a time. In other words, it displays information using as much as the screen as possible until it has filled the entire screen, at which point it pauses. To advance the display one line at a time , press Enter. To advance the display a whole screenful at a time, press the Space key. To quit, press 'q', or continue viewing until you reach the end of the file. You cannot scroll back up the file with more, so it is quite outdated. Here is the replacement: 

  less "Less is more and more is less." 

That statement essentially sums up the functionality of less. Less is another program that allows you to view text files, and behaves almost exactly like more except for two key differences. Less allows you to scroll back up the file using the up-directional   key on your keyboard. In addition, you can only exit a file by pressing 'q', not by simply reaching the end of the file. 

Side note: Both less and more allow you to search the text file you are viewing to find instances of a specific word or phrase. Simply type '/' and the phrase you want to search for (keeping in mind that this is case-sensitive) and press Enter. Both less and more will bring you to the next instance of that phrase in the file. People who are using more to view documents might have difficulty using this functionality with smaller text files. If more has reached the end of the text file you are viewing, it brings you back to the UNIX prompt without pausing. Be sure that you are using less or more before trying to perform your search. 

  who Used without arguments, who lists the login name, terminal name, and login time for each current user. Who can also be used to find out what your user name is. Just type either 

who am I

or 

who is who

For information regarding output when using single arguments, consult the man pages. 

  cat Displays a file to the screen all at once: 

cat my_file

It's very useful for checking your files for strange characters which may appear if the file is ftp'd in the incorrect mode.  You can see these characters by using the -v flag: 

cat -v my_file

For more information, check the man pages. 


 

UNIX File Permissions

Note that you can also change permissions via WinSCP as discussed in Lab 0. The following explores an alternate way to set file permissions.

File permissions allow you to control who can view, edit, and execute the files and directories you own. You can make some of your files available to other Georgia Tech students or anyone in the world, and it is also possible to ensure your files are private.

You can decide who can access the files in your home directory, but not files that are outside your directories. This is because they probably don't belong to you. Whoever owns them decides who has permission to access them. Type

ls -l
and you will see what is called a "long listing" of the files in your directory. It probably looks something like this:
 
  total 8            
  drwx------ 2 gt2396a gtpsa 512 Sep 3 15:57 Mail
  drwx------ 2 gt2396a gtpsa 512 Dec 20 1993 News
  -rw-r--r-- 1 gt2396a gtpsa 1056 Sep 7 12:13 hw3.txt
  drwxr-xr-x 2 gt2396a gtpsa 512 Aug 8 20:21 public

The long listing gives you various information about your files (such as their size and time stamp). Over on the right side are the names of your directories and files, and permissions are represented in the long listing as the row of letters and hyphens on the far left of each file.Here's how to read the permissions:

A "d" in the first position means that you are looking at a directory.
After the d, the next three columns represent the owner's (gt2396a) permissions. The owner is generally the user that created the file. The three columns after that are for users i n the same group as the file's group (gtpsa) and the last three are for everyone else, usually referred to as other or world.
All Georgia Tech students are part of the gtpsa group, so whatever you set for the group will apply for all students, who are usually the only people you're concerned with anyway. However, in some cases you will want to grant access to the "whole world". For example, any file you want to appear on a web page must be accessible to the whole world.
The r means that the file or directory is Readable by whoever it applies to, the w stands for Writeable, and x means eXecutable. For instance, hw3.txt is r readable and writeable by the owner, but only readable by the group and the world.
For a directory, the x permission indicates permission to access that directory to use files in the directory. You need r permission on a directory in order to perform an ls in the directory. It is important to note that directory permissions work in conjunction with file permissions. To access files, both file permissions and directory permissions must be set correctly. For example, if someone else's directory has the permissions
 
drwx--x--x  gt1232b  gtpsa  512  Aug 8 20:21  public 
 
then you can make a copy of any file in the public directory (assuming the file has the appropriate read permission). However, you could not run ls while in the public directory.

To change the permissions of a file, you use the chmod command (which means "CHange MODe"). There are two ways to use chmod -- with letters (symbolic), or with numbers (actually the octal bit pattern that the symbols are translated to). We'll just discuss the symbolic forms; you can read the man pages on chmod for more information. The format of chmod is

WHO GRANT PERMISSION
u - User (owner)  + give <PERMISSION> to <WHO>  r - read 
g - Group  - remove <PERMISSION> to <WHO>  w - write 
o - Other (World)  = remove all permissions from <WHO> and then give <PERMISSION>  x - execute 
It is extremely important that you know exactly who has permission to view, change and execute your files. In fact, it is your responsibility to ensure the security of your files. There have been an innumerable number of academic misconduct cases that involved a student copying files directly from another student's directory simply because he or she had access to them, regardless of whether or not the thief even knew the victim. Protect your files!
 
 

Using Pico

To create a file with your lab2 answers in it, you would type:
pico lab2.ans
This tells acme that you want to use pico to edit the file named "lab2.ans". If that file already exists, pico will open it and display it on the screen. You can then make whatever changes you want to it. If it does not exist, pico will create it and allow you to type whatever you want into it. Just about everything you need to know to use pico is always displayed at the bottom of the screen. Notation such as ^X means "press and hold the Control key while pressing X". Here are some useful keystrokes to know:
  ^g Online help. Note that there is no man page for pico, just the internal help. 
  ^x Exit Pico. It will prompt you to save if your file has been modified. 
  ^o Save file without quitting - very important. 
  ^r Read in a file. 
  ^d Delete the character your cursor is on. 
  ^k Cut a line or marked area. 
  ^u Uncut (paste) last cut text, inserting it at the current cursor position. 
  ^w Search your document for a word or phrase in your document. Use ^W<Enter> to search for the same word or phrase again. 
  ^f move Forward a character. 
  ^b move Backward a character. 
  ^p move to the Previous line. 
  ^n move to the Next line. 
  ^a move to the beginning of the current line. 
  ^e move to the End of the current line. 
  ^v move forward a page of text. 
  ^y move backward a page of text. 
For practice, create a text file using pico. Write a few sentences about what you did over the holiday (bet you have not done this since second grade!). Use an appropriate filename. To save it, just Ctrl-X to exit, and it will ask you if you want to save it. To save without exiting, hit Ctrl-O.

Go Back to Lab2 Main


Last Modified: June 5, 2005 by Tina Denq