271 Final Review Exercises
1. Write a shell script that does the following:
a. Verify that the script was called with one parameter, and exit with a code of three if there was no parameter sent.
b. Display the current directory
c. Create a new directory named as the parameter the script was called with.
d. Copy all the files in the following directory into the new directory you just created.
/home/pe16132/public_html/csc271/note/scripts/finalreview/one
e. List all the files in your new directory that have the word email in the filename.
f. Write a new file called sortedUpperExample with
i. all the lines in junk.txt that have the word "example" ,
ii. convert all the words to uppercase
iii. sort every line alphabetically
iv. (extra : only show the email address)
g. Copy emails.txt to junk.txt in your new directory
h. Rename the file emails.txt to newname.txt in your new directory
i. Add all the lines in emails5.txt to emails6.txt
j. Display every line of the file emails6.txt on the screen
k. Display the number of lines in junk.txt
l. Display the message "tons of addresses" if there are more than 5 lines in junk.txt otherwise say "very few addresses".
m. Change every occurrence of the word "example" or "sample" to TEAM in junk.txt , except: do not change the first line of the file. (Be sure to change multiple occurrences on one line.)
n. Change every email domain you find to holiday.com in junk.txt. (an email domain always follows @ and contains at least one period. : ex: Adelphi.edu.
2. Create one more alias in your .bashrc
3. Explain the difference between the inode table, file open table, and file descriptors.
4. File descriptors: What are the 3 standard file descriptors are for every process? How do you access them in bash scripts, perl scripts and c programs? Which file descriptor do you use to write to the screen and read from the screen? How can you override them from the command line?
5. When programming in C, in what order would you use the commands read, open, write, close, seek when you wanted to copy file1 to file2? Which commands will use the actual filename. Which commands will use the input file's file descriptor? Which commands will use the output file's descriptor? Which commands will share a string variable?
6. What is a make file?
7. What commands do you use to debug the following programs:
a. Bash script
b. Perl program
c. C program
8. What is the purpose of chomping a variable in Perl?
9. How do you access command line parameters in bash scripts, perl and c ?
10. For Perl: Study homework 1, 2 and 3 and your catalog.
11. Write a perl program that asks the user for a name and then searches an addressbook.txt file to print the first row that contains that name. Adjust this to take the name of the address book file from the command parameter. Also adjust it to ask for a name and a city and find the first row with both the name and city (and the name will follow the city). Then, print only the second column found. The file is comma separated.
12. Write a c program that reads one file and writes all of it to a new file. Then change the program to append one file to the other instead.
13. Write a c program that links a file, writes the word "good" starting in the 5th position of the original file and then unlinks the original file.
14. Explain what fork does and why you would use it.
15. Explain what exec does and why you would use it.
16. Give an example that shows what "everything is a file in unix" means.
17. Give an example of how unix uses the philosophy: do one thing and do it well.
18. Explain how the linux system uses fork and exec.