IT 244: Introduction to Linux/Unix
Class 3
General Advice
Course Work
Tips and Examples
Review
New Material
Microphone
Trouble? Questions?
Has anyone had any trouble doing something for this class
or have any questions?
Readings
If you have the textbook you should read chapter 2,
Getting Started.
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
Today's Class
In today's class I will cover some basics of the command line.
I will also show you and editior that can be used to create scripts.
And I will cover the script command that you will need for
homework 2.
General Advice
Do You Have Enough Time to Do the Work for This Course?
- Many of you work, either part or full time
- This cuts down on the time you have to study
- Technical courses are filled with details where accuracy is very important
- They also introduce concepts which may take some time to fully understand
- Such courses require a significant amount of study time ...
- to learn the material and do well in class
- This studying should not be done on one day ...
- but spread out over the days of the week
- You should not be taking this course ...
- if you can't study several hours a week for it
- Too many students rush to finish a degree ...
- without doing the work to really learn the material
- These people are setting themselves up for professional failure
- If you try to do too much ...
- you may end up accomplishing too little
- Today is the last day of Add/Drop ...
- when dropping the class won't mean losing money
- Be honest with yourself
- Looking at all your other commitments ...
- do you have enough time for the work I will demand of you?
Course Work
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 day's quiz
- Get a blank piece of paper
- Write the answers to the questions on the paper
- Go to the listing of Class Quiz Answers you will find
here
- Check your answers
- Do not give me the paper with your answers
- Class quizzes are not graded
- They are designed to help you learn the material covered in class
First Graded Quiz
- The first Graded Quiz will be given on Tuesday next week
- I will pass out the exam papers after my lecture
- Questions on the Graded Quiz come from the Class Quizes
- Usually the quizzes from the previous week
- Unless I tell you otherwise ...
- you should expect a Graded Quiz each week on Tuesday
- You will be able to see your scores on Gradescope
Home and it244 Directories
- When you first log in, you will be in your home directory
- This directory belongs to your account ...
- and no other account can make changes to it
- The name of this directory is your Unix account name
- If you registered for this class, you should see a
it244 entry here
- It looks like a directory ...
- but it is really something called a link
- We'll discuss links in a future class
- If you use
cd to enter it244 ...
- you will be inside your IT 244 class directory
- In Class Exercise 2 your were told to create two directories
- An hw directory for homework scripts
- And an ex for Class Exercises
- For each new assignment you must create a new directory inside
either hw pathname ex
- So today you will create an ex3 directory
inside your ex directory
- The files you create for this exercise should be created in
this directory
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 it works
- Understanding comes with 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 by 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
points
- 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 can run
to test your script
- When you run this command you will be asked for your username
- After you enter this and hit Enter or Return, the test will run
- Here is how it looks for Class Exercise 2
$ ~ghoffman/it244_test/ex02.sh
Unix username: ghoffman
ex hw
ex2.sh
ghoffman Glenn Hoffman
Class Exercise 2
- When testing future Class Exercises you will see something like this
++++++++++++++++++++++++++++++++++++++++++++++++++
Error check
--------------------------------------------------
--------------------------------------------------
- If you see nothing between the two lines of dashes,
---- ...
- your script has no Unix errors
- 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 a number of ways you can do this
- Post a question in the class discussion area
- Email the Class Assistant
- Ask other students in the class
- Come to Zoom Office Hours
- DO NOT EMAIL ME with your question
- I have close to 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 onto pe15 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
Login Failure
- If you enter the wrong password when connecting to pe15 ...
- you will be blocked from logging in for 10 minutes
- Wait 10 minutes and try again
- If you have forgotten or misremembered your password, you can change it
- Go to
https://portal.cs.umb.edu/password/
- If you have trouble with your account send an email to operator@cs.umb.edu
Review
Operating Systems
- The operating system
is the software that allows you to use a computer
- Without an operating system, a computer is a dead piece of metal
- Here is now the textbook defines an operating system
An operating system is the low-level software that schedules tasks,
allocates storage, and handles the interfaces to peripheral hardware,
such as printers, disk drives, the screen, keyboard, and mouse
- Windows and MacOs are operating systems
- As are Android and iOS for phones
Components of the Operating System
- There are three components of an operating system
- The kernel runs the operating system
- It gets it's own chunk of memory ...
- that no other program can use
- The kernel is always running
- The kernel also allows programs to talk to the hardware
- No program can use any piece of hardware without going through the kernel
- The shell is a special program that gives you the command line
- You use the shell to run other programs
- Utilities are programs that allow you to use and manage computer resources
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 commonly used 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 ...
- and hit Enter or Return
- 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 the way a command works
- 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
- In other words, we will be talking to the shell
- On the command line, you do your work by typing commands
- 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 work with 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 program
- When you run an installer you usually answer a number of questions
- It's good to have a record of your answers and how the machine reponded ...
- 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 the machine prints in response
- 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
- 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
The nano Text Editor
nano is a simple text editor created as part of the GNU project
- In
nano you give 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 and 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 window
- 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 also 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 also have 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
man as in a manual of instructions
- 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 an
internet search engine ...
- like Google or DuckDuckGo
- 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
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