CSCI 330 - Assignment 2 Man pages
(Total points for complete assignment 50 points)
Due Monday 25 Sept. 2017, Mid-Night

For this assignment, create a 330 directory.

  • mkdir 330

    and change permissions so only you can access it, either

  • chmod 700 330
    or
  • chmod u=rwx,go=   330

    #Because there is nothing to the right of go= , this turns off all permission for group and other.

    Change to your 330 directory and do all work there.

    Use the man command to read about each command and desired feature listed in the problems below. When you believe you have the right answer, use one of the editors and enter the answer into a file called assn02.sh You can run the answers from your file to test if they are correct. If an answer is wrong, simply edit your answer and re-run the command.

    Start by creating assn02 as an empty executable shell file. Use the following commands at the prompt:

    touch assn02
    chmod 700 assn02

    To use the new file for the assignment, open the assn02.sh file, enter the command, options, and arguments for the problem you are working on, save the file and quit.

    You have created a shell script file.

    To test the command, at the prompt, enter:

    ./assn02.sh

    If the syntax is correct, your command will run and you can check the output to see if your option choices are correct. If you find something is incorrect, open the file, edit the command line, save and quit, and run it again. Once you have answered a problem, comment out the command line for that problem (see below) and work on the next problem. By commenting out each problem as you solve it, you will be able to put all solutions in the one file and still test them one by one.

    The assn02.sh file should contain the following information.

    The first line in assn02.sh should contain on the line by itself (no spaces or tabs).

    #!/bin/bash

    This is sometimes referred to as the shebang, and it indicates to the command interpreter how to interpret commands found in the file.

    The subsequent lines in the file may be command sequences and/or comments.

    To find a solution to a particular problem, use man on the command being studied. The man page gives a basic synopsis of what a command does and available options that modify that behavior.

    It lists both the standard Unix style options, single hyphen followed by a character, and the Linux style options, a double hyphen and a descriptive word.

    Where possible use the single hyphen version. But is it possible that a particular option is only available as a Linux style option.

    For each problem :

    You can save some typing by creating a couple of shell variables to hold path to the test data and the check data directories . Under the shebang line, enter the following. You may use these variables rather than typing long path info in your command sequences. Because these are local, when the shell-script terminates, they will be forgotten each time the program terminates.

    You may use different variable names but, keep in mind, PATH is already in use. When creating local temporary variable, using lower case is common practice. Unix is case sensitive, so you must reference the variable exactly like you declared it.

    Redirect output to a separate file for each command. Use the format 1a.out, 1b.out, etc. for each command. This will allow you to use diff to compare your output with a set of check files I'll set up.

    A solution will look something like this. Note the use of $data variable and redirection. :

    The answer file will look something like this: assn02.ex

    Remember, when using a local variable to remember the path to the test data, DON'T use the ~berezin/Assns or /home/hopper/berezin/Data before the filename. That is what the local variable provides.

    After diff checks your output, take the time to actually look at the output, to familiarize yourself with what the commands/options do. For small files, you can cat the file to the screen, for larger files, use less.

    Problems

    1. cat - concatenate the contents of the file or files listed as arguments to standard output.
    Apply cat to ~berezin/Data/data02.txt

    What option or options

    2. diff - diff compares two text files given as arguments and indicates the differences between them. First run diff with the specified arguments but without any option[s] to have see the default behavior of diff. Use data02.dif1 and data02.dif2 for the two files to differentiate. Take moment to look at diff.txt using the following three commands.

    cat diff.txt

    cat -vet diff.txt

    less diff.txt

    Then for each option question, compare $data/data02.dif1 to $data/data02.dif2 using the option that matches the problem. The files have been designed so that certain lines will disappear from the output of diff if they match according to the correct option choice. Remember to redirect output to the .out files.

    You can view the output files with less. Because these files contain some non-printable characters, you will warnings like the following :

    "2a.out" may be a binary file.  See it anyway?
    
    Hit the y key to continue.

    What option or options

    3. finger - finger retrieves information about users on a system. When run by itself, it displays minimum information about their login session.

    On the other hand, when applied to a specific user, it gives additional information, including a user's .plan file, if it has been created. It will do this even if the user is not logged on.

    What option or options

    4. grep - global regular expression parser. grep will search one or more files and find all lines that contain a string of characters that match a pattern (regular expression) defined by user. Look for the string "assign" in the file or files specified in the problems below. Your command will look something like: You can do the following in the answer file to save some typing if you know how to copy and paste.

    In preparation, run the grep with no options separately on three files, data02u.txt, data02n.txt, and data02ps.txt.

    Immediately follow each run with :

    This will show you the default results of the command's execution and also show its success status.

    echo $? displays the success status of the last run command, 0 = success, a non-zero is failure. Depending on the program, a specific value tells what the failure is.

    Note status.

    Note status.

    Note status.

    Do NOT run any other commands between the grep and the echo $?

    For grep, what option or options


    5. tail - display the last few lines of a text file. How many lines or where to start displaying from can be controlled by various options. Apply tail to ~berezin/Data/taild. Start by trying it with no options.

    What option or options

    6. ls - list the contents of the current or specified directory file. Its options determine how much and in what format that information is revealed. Apply ls to ~berezin/Data/d2 directory.

    What option or options


    7. sort - sort the contents of one or more text files. Apply sort to ~berezin/Data/data02s.txt

    What option or options

    8. od - (octal dump) displays the contents of a file, text or binary, in a readable format. By default, od displays each byte as a three digit octal value, even readable text.
    Use traditional options.

    Apply od to data02h.txt.

    What option or options

    9. pr - pr(int) (display) the contents of a text file formatted for printing. Usually breaks pages at 66 lines rather than 24 (screen length) and puts a header with a page count..

    Apply pr to the output of ls on /bin

    What option or options 10. tr - tr(anslate) characters in a text file into another set of characters. tr usually takes two lists of characters and matches them. If a character in the text file is found in the first list at a particular position, it is replaced by the character found in the second list in the exact same position. Besides translating characters into other characters, tr can also delete a list of characters.

    Important 'feature' of tr is that it reads from standard input, keyboard, and write to standard output, screen. So you must use redirection in, <, to specify file being translated and redirection out, >, to specify the file to store results in.

    Apply tr to /etc/profile

    What option, options, and/or arguments

    11. cut - cut specific columns of data from a file.

    What option or options

    12. date - displays today's day and date up to the second in a human friendly manner. However, what info is shown and in what format can be varied. Read both the date man page and the strftime (string format for time). The second man page represents not a command but a function that date invokes and it lists all formats available.

    What option or options

    13. ps - lists the processes (commands) running on the system.

    What option or options

    14. stty - set terminal type allows user to view or set the properties of the terminal. For example, you can change the definition of the erase key or reset the terminal. stty treats all arguments like options and its syntax differs from other commands. For many of the options, you can give the option with or without a hyphen. Without the hyphen, the option turns on a feature, with the hyphen, the option turns off a feature.

    Run stty with its options.

    What option or options

    15. split - splits a file into multiple files. Complement of cat, split breaks a file into smaller files.

    Split will generate a set of files, xaa, xab, xac, etc. so that is what to look for when the file is run. Make sure you Don't any other files starting with x and do a rm x* between each option trial.

    For steps a-c, use data02.txt

    What option or options

    Handing in the assignment

    For this assignment, you will create the file assn02 with your answers recorded in it as a set of executable lines.

    Email the results to me on turing or hopper.

    mutt -s assn02 berezin < assn02

    Note that if this is successful, there will be no response. I will start reviewing my email on turing and hopper and respond when I've received something from you.