Introduction to Unix CS 21 Lecture 14 Lecture

  • Slides: 28
Download presentation
Introduction to Unix – CS 21 Lecture 14

Introduction to Unix – CS 21 Lecture 14

Lecture Overview n n Lab Questions Backup schemes n n Printing in Unix n

Lecture Overview n n Lab Questions Backup schemes n n Printing in Unix n n Using tar to archive lpr lpq Lprm Quiz 2

Bash Shell Scripting Clarifications n #/bin/bash n n Must be the absolute first line

Bash Shell Scripting Clarifications n #/bin/bash n n Must be the absolute first line in your script, otherwise it is meaningless Put before your name, and before anything else # will start a comment, so put in front of your name Always run your scripts to verify what they are doing before you turn them in

Take Home Assignment Clarifications n n n This is longer than all other programs

Take Home Assignment Clarifications n n n This is longer than all other programs so far, so if you haven’t started yet, start ASAP Due at the beginning of lab on Thursday (6: 00 pm) Hints: n n Awk can be treated like just another bash program, so you can make calls and awk programs inside your bash shell script Indent for readibility (Comment for understandability)

Once A File Is Gone, It’s Gone n n The only way to prevent

Once A File Is Gone, It’s Gone n n The only way to prevent data loss is to keep a recent copy somewhere safe Of course, the entire hard drive could fail, so to be safer you need it in multiple locations n n Other hard drives Backup tapes

Our System - RAID n n n Redundant array of independent disks Every hour

Our System - RAID n n n Redundant array of independent disks Every hour a process checks and stores away any difference in your directories and files Places these files in the. snapshot direcotry n Located on one or more other drives

Tape Archive - tar n Designed to store files onto a tape device n

Tape Archive - tar n Designed to store files onto a tape device n n Now used for storing and collecting files anywhere Creates and maintains archives Commonly seen as XXXX. tar files Usage: tar [FLAGS] [FILES]

Common Flags n -c n n -f n n Specify file -x n n

Common Flags n -c n n -f n n Specify file -x n n Create an archive Extract an archive -t n List an archive

Creating A tar Archive n n n tar –cf backup. tar FILES tar –c

Creating A tar Archive n n n tar –cf backup. tar FILES tar –c FILES > backup. tar As always, if you use file redirection be careful n Easy to overwrite

Example

Example

Listing A tar Archive n n n tar –tf backup. tar –t < backup.

Listing A tar Archive n n n tar –tf backup. tar –t < backup. tar Will simply print out a list of all files located in that tar archive without changing them

Example

Example

Extracting A tar Archive n n tar –x < backup. tar –xf backup. tar

Extracting A tar Archive n n tar –x < backup. tar –xf backup. tar Will create all of the files in their respective directories Will overwrite any files that are there already, so be carefule

Example

Example

Automatically Compressing A tar Archive n -Z n n -z n n Runs zip

Automatically Compressing A tar Archive n -Z n n -z n n Runs zip automatically on all files Runs gzip automatically on all files Example: n tar –czf compressed. tar. gz *. txt

The Most Common Usage n n Tarfile. tar. gz Referred to as a “tarball”

The Most Common Usage n n Tarfile. tar. gz Referred to as a “tarball” Almost all Unix programs and packages are available in this form To extract them: n tar –xzvf tarball. tar. gz

Example

Example

Basic Printing In Unix n The printers expect to be given a. ps file

Basic Printing In Unix n The printers expect to be given a. ps file n n Postscript Other formats may or may not work or may come out ugly n n Pdf (Adobe Acrobat format) Ascii (Straight text)

lpr n n n Directly feed a printer a ps file to print Usage:

lpr n n n Directly feed a printer a ps file to print Usage: lpr [FLAGS] to. Print. ps Most common flag: n n n -Pname Specifies the name of the printer to send it to Default is located in /etc/cups/lpoptions

lpq n n Prints out a list of all jobs waiting to be printed

lpq n n Prints out a list of all jobs waiting to be printed from a specific printer Each job has an associated job ID Usage: lpq [FLAGS] Most common usages: n n lpq -Pname

Poor Example

Poor Example

lprm n n n Used to remove jobs from the queue Usage: lprm [FLAGS]

lprm n n n Used to remove jobs from the queue Usage: lprm [FLAGS] job. ID Example: n lprm –Pname 23

Always Remove Your Print Jobs That Don’t Print! n n n Sometimes, the printers

Always Remove Your Print Jobs That Don’t Print! n n n Sometimes, the printers don’t work and people send jobs to the printers without knowing it These jobs hang around until the printers start working again, and then everything gets printed Your work could print out when you’re not there and someone else could take it

a 2 ps n n n Convert ASCII files into the. ps format Usage:

a 2 ps n n n Convert ASCII files into the. ps format Usage: a 2 ps [FLAGS] ascii. File Examples: n n a 2 ps –o print. Me. ps ascii. File a 2 ps –Pname ascii. File

pdf 2 ps n n Converts Pdf format files into. ps files Usage: pdf

pdf 2 ps n n Converts Pdf format files into. ps files Usage: pdf 2 ps input. pdf output. ps

Viewing ps, pdf, And Other Files n gs n n n gv n n

Viewing ps, pdf, And Other Files n gs n n n gv n n n Ghostscript A basic ps and pdf viewer Ghostview A more user friendly ps and pdf viewer xpdf n A pdf viewer

Next Time n Perl Programming Basics n n Syntax When would you use perl?

Next Time n Perl Programming Basics n n Syntax When would you use perl?

Quiz 2 n Good Luck

Quiz 2 n Good Luck