Before we get into programming proper, we need a few fundamental survival skills
which we will use to control our environment. You will need to be able find your way around the UNIX Operating System.
Now let's begin!
We will begin class today with a discussion of the terminal and file systems. We will talk about what a file system is and look briefly at the Unix file system. After that, we will hava a web activity exploring basic unix commands we will need to manage our computing environment in Computer Science.
/home/username
), create a directory named
computer_science
, then change to this directory (pwd
should return
/home/your_username/computer_science
when you are finished).
Create the following subdirectories in the computer_science
directory:
programs
, notes
, and projects
. Running pwd
now you should see this:
/home/username/computer_scienceand running
ls
should give you this:
notes programs projectsIn the
programs
directory, create four more subdirectories named gvr
,
python
, java
, and c
.
c
subdirectory of the programs
directory
(Hint: the path should be: /home/username/computer_science/programs/c
).
c
directory.
This is a compressed (zipped), archieve file containing source code for a little
utility program called tree
.
tar xzvf tree-1.5.0.tgz
tree-1.5.0
containing six files.
make
from the command
prompt. This will compile the source file into a binary, or
executable file which can be run by the operating system.
./tree
and you will see the following output:
. |-- CHANGES |-- LICENSE |-- Makefile |-- README |-- tree |-- tree.1 |-- tree.c `-- tree.oIf you move the file named
tree
(the executable file) into the computer_science
directory, and run ./tree
again, you will see this:
. |-- notes |-- programs | |-- c | | |-- tree-1.5.0 | | | |-- CHANGES | | | |-- LICENSE | | | |-- Makefile | | | |-- README | | | |-- tree.1 | | | |-- tree.c | | | `-- tree.o | | `-- tree-1.5.0.tgz | |-- gvr | |-- java | `-- python |-- projects `-- treeHow would you describe what
tree
does?
tree
available at all times and from within any directory.
To do this we need to set the PATH
environment variable. This is a rather involved process,
so follow these instructions step-by-step with care:echo $HOME
. What does this command return? Now type:
echo $PATH
. Write down on a piece of paper what this command returns.
PATH
is an environment variable that stores the search path on the system. There are
several directory paths separated by colons ( :
). When you type a command, like links2
,
the operating system searches each directory in the path, looking for a match to what you typed. The first time
a match is found, the command is executed. If no match is found, you will get back a message like this:
-bash: tree: command not foundTo see this in action, change to your home directory and type
tree
at the command prompt.
tree
is in a directory named bin
(notice how many bin
directories
where in the search path). So, make a directory named bin
in your home directory.
tree
file to this new bin
directory.
PATH
to include the new bin
directory. Before making this automatic, let's see how it works. Type the following command at the
unix prompt:
$ echo $HOME/bin:$PATHNotice how is this different from what you see when you type:
$ echo $PATH
$ export PATH=$HOME/bin:$PATH
.bashrc
file, which is located in your home directory:
PATH=$HOME/bin:$PATH export PATHYou will need to be in your home directory and use a text editor like nano to do this.
nano .bashrcCtrl-O to save
Congratulations! You have just completed our introduction to Unix.
The evaluation for this lesson will consist of a performance exercise. You will select at random (I'll tell you in class about how the selection process will work) a task to be performed. Tasks will look something like this:
sports
in your home directory.sports
directory named baseball
, football
,
basketball
, and soccer
.stars.txt
in the baseball
directory. Add the names of three
baseball stars, one per line, to this file. If you don't know the names of any baseball stars, just make up
three names.sports
directory.The complete list of tasks can be found here.