Psy 422 Day 1

An overview of some problem-solving strategies that may be useful for programming and computing, followed by an introduction to Unix, and an assignment to do some problem-solving using Unix tools. We will also set up your account on the course server and create your first web page on the server.


Loggin In | Display Conventions | Command Line | The Shell | User accounts | The Tree Metaphor | The Plumbing Metaphor | Getting Help | List of Unix Commands | A Guided Tour | Assignment


Some Strategies to Keep in Mind:

To Code or Not to Code...
Considerations for deciding whether to code a solution to a problem into a script or program:


Introduction to Unix

Background

History
Unix was invented at Bell Labs in 1969 to fill an urgent need for a dependable operating system that could support multiple users at a time. In 1991 a Finnish graduate student named Linus Torvalds created a Unix-like kernel (the core of an operating system) that ran on 386 PCs. He made it freely available on the internet, and the eventual result was Linux, a free (open source) Unix operating system for PCs.
Philosophy
Unix applies the "divide and conquer" strategy as an operating system. Unix has lots of little programs that each do one thing well. Unix lets you string those little bits and pieces together in lots of different ways. The result is great power and flexibility.

Getting Started with Unix: A brief Tutorial

Logging in

An account has been created for you on sheu-hp.psy.depaul.edu. This machine will serve as our development host and web server for this course. It is where you can carry out assignments and work on projects, and generally mess around and learn things. You will also need to have an account on one of the university's public unix machines, such as shrike.depaul.edu. Most of what you learn to do on our development server should work on shrike or condor as well. For this tutorial we will be working only on our development server.

The first thing you need to do is log in. The steps below will walk you through the process.

Display conventions in this document

A quick note about my conventions for displaying input, output, and code: Code - the contents of a program or script - will be displayed like this. Output - text that the system displays to you such as the command prompt or output from a command or program - will look like this. Input - text that you are to type in, such as commands you type at the command prompt, or responses you type in as input when prompted by a program - will look like this. To indicate that you should press a certain key or combination of keys (like the tab key for example) this format will be used: tab.

The command line

If you logged in successfully, you should see something like this:

[orval@sheu-hp orval]$

This is what is affectionately known as the "command prompt," because it is where you type Unix commands. The command prompt contains some helpful information:

orval@sheu-hp
This tells you who you are (orval) and what machine you are logged in to (sheu-hp).
orval]
This tells you who you where you are (what the current directory is)
$
This tells you what shell you are running (bash) and tells you that the system is ready for you to enter a command

You can change the prompt if you like, but for now we will just use the default bash prompt and start typing in commands. Try the examples below to get you started. Remember that all commands are case sensitive - just as usernames and passwords are. By the way, I may omit telling you to "press Enter" all the time, but you can generally assume that you are expected to press "Enter" after typing in a command on the command line. Remember to type in any commands that you see next to a command prompt in the examples throughout this document.

The very first thing you should do when you log in for the first time is change your password.

Passwords can contain both upper and lower case letters, numbers, and punctuation, but no spaces. If you try to choose a password that is too easy to guess, the passwd program will not allow it. A good password is one that is not based on a dictionary word, and contains numbers or punctuation as well as letters. A good password is also one that you can remember.

Once you have successfully changed your password, log out and log back in again using your new password. To log out simply type logout or exit at the command prompt. Once you have logged back in, try out the following commands to learn more about the command line:

The shell

Most of these command line features are a function of the shell. The shell is the program that the user interacts with on the command line. There are several different shells available, and each works a little differently. We are using bash. It is the default shell for most machines. It is also favored by programmers because it is good for writing scripts - files of command lines that can be run as a batch rather than having to be typed on the command line one at a time. Another popular shell is tcsh, or the C-shell. It uses syntax that is similar to that of the C programming language. You can try out the tcsh shell by typing tcsh at the command line if you wish.

You can customize the way the shell behaves by editing the bash configuration files, .bashrc and .bash_profile. Later in the session we will edit your .bash_profle file to change the default behavior of the cp and mv commands.

User accounts and file permissions

Because Unix is designed to support multiple users at a time, it has a system for managing user accounts and files. Every file belongs to a user, and the owner of a file can determine whether other users can access it. The following commands demonstrate various aspects of file permissions and ownership.

The Tree Metaphor: The Unix file system

The Plumbing Metaphor: Standard input, standard output, piping, and redirection

Getting Help

Unix Commands: A Short List

Some basic commands (and some fancier related commands)

Unix Commands: An abbreviated guided tour

This little exercise will introduce some commonly used Unix commands and, in the process, create a web page for you on the course server.

    $ uname -a

    $ id orval

    $ who

    $ w

    $ TERM=vt100

    $ export TERM

    $ stty

    $ mkdir tempd

    $ cd tempd

    $ pwd

    $ mv ../w-output .

    $ history | tail 

    $ cd 

    $ pwd

    $ rmdir tempd

    $ mv tempd/w-output .

    $ rmdir tempd

    $ pushd /etc

    $ ls

    $ more < passwd

    $ pushd

    $ ps -aux > processes

    $ wc *

    $ ls -l

    $ sleep 5; ls

    $ tail processes 

    $ ps >> processes

    $ tail processes

    $ chmod ugo-r processes 

    $ tail processes 

    $ chmod 744 processes 

    $ head processes 

    $ cat processes | grep root 

    $ cat processes | grep root | tail

    $ ping shrike.depaul.edu
           (Demonstrates control-c)

    $ cat > controld-demo

    $ echo 'control-d is the Unix end-of-file character' | sed -e 's/Unix/Linux/'
           (Other special characters: control-z  ~ \ )

    $ rm controld-demo

    $ rm -i w-output 

    $ cal

    $ date

    $ man date

    $ info grep

    $ locate hosts.allow

    $ locate hosts

    $ locate hosts | wc

    $ locate hosts | grep '^.etc'

    $ locate hosts | grep '^.etc.*y'

    $ find /var/ftp/ -name '*index.html'

    $ vi .bash_profile 
          (uncomment the lines for aliases for mv and cp)

    $ source .bash_profile 

    $ ftp sheu-hp.psy.depaul.edu
         log in as anonymous
         cd pub
         get sample-index.html
         quit

    $ ncftp sheu-hp.psy.depaul.edu
         cd pub
         get tidy_linux_x86.tar.gz
         bookmark sheu-hp
         quit

    $ ls

    $ gunzip tidy_linux_x86.tar.gz

    $ tar -xf tidy_linux_x86.tar 

    $ ls

    $ mkdir bin

    $ mv tidy bin

    $ which tidy

    $ hash -r

    $ mv sample-index.html public_html/

    $ cd public_html/

    $ tidy -h |more

    $ tidy -i sample-index.html > index.html

    $ diff sample-index.html index.html 

    $ vi index.html
          (pico - an easier to use editor)
          (emacs - a more powerful editor)
 

Now point your web browser at sheu-hp.psy.depaul.edu/~orval (but substitute your user name for "orval").

Assignment due next week

Valid XHTML 1.0!