IT 244: Introduction to Linux/Unix
Class 3
Tips and Examples
Review
New Material
Microphone
Login Failure
If you enter the wrong password 5 times when connecting to pe15
you will be temporarily blocked from logging in to this machine.
This lock out will only last for 2 hours.
After 2 hours, you should be able try again.
If you have forgotten or misremembered your password, you can change it.
Go to https://portal.cs.umb.edu/password/
Recordings of Class Meetings
You will find links to the recordings of class meetings
here.
Use of Storage Space on the CS LAN
All of you will have an account on the Computer Science Department network.
With this account you get a home directory.
There is a limit on the total size of the files in your home directory.
So you should not store there anything you do not need for your classwork.
Readings
If you have the textbook you should read chapter 2,
Getting Started.
You will find a list of all reading assignments here.
There is a link to this page on the class web page.
Homework 2
I have posted homework 2.
As usual, it will be due this coming Sunday at 11:59 PM.
Let's take a look at the assignment
Class Quizzes
From now on, each class will have a Class Quiz.
The Class Quiz is ungraded.
It is designed to help you remember the material covered in class.
Here is how it works.
Go to the listing of Class Quizzes you will find
here.
Click on the link for the quiz you need to take.
Answer all the questions on a piece of paper.
Go to the listing of Class Quiz Answers you will find
here.
Check your answers.
First Graded Quiz
The first graded quiz will be given on Tuesday next week.
The questions from the graded quiz are taken from the ungraded quizzes of the
previous week.
Unless I tell you otherwise, you should expect a graded quiz each week.
The quiz will be available on Gradescope on Tuesday.
Do Not Post Anything From this Class Online
There are many web site that claim to "help" students
learn new material.
As far as I am concerned sites like Chegg and CourseHero get their money
by helping students cheat on their assignments.
Posting ANYTHING on such sites is a violation of your
Oath of Honesty and will be reported to the Provost's Office.
This includes quiz and exam questions as well as homework assignments
and Class Exercises.
Questions
Are there any questions before I begin?
Tips and Examples
Some Skills Only Come With Work
- This course requires you to learn and understand a number
of concepts
- You will find a list of them
here
- You must know them on a deep and fundamental level ...
- so that you can use them to accomplish a task
- It is not enough to memorize a definition ...
- though that is a first step
- Each of these concepts is a tool
- And the best way to learn a tool is to use it
- That is why there are so many assignments in this class
- You will be writing small scripts for this course
- When you write them think of the concepts you are learning
- And what other things you can do with them
- You might want to play around with a concept
- Write a little something of your own ...
- to better see how they work
- Understanding comes with the effort
- The more you work with a concept ...
- the more you can do with it
Class Exercises
- There is a Class Exercise for every class ...
- except the review sessions for the Midterm and Final exams
- Each Class Exercise must be in a separate directory inside the
ex directory
- The ex directory must be inside your
it244 directory
- If you do not finish the script in class you can finish it later
- All Class Exercises must be finished before the following Sunday at 11:59 PM
- I check your Class Exercises 4 times a week
- The last check is on the weekend after they are due
- If there is a problem with your script, or it is missing ...
- I will send an email to your UMB email address
- If the exercise is not complete or it has an error ...
- you will lose two points for each day it is late
- I have have written test scripts for each of the Class Exercises
- I use these scripts to test your code
- You can run these scripts to test what you have written
- But you have to connect to pe15.cs.umb.edu
to do this
- At the bottom of every Class Exercise is the command you run
to test your script
- When you run this command you will be asked for your username
- After you enter this an hit return, the test will run
- Here is how it looks for Class Exercise 2
$ ~ghoffman/it244_test/ex02.sh
Unix username: ghoffman
ex hw
ex10 ex12 ex16 ex18 ex2 ex22 ex24 ex26 ex5 ex7 ex9
ex11 ex13 ex17 ex19 ex21 ex23 ex25 ex27 ex6 ex8
ex2.sh
ghoffman Glenn Hoffman
Class Exercise 2
- When you run the test scripts you will not see all the ex
directories
- When testing future Class Exercises you will see something like this
++++++++++++++++++++++++++++++++++++++++++++++++++
Error check
--------------------------------------------------
--------------------------------------------------
- This is the test script running your code looking for Unix errors
- If you see nothing between the two lines of dashes,
----, your script is good
- If the output of your script is missing something or
produces incorrect output ...
- you will hear a beep ...
- and see an error message
Getting Help
- This course makes you do things that you may not have done before
- Whenever you do something new there is always a good chance you will make
a mistake
- When this happens, the first thing you should do is reread the instructions
- Mistakes often happen when we read too fast
- If you cannot fix the problem in a reasonable amount of time, ask for help
- There are two ways you can do this
- Post a question in the class discussion area
- Email the Class Assistant
- DO NOT EMAIL ME with your question
- I have over 100 student each semester
- With that workload I must be very careful how I spend my time
- I would rather respond to your question on Piazza than in an email
- Only one student will see an email response
- But an answer on Piazza can be seen by the entire class
- Only send me an email when you have an issue that affects you and you alone
- Like being out of the country due to a family emergency
Describing a Problem
Don't Use Screenshots in Piazza
- Many students paste screenshots of code into Piazza
- This is not a good idea
- I have a hard time reading some of the screen shots
- And I can't copy the code into the Python interpreter to test it
- Instead tell me the name of your script on
pe15.cs.umb.edu
- This way I can run the code myself
- And use various debugging techniques
Review
Shells
- The shell
is the program that gives you the command line
- You use the command line to run programs
- Modern shells provide a number of features that make them easier to use
- Down through the years there have been a number of different Unix shells
- Today, the two most common shells are the TC shell and Bash
- We will be using Bash in this course
Unix Commands
- Unix commands are programs
- To run a Unix command type the program name on the command line
- Sometimes you want that command to work on something like a file or directory
- To do this you type the name of the file or directory after the command
- This is called an
argument
- Some commands have
options which appear right after the command
- Options change what the command does
- For example the
ls
command lists the contents of a directory
$ ls
foo.txt it244 work
- When
ls
is used with the -l
(for long) option, you get more information
$ ls -l
total 3
-rw-r--r-- 1 it244gh libuuid 16 2012-06-26 16:19 foo.txt
lrwxrwxrwx 1 it244gh libuuid 34 2012-02-07 09:46 it244 -> /courses/it244/s19/ghoffman/it244gh
drwxr-xr-x 2 it244gh libuuid 512 2012-06-27 11:08 work
- If
ls
is given the name of a directory as an argument
it will list the contents of that directory
$ ls html
it116_html it117_html it244_html
Attendance
New Material
The Command Line
- In this course we will be using the command line
- On the command line, you talk to the machine by typing
- You have to be careful what you type
- If you make a mistake of even one character the command will not work
- This is not the way most of you have interacted with computers
- You are used to a Graphical User Inteface
- GUIs
use windows, icons, menus and buttons to make it easy to talk to a computer
- The command line is NOT a user friendly environment
- I sometimes call it user hostile
- So why do we study the command line?
- Because the command line has more power
- Programs written with a GUI take time to create and maintain
- They will never have all the features of the command line
- Most Linux/Unix server installations never install a GUI
- A GUI uses system resources that are better spent on other things
- The commands you type at the command line can be put into text files
- These files are called shell scripts
- Instead of typing the commands, you can simply run the shell script
- This makes it easy to automate routine tasks
The Unix script
Command
- Sometimes it is useful to keep a record of your Unix session
- For example, when you are running software to install a package
- When you run an installer you usually answer a number of questions
- It's good to have a record of your answers if you run into trouble later
- Unix provides the
script
command to keep a record of a
shell session
- When you run
script
, Unix creates a new shell session
- Then everything that appears on the screen is stored in a text file
- Everything you type ...
- and everything that is printed in reply
- If you run
script
with no argument, the name of the text
file will be typescript
- This file will be created in the directory you were in when you ran
script
- To end the
script
session, type exit
at the
command line
script
does not save anything to disk until you type
exit
- If you want to add to the bottom of an existing
typescript file run
script -a
- If you don't you will lose what was in the original file
- It will be overwritten with the text from the new session
- When you end a
script
session you will be back in the original directory
- This will happen even if you changed directories in your
script
session
The Editor Used in This Class
- Unix can be customized in many ways
- All these customizations are done by editing text files
- This means you need to know how to use a Unix text editor
- A text editor creates a file that only contains characters
- It does not contain formatting information like bold or italic
- Most Unix system administrators use the
vim
text editor
vim
is an updated version of the vi
editor
- The textbook devotes an entire chapter to
vim
and another chapter to emacs
emacs
is preferred by programmers
- I don't want to spend class time teaching you either editor
- The only way to learn an editor is to use it
- Both
vim
and emacs
have many features
- So using them can be very confusing at first
- Today I'll show you
nano
, a simple text editor
- Today's Class Exercise will give you some practice with
nano
- You are free you use any Unix text editor in this class
- Do not use a word processor, such as Microsoft Word
- These programs create files with non-printing format characters
- Such files are useless on Unix
- If you submit work NOT not created by a text Unix text editor you will lose points
The nano
Text Editor
nano
is a simple text editor created as part of the GNU project
- In
nano
you issue a command by holding down the Control key while pressing a letter
- You can move to the beginning of a line of text by pressing Control A
- Control E will move the text insertion point to the end of the line
- The Control key is a modifier key like the Shift key
- You hold down the Shift key to capitalize a letter
- You hold Control key while pressing a letter to make something happen
- When I write "Control A" it does not mean hold down the Shift key along with the Control key
- I mean hold down the Control key while pressing the A key
- Some of the basic
nano
commands appear at the bottom of the page
- The ^
in this list of commands stands for the Control key
- So ^O means Control O
- The
nano
feature set is limited
- You can only work with one file at a time
- You can search for text but there is no search and replace feature
nano
does have a limited cut and paste feature
- If you press Control K the entire line will disappear
- You can then go to another line and hit Control U
- The line will be pasted back at that point
- When you want to save a file you hit Control O
- The name of the file will appear at the bottom of the screen
- You need to hit Enter to accept that name and complete the save process
- Control X will quit
nano
- I have created a web page with instructions for using
nano
here
- There is a link to it on the class web page
Retrieving Your Last Command
- What do you do when the command does not work?
- You need to run it again, fixing your mistake
- But if you try to type in the command all over again ...
- you could make a different mistake
- Fortunately, Bash can help
- Bash remembers your previous command lines and lets you run them again
- This feature allows you to retrieve the last command you typed
- You use this feature by pressing the Up and Down arrow keys
- To retrieve the last command, simply hit the Up arrow
- To retrieve the next to last command, hit the Up arrow twice
- You can use the Down arrow to go in the opposite direction
- Get in the habit of using this history feature
- It can save you a lot of typing
Correcting Mistakes on the Command Line
- The command line is not a user friendly environment
- There are no menus
- You have to remember the names of all commands
- This is one reason Unix command names tend to be short
- If you misspell a command, Unix responds with a cryptic error message
- Fortunately, Unix provides
command line editing
- This means you can change what appears on the command line before you run it
- Control A moves to the beginning of the command line
- Control E moves to the end of the command line
- Control U removes all text from your current position to the beginning of the line
- Control K removes all text from your current position to the end of the line
- Any text deleted by using Control U or
Control K is stored in memory
- You can paste it back on the command line using Control Y
- The Right and Left arrow keys move the text insertion point back and forth
- Today's class exercise will let you practice these features
Stopping a Running Program
- Most commands run quickly
- But some programs, like a compiler, can take a long time to finish
- Every once in a while you run a command that never seems to finish
- When you need to abort a running program use Control C
- This will work on most Unix systems
Using Options with Unix Commands
- Most Unix commands have options which modify their behavior
- These options appear after the command
- You must type a space before entering the option
- Before the GNU project, most options used a single letter ...
- and were preceded by a single dash
- Most GNU utilities use options which consist of words ...
- preceded by two dashes
- Often, commands will support both option formats
$ cat --help
Usage: cat [OPTION]... [FILE]...
Concatenate FILE(s), or standard input, to standard output.
-A, --show-all equivalent to -vET
-b, --number-nonblank number nonempty output lines
...
Getting Help with Unix Commands
- Most Unix commands have a help option,
--help
- This option will provide a brief description of the command
- It will also provide a list of options
$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
...
The System Manual
- Unix comes with two extensive documentation systems
- The first system consist of the
man
pages
- To use this system type
man
followed by the name of the Unix command
$ man ls
- The man pages are usually several screens in length
- Hit the Enter key to move down one line
- Or hit the Space bar to move to the next screen
- To exit, type q
- You can move up and down through the
man
pages using the Up and Down arrow keys
- The
man
pages are often very technical
- They can be quite intimidating
- But you don't have to read all of the page
- You only have to read enough to answer your question
- I usually read the first few lines which show the arguments expected
- Then I skim down the list of options
- Learn the art of reading just enough to get the job done
- A dear friend of mine called this "guerrilla reading"
- Go in
- Get what you need
- And get out
The info
System
- Linux also provides an entirely different documentation system
- This system is menu-based and was created by the GNU project
- To enter this system use the
info
command
- You can follow
info
with the name of a command
- If you don't give an argument to
info
you will see an introductory section
- The Up and Down arrow keys will move up and down one line at a time
- The Space bar moves you down one screenful
- The
info
system uses links which are indicated by an asterisk, *
- To use a link, move down to a line with an asterisk and hit Enter
- This will take you to a new page
- To return to where you were, type l (the letter "el") for "last"
- Type h for help
- When you are done with the help page type l (el)
- To leave the
info
system type q
info
is better than man
for commands created by the GNU project
Searching for a Keyword with apropos
Getting Help from the Internet
- The Internet is also a very good source of information about Linux
- If you get a strange error message, try typing it into Google
- There is a large amount of Linux documentation on the web
- One place to start is the Linux Documentation Project
which you will find at www.tldp.org
Homework Directories
- When you first log in, you will be in your home directory
- The name of this directory is your Unix account name
- You homework needs to go into another directory
- Each of you should have a class directory, it244, in your home directory
- For each homework assignment you must create a new homework
directory ...
- inside your hw directory
- The name of this directory must be "hw" followed by a number
- So directory for homework 2 should be hw2
- I use a shell script to collect your homework
- If you put your homework in a different place the script will fail
- Grading homework takes a lot of time
- Having to search for your work makes the grading take longer
- If you put your homework in the wrong directory ...
- you will get a 0 for the assignment
Using script
in Homework 2
- Homework 2
is your first homework assignment using Unix
- The assignment must be done on pe15.cs.umb.edu
- You need to create a text file using
nano
or
some other Unix text editor
- You will also be asked to run
script
and do 12 things
- I will look at the typescript file you create ...
- to see if you have completed the work correctly
- Your
script
session does not have to be perfect
- If you make a mistake while running
script
simply try again
- The best thing to do is to practice the commands before you use
script
- When you have a list of commands that work ...
- you can then run them in a
script
session
- Be sure to check your work
Class Exercise
Class Quiz