For this assignment, create a 330 directory.
and change permissions so only you can access it, either
#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 :
check="/home/hopper/berezin/Data/assn02_d"
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. :
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.
What option or options
1b. numbers the lines printed out BUT skips numbering blank lines.
1c. indicate where tabs are with ^I and where form-feeds are with ^L.
1d. prints a $ at the end of the text line. This is good for spotting trailing blanks.
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
2b. ignore all blanks.
2c. ignores trailing blanks and treats other blanks as being equal.
Note that there is a slight difference in the output between the two
problems (b and c) above.
2d. Produces a script that can be used by the ed editor to recreate the second file from the first file. Your .out file will probably be blank.
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
First run finger on user berezin with no options.
Then run it again with the option to suppress .plan
finger with no options will do a minimal listing of all users currently logged in. But it will not show any plans. Run finger with no arguments or options.
3b. Find the option that will make it show the more detailed display including the .plans if a logged in user who has created one.
Because the users logged in at any time constantly changes, the output file will not match mine. The output may be rather long, so use less to view the output file
Then look at my output from the command line. Type in the following or copy and paste it on the command line from this web page. :
less /home/hopper/berezin/Data/assn02_d/3b.out
In preparation, run the grep with no options separately on three files, data02u.txt, data02n.txt, and data02ps.txt.
Immediately follow each run with :
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.
Do NOT run any other commands between the grep and the echo $?
For grep, what option or options
Do the three greps above with the chosen option[s].
Remember to print the status also. Note that the output may change but the status should be consistent with the original test runs.
4b. does not print any standard output (matches).
Do the three greps above with the chosen option[s].
4c. count the number of lines that contain the string assign
Search ~berezin/Data/data02ps.txt
4d. ignore the case of the string being searched for.
Search ~berezin/Data/data02ps.txt
4e. print all lines that do NOT contain the regular expression.
Search ~berezin/Data/data02ps.txt
4f. print just the filename of the file containing the string matching
the regular expression. Use
~berezin/Data/data02*
for the file name.
Make sure you include the asterisk after data02
What option or options
5b. lets you specify by character count where to start printing from. Print from the 13th character from the end. Count the number of characters in the output. You will find that line feeds are counted.
5c. lets you specify by character count where to start printing from. Print from the 13th character from the beginning. You will find that line feeds are counted.
What option or options
6b. allows you to specify a directory name and displays the permissions of the directory rather than the permissions of contents of that directory.
6c. puts special symbols after directories, executables and linked filenames when listing them.
6d. displays the inode number next to the filename.
What option or options
7b. specifies the name to send the output to instead of to standard out.
Use mysort as the name of your output file
7c. causes lower case letters to be listed together with the upper case letters.
7d. sort on the second word on the line. Use the data02ps.txt file.
The second word is a number but it will still work. Note how it sorts.
All the 1's come first, then all the 2's.
Use data02ps.txt for 27.
7e. sort on the second word on the line but also sort so is numerically correct, 1-10 followed by 11-99, followed by 100-999, etc.
Use data02ps.txt for 27.
Apply od to data02h.txt.
What option or options
9b. displays the bytes of a file as hexadecimal numbers.
9c. displays the bytes of a file as decimal (base ten) numbers.
Apply pr to the output of ls on /bin
9b. lists line with a three digit wide line count in front and separate line count from line contents with a > Be careful to quote the >
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
10b. translate lower case a through f to upper case B through G.
What option or options
11b. get the sixth-field (word) from the file /etc/passwd. Use colon : as a delimiter. You may have to quote the colon.
What option or options
12b. prints only the hour data02.txt was last modified.
What option or options
13b. lists every single process running on the system with a full listing.
13c. lists only processes not related to a terminal.
Run stty with its options.
What option or options
(44)b. resets the terminal to a reasonable set of values. This may be useful if your terminal becomes garbled because of a bad connection or cat-ing an executable file.
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
# You should see 7 files xaa, xab, xac, xad, xae, xaf, xag. # Running wc x* in your work directory, should give :
7 23 219 xaa 7 27 281 xab 7 21 211 xac 7 36 347 xad 7 21 197 xae 7 22 218 xaf 42 150 1473 total |
(48)c. splits file into 3 files.
# Run wc x*, you should get :
13 50 491 xaa 13 50 491 xab 16 51 491 xac 42 151 1473 total |
170 1565 12288 xaa 141 1233 9166 xab 311 2798 21454 total |
Read the SIZE and CHUNK sections at the end of the options list in the man pages.
Email the results to me on turing or hopper.
mutt -s assn02 berezin < assn02
-s assn02 : sets the subject line.
berezin : my account ID on the local system
< assn02 : redirects input input from your assignment rather than from the keyboard.