IT 244: Introduction to Linux/Unix
Tips and Examples
The reading assignment for this week is chapter 2 of Sobell, Getting Started.
You will find a list of all reading assignments here.
There is a link to this page on the class web page.
I have posted homework 2.
As usual, it will be due this coming Sunday at 11:59 PM.
You will find a list of all homework assignments here.
The class web page has a link to this page.
Let's take a look at the assignment
Tips and Examples
- There is a Class Exercise for every class ...
- except the review sessions
- Each Class Exercise must be in a separate directory ...
- inside the ex directory ...
- inside your it244 directory
- If you finish the execise in class I will check it
- If you do not finish it in class you can finish it later
- All Class Exercises must be finished before Sunday at 11:59 PM
- If the execise is not complete or it has an error ...
- you will lose two points for each day it is late
- I will not check a Class Exercise from a previous class because it takes too much time
- If I have not checked you Class Exercise in class ...
- I will check it in the following week
- If you want to run my test scripts on your Class Exercise ...
- you will find my test scripts here /home/ghoffman/code/it244_code/testing_scripts_it244
- The shell
is the program you are talking to ...
- when you type something at the command line
- The shell listens to what you type at the command line ...
- and then asks the
to run the program for you
- The shell is the program you use to talk to the kernel
- 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 shell are the TC shell and Bash
- Bash is the shell we will be using in this course
- To run a Unix command, you type the command ...
- followed, perhaps, by options and arguments ...
- and then hit Enter ...
- or Return on a Mac
- Options change what the command does
- For example the
ls command lists the contents of a directory
foo.txt it244 work
ls is used with the
-l (for long) option ...
- more information is presented
$ ls -l
-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/s12/ghoffman/it244gh
drwxr-xr-x 2 it244gh libuuid 512 2012-06-27 11:08 work
- There must always be a space between the command ...
- and the option
- If you don't but a space in between ...
- you will get an error
ls-l: command not found
- Arguments are the things on which the command operates
ls is given the name of a directory as an argument ...
- it will display the contents of that directory
$ ls html
- Most Unix/Linux commands are very short, to save typing ...
- and usually have mnemonic value
- For example,
ls stands for "list"
The Command Line
- In this course we will be using the command line
- The command line is provided by your copy of the shell ...
- which allows you to runs commands ...
- by asking the kernel to run programs for you
- 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 ...
- where a great deal of effort has been spent ...
- trying to make things easier for the user
- 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
- GUI's take time to create and maintain ...
- so 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 services
- 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
- Sometimes it is useful to keep a record of your Unix session
- If you are installing new software ...
- it is good to keep a record of the options you chose
- Unix provides the
script command for this purpose
- When you run
script, Unix creates a new shell session ...
- and everything you type at the keyboard ...
- and everything that gets printed to the screen ...
- is stored in a text file
- This text file is a record of everything that happened ...
- in that shell session
- If you run
script with no arguments ...
- the session will be recorded in a file named typescript
- This file will be created in the directory you were in ...
- when you ran
- If you run
script with an argument ...
script will use that argument as the name of the transcript file
- To end the
script session, type
exit at the command line
script does not save anything to disk until you type
- If you quit your ssh session before typing
- NOTHING will be recorded
- Be sure you type
exit before disconnecting from your ssh session
- If you quit
- and then later run
script again ...
- you will lose your first session results
- The file created by the second run of
- will overwrite the contents of the first session
- If you want to add to an existing typescript file ...
- When you type
exit to end a
script session ...
- you will find yourself back in the directory ...
- from which you ran
- This will happen even if you changed directories in your
The Editor Used in This Class
- Unix can be customized in many ways
- All these customizations are done by editing text files
- For this reason, 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
- You will also need a text editor when writing scripts
- Most Unix system administrators use the
vim text editor
vim is an updated version of the
- The textbook devotes an entire chapter to
- and another chapter to
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
emacs have many features ...
- and 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
- You are free you use any Unix text editor in this class
- Do not use a word processor, such as Microsoft Word
- Such programs create files with non-printing format characters...
- which makes it very difficult to read them ...
- and impossible to run them on Unix
- If you use something that is NOT a Unix text editor ...
- when you are creating a homework file ...
- I'll deduct 10 points from your grade
nano Text Editor
nano is a simple text editor created as part of the GNU project
nano you issue a command by holding down the Control key ...
- while pressing a letter key
- You can move to the beginning of a line of text by pressing Control A ...
- and move to the end of the line with Control E
- The Control key is a modifier key like the shift key
- When you hold down the Shift key while pressing the key for a character ...
- it captitalizes the letter
- When you hold down the Contol key while pressing the key for a charcter ...
- it does not print a character
- Instead it sends control information to the computer
- When I write something like "Control A" ...
- I mean hold down the Control key while pressing the A key
- Although I used a capital A here ...
- I do not mean you should hold down the Shift key
- I use capital letters when writing control key sequences ...
- because the capital letters are easier to read
- 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
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 ...
- then if you go to another line and press Control U ...
- the line will be pasted back at that point
- When you want to save a file you press Control O ...
- and 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
- I have created a web page with instructions for using
- There is a link to it on the class web page
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 make a mistake typing a command ...
- Unix will respond with a cryptic error message
- Fortunately, Unix provides
command line editing
- that make it relatively easy to correct mistakes
- 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 put in a paste buffer ...
- and you can paste it back on the command line using Control Y
- The right and left arrow keys can also be used ...
- to move back and forth over the command line
- Today's class exercise will let you practice these features
Retrieving Your Last Command
- When you get an error message from the command line ...
- you need to enter the command again
- This can be very annoying for long and complicated commands
- Fortunately, Unix remembers the commands you enter ...
- and let's 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
- Once you have used the up arrow ...
- you can use the down arrow to go in the opposite direction
- Get in the habit of using the history feature
- It can save you a lot of typing
Stopping a Running Program
- Most Unix commands execute quickly
- Unix commands run programs
- But some programs, like a compiler, can take a long time 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
- 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 ..
- Depending on the command, you can use
--help, or both, to get help
The System Manual
- Unix comes with two extensive documentation systems
- The first system consist of the
- To use this system type
- followed by the name of the Unix command
- The man pages are usually several screens in length
- To advance, hit the Enter key to move down one line ...
- or the Space bar to move to the next screen
- To exit, type q
- You can move up and down through the
man pages ...
- by pressing the up and down arrow keys
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
- 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
- You can follow
info with the name of a command
- If you don't give an argument to
- 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
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")
- Type h for help
- When you are done with the help page ...
- type l (el)
- To leave the
info system type q
- For any utility created by the GNU project ...
info documents are superior to the
Searching for a Keyword with
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
- When you first log in, you will be in your home directory
- 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 the hw directory ...
- inside your it244 directory
- 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 somewhere else ...
- you will get a 0 for the assignment
- After I finish speaking at the beginning of each class ...
- I will distribute a Class Exercise
- You must work on this in class ...
- so I can help you if you get into trouble
- For each Class Exercise, you must create a new directory ...
- inside a ex directory ...
- inside your it244 directory
- When you are finished with the Class Exercise ...
- come to me so I can run a test script on it
- If you don't finish the Class Exercise in class ...
- you can continue working on it ...
- either at home or on campus
- But you must finish it by Sunday at 11:59 PM ...
- or you will lose points
- If you get stuck working on the assignment outside of class ...
- post your problem on the class discussion area
- I will not penalize you if you fail to complete the assignment on time ...
- due to some emergency ...
- but you must inform me of this in an email
script in Homework 2
- Homework 2 is your first homework assignment using Unix
- The assignment must be doen on users3
- You need to create a text file using
- or some other
Unix text editor
- You will also be asked to run a series of commands
- Since I need a record of what you have done ...
- so I can check you off for this assignment ...
- you will have to use the
script command keeps a record of what you type ...
- and what Linux prints to the screen ...
- in a text file
- I will look this file to see you have completed the work
script session does not have to be perfect
- If you make a mistake while running
- simply try again
- But it is best for me if you practice what you need to do ...
- before you use
- If you don't, the typescript files can become very long
- This means the grading takes much more time than it has to
- So, please, run through the homework first without using
- As you complete each step of the homework ...
- you can copy and paste the Unix command into a text file
- Then when you are sure that you have everything working ...
script copying command from your text file
- This will save me a lot of time
- Please DO NOT use an editor, like
- while running
- In other words, do not use
- The control key sequences mess up the output
- This makes it hard for me to read and grade your work