Question: For this project, you are tasked with implementing a collection of basic Unix utilities using low-level system calls. This is a natural extension to some

For this project, you are tasked with implementing a collection of basic Unix utilities using low-level system calls. This is a natural extension to some of the recent Breakouts/Labs where you were asked to implement some of the more involved utilities from scratch. Doug McIlroy, the inventor of Unix pipes and one of the founders of the Unix tradition states that one of the fundamental parts of the Unix philosophy is that you should write a program to do one thing and do it well. The programs presented in this project embody this philosophy.

Not all utilities are the same difficulty. Please manage your time wisely. Here is the list of utilities that you must implement:

1. ./head [-n number] [file...]

(20 points) The head utility shall copy its input files to the standard output, ending the output for each file at a designated point. Copying shall end at the point in each input file indicated by the -n number option. The option- argument number shall be counted in units of lines. If no file operand is specified, or when file is -, then standard input is assumed.

-n number: The first number lines of each input file shall be copied to standard output. The application shall ensure that the number option-argument is a positive decimal integer. When a file contains less than number lines, it shall be copied to standard output in its entirety. This shall not be an error. If no options are specified, head shall act as if -n 10 had been specified.

2. ./tail [-n number] [file]

(20 points) The tail utility shall copy its input file to the standard output beginning at a designated place. Copying shall begin at the point in the file indicated by the -n number option. The option-argument number shall be counted in units of lines. Line counts start from 1. Tails relative to the end of the file may be saved in an internal buffer, and thus may be limited in length. Such a buffer, if any, shall be no smaller than 2048*10 bytes. If no file operand is specified, or when file is -, then standard input is assumed.

-n number: This option shall be equivalent to -c number, except the starting location in the file shall be measured in lines instead of bytes. If neither -c nor -n is specified, -n 10 shall be assumed.

1

3. ./wc [-c | -l | -w] [file...]

(20 points) The wc utility shall read one or more input files and, by default, write the number of newlines, words, and bytes contained in each input file to the standard output. The utility also shall write a total count for all named files, if more than one input file is specified. The wc utility shall consider a word to be a non-zero-length string of characters delimited by white space. If no file operand is specified, or when file is -, then standard input is assumed.

-c: Write to the standard output the number of bytes in each input file. -l: Write to the standard output the number of newlines in each input file. -w: Write to the standard output the number of words in each input file.

./true ./false

(20 points) The true utility shall return with exit code EXIT SUCCESS. The false utility shall return with exit code EXIT FAILURE.

./env (20 points) The env utility prints all of the currently set environmental variables to standard output.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!