COP 3344-01 Introduction to Unix: Lecture 4
Learning objectives
After this class, you should be able to:
- Use the following Unix commands:
 cmp,cut,diff,gunzip,gzip,head,sort,tail,tar, andwc.- Compare two (possibly binary) files to determine if they are different using
 cmp.- Find out how two files differ using
 diff.- Extract some text from each line of a file using
 cut.- Read the first few lines or last few lines of a file using
 headortailrespectively.- Sort a file using
 sort.- Count the number of words and lines in a file using
 wc.- Archive files using
 tar, and extract files from the archive.- Compress and uncompress files using
 gz.- Redirect standard input, standard output (including appending to a file), and standard error.
 - Combine commands using pipes.
 - Group commands using
 '(',')', and';'.
Reading assignment
- JEA: Chapters 10-11, 23.9-23.14, Single Unix Specification for definitions of the commands.
 - Lecture slides: Lecture4.
 Exercises and review questions
- Questions on current lecture's material
 
- Create a file called
 PracticeFilewhich contains three columns of text, separated by tabs.- Output the first few lines and the last few lines of the file into another file, called
 file1, using features we have learned, such as I/O redirection. Next, output the contents offile1.- Output only the second and third columns of the file
 PracticeFileusing features we have learned.- Output lines
 4to8of the filePracticeFileusing pipes and commands we have learned (you may want to check documentation of some options toheadandtail).- Sort the contents of
 PracticeFileand output into a file calledSortedPracticeFile.- Check if the number of lines in
 PracticeFileandSortedPracticeFileare identical, using a command that we have learned.- Check if the files
 PracticeFileandSortedPracticeFileare identical, usingcmp.- Modify the file
 PracticeFileby adding a few lines, changing a few lines, and deleting a few lines, and store it in a file calledModifiedPracticeFile. Usediffto find all the differences between the two files.- Create a compressed archive of all the files you have created in this exercise, using
 tarandgzip. Move the compressed archive to a different directory, and extract the files. Check if you got the same files back. Check some of the files, against the originals, to ensure that the contents of the files have not changed.- Questions on next lecture's material
 
- Write a simple shell script called
 info, which gives the date using thedatecommand, and prints the current working directory.