Assignment 3

The Pipes Are Full Of Cats


Sep 21
40 pts
Oct 5
Create plain text files, one for each part. Do not use a text editor. Each should be created by a single Unix command, except #3, which you may create in two steps.
  1. A file containing the first line of every plain file in /etc. For any which cannot be read (sub-directories, or where you don't have permission), make sure the appropriate error message appears. It's intended that you operate on the contents of /etc itself, not the whole tree, so sub-directories of /etc will just show an error message, but that message should be in the file.
  2. Exactly the 10th line of the password file. (Think head followed by tail in the same pipe.)
  3. Make sure you have the lsof command. If not, install it or just use Sandbox. The lsof command lists all open files. Create a list of all files opened by one of your processes, and sorted by the command which opened the file. Make sure the file contains the lsof header at the top (which probably means you'll have to create this one in two steps).
  4. A file listing all running processes which are executing programs from either the /sbin or /usr/sbin directories, and sorted by the owner. Use ps -aux to list all the processes, and filter it with grep. It's easy to get the filtering grep itself in the list, even though grep is not located in /sbin. (Can you see why?) Make sure grep does not appear in your list. One simple way to do this is to send the output of the first grep through a second one that uses the -v option.
  5. Read the man page for sort (and feel free to Google about it). Produce a file which lists all the entries from /etc/passwd having home directories which are not under /home and sorted by the numerical user id (the third field in passwd). Make sure to use a numerical sort (otherwise 11 comes before 9).
  6. Read the documentation for the cut command, and produce a similar file, but showing only the userid, numeric uid, and the name (first, third, and fifth fields) separated by spaces. The name field may be blank. (Note that sort and cut need to specify many similar things, but use different option letters to do it. Different commands were created by different parties at different times, and it shows.)
Once you have created your files, send them to me here. If you create them on Sandbox, you can copy them off using WinSCP, FileZilla or any client that supports the scp protocol. Or if you're daring, you can just run this from Sandbox: