Title: Final Exam
Course: CIS 121: Linux/UNIX I: Fundamentals ~ For IGNITE Review

Q: Special Instruction 1: When answering these questions, do not change your directory (use cd) unless instructed to do so. Also, do not use awk. Ask your instructor if you have a question about this. Indicate that you understand this by checking "TRUE" and earn one extra credit.
- True
- False
A: True

Q: Special Instruction 2: Do not put an unnessary "dot slash" (./) in front of a path. i.e. if "mydir/fileX" would work do not enter "./mydir/fileX" Ask your instructor if you have a question about this. Indicate that you understand this by checking "TRUE" and earn one extra credit point.
- True
- False
A: True

Q: Special Instruction 3: Do not place an unnecessary slash(/) after a path. i.e. if the path "dir1/dir2" works do not use "dir1/dir2/" Ask your instructor if you have a question about this. Indicate that you understand this by checking "TRUE" and earn one extra credit point.
- True
- False
A: True

Q: Special Instruction 4: When using pipes(|) or redirection (<,>,>>) please place a space before and after the symbol unless such a space would change the meaning. Mark this TRUE for one extra credit point.
- True
- False
A: True

Q: When was UNIX developed?
A: 1969 / 69 / !969-71 / 69-71
If wrong: Unix was developed in 1969 and became available in 1971.

Q: What two people were the primary developers of the UNIX operating system?
A: Dennis Ritchie and Kenneth Thompson / Ken Thompson & Dennis Ritchie / Kenneth Thompson, Dennis Ritchie / Dennis Ritchie and Ken Thompson / Ken Thompson and Dennis Ritchie / Dennis Ritchie, Kenneth Thompson / Ken Thompson Dennis Ritchie / Dennis Ritchie, Ken Thompson / Ken Thompson, Dennis Ritchie / Kenneth Thompson and Dennis Ritchie / Dennis Ritchie & Ken Thompson / Dennis Ritchie, and Kenneth Thompson
If wrong: Dennis Ritchie and Kenneth Thompson were the primary UNIX developers.

Q: The next 7 questions are based upon the following material:

Assume your current working directory is "anywhere" in the above diagram. Enter a single command that will create three separate directories in your current directory called "mickey", "goofy", and "pluto".
A: mkdir -p mickey goofy pluto / mkdir mickey goofy pluto / mkdir ./mickey ./goofy ./pluto / mkdir {mickey ,goofy, pluto} / mkdir {micky,goofy,pluto} / mkdir ./{mickey,goofy,pluto} / mkdir mickey/ goofy/ pluto/ / mkdir -p ./{mickey,goofy,pluto} / mkdir goofy mickey pluto / mkdir -p {mickey, goofy, pluto}

Q: Assume your current working directory is "anywhere" in the above diagram. Enter the command to delete directory "dir7".
A: rm -r dir2/dir6/dir7 / rmdir dir2/dir6/dir7 / rm -r ./dir2/dir6/dir7 / rmdir ./dir2/dir6/dir7 / rm -rf dir2/dir6/dir7 / rm -fr dir2/dir6/dir7 / rm -ri dir2/dir6/dir7 / rm -ir dir2/dir6/dir7 / rmdir -i dir2/dir6/dir7

Q: Assume your current working directory is "anywhere" in the above diagram. Enter the command to display the contents of file "file4".
A: cat dir2/file4 / cat ./dir2/file4 / less dir2/file4 / more dir2/file4 / pg dir2/file4 / cut -f1- dir2/file4 / grep ".*" dir2/file4 / sed -n '1,$p' dir2/file4 / awk '{print $0}' dir2/file4 / cat dir2/file4 | more / cat /dir2/file2 | more

Q: Assume your current working directory is "anywhere" in the above diagram. Enter the command to change your working directory to "dir6".
A: cd dir2/dir6 / cd ./dir2/dir6 / cd dir2; cd dir6 / cd ./dir2; cd ./dir6

Q: Assume your current working directory is "dir6" in the above diagram. Enter the command to rename "file4" to "newfile". "newfile" should remain in the same directory it was in before it was renamed.
A: mv ../file4 ../newfile

Q: Assume your current working directory is "dir6" in the above diagram. Enter the command to search for all lines containing the pattern "joe", ignoring case, in all files in directory dir6.
A: grep -i "joe" * / grep "[jJ][oO][eE]" * / grep -i 'joe' * / grep '[jJ][oO][eE]' * / grep -i joe * / grep -i 'joe' file7 / cat * | grep -i 'joe' / grep -li joe * / grep -i joe ./* / grep -i 'joe' ./* / cat * .* | grep -i 'joe' / grep -i "joe" * .* / cat * | grep -i "joe" / grep -i "joe" ./* / grep -iw 'joe' * / grep -wi 'joe' * / cat * | grep -i joe

Q: Assume your current working directory is "dir6" in the above diagram. Enter the command to delete all files in the directory "dir5". Use wildcards.
A: rm ../dir5/* / rm ../dir5/file[56] / rm ../dir5/file? / rm ../dir5/f* / rm ../dir5/file* / rm ../dir5/* ../dir5/.* / rm -i ../dir5/* / rm ../dir5/file{5,6} / rm -i ../dir5/* ../dir5/.*

Q: Give an example where you would use a variable name "var" without the $ prefix (e.g. $var).
A: set var=value / var=value / export var / unset var / read var / for var in set... / let c=a+b / when you are creating or exporting variables / To set the variable's contents / when assigning the variable / When setting or reading into the variable (e.g. var1=42) / var=5 / var='when you set it as something' / var=42 / In a script when using the read command / I would use var to define a variable; example var=123 / var = "generic variable" - assignment statements do not use the $ prefix / read var (entering user input in a shell script) / When introducing the variable in a script for the first time with the read command. / When setting the variable / When reading in to a variable in a script. / When you create the variable using the syntax varname=varvalue / $(( var + 6 )) / after the read command / when you are assigning a value to the variable. 'read var' / When you are defining the variable. / var=10 / var= / when defining a variable

Q: Write a command to create a hard link called "hlink" in the parent directory of your current directory. The new hard link should point to a file called "myfile", which is in a directory "dir2", which is a sub-directory of "dir1", which is under your current directory.
A: ln dir1/dir2/myfile ../hlink / ln ./dir1/dir2/myfile ../hlink / ln ./dir2/dir1/myfile ../hlink

Q: Write a command to list all files and directories in the home directory of user "newguy" including hidden files. Do not list the contents of the subdirectories. You do not know the home directory path of "newguy". Do not change directories.
A: ls -a ~newguy / ls -a ~newguy/ / ls -pa ~newguy / ls -pa ~newguy/ / ls -pad ~newguy/* ~newguy/.* / ls -Fa ~newguy / ls -Fa ~newguy/ / ls -Fad ~newguy/* ~newguy/.* / ls -d ~newguy/* ~newguy/.* / ls -al ~newguy / ls -al ~newguy/* / ls -dl ~newguy/.* ~newguy/* / ls -d ~newguy/* ~newguy/.[!.]* / ls -la ~newguy / ls ~newguy/* ~newguy/.* / ls -ld ~newguy/* ~newguy/.* / ls ~newguy ~newguy/.* / ls -l ~newguy/* ~newguy/.* / ls -d ~newguy/.* ~newguy/*

Q: Write a single command (no pipes) to search the contents of all the files in your subdirectory "fred" for lines that have the word "wilma" or "Wilma" in them. The subdirectory "fred" is under your current directory.
A: grep -w [wW]ilma fred/* / grep -w '[wW]ilma' fred/* / grep -w "[wW]ilma" fred/* / grep -w [wW]ilma ./fred/* / grep -w "[wW]ilma" ./fred/* / grep -w '[wW]ilma' ./fred/* / grep -iw "wilma" fred/* / grep -wi wilma fred/* / grep -wi 'wilma' fred/* / grep -wi "wilma" fred/* / grep -w '[W,w]ilma' fred/* / grep -iw 'wilma' fred/*

Q: Write the command to copy all files with names ending in "XX" from your subdirectory "mysub" to your parent directory. "mysub" is a subdirectory of your current directory.
A: cp mysub/*XX .. / cp mysub/*XX ../ / cp mysub/*XX ../. / cp ./mysub/*XX .. / cp ./mysub/*XX ../ / cp ./mysub/*XX ../. / cp mysub/*XX mysub/.*XX ../ / cp -i mysub/*XX ../

Q: Write the command sequence to display a list of users who are logged into the system. Names only (e.g. user-id). No name appearing more than once. Do not create any files, instead use pipes. Do not send any information to the printer. Assume that user names are found in the first field and are always 8 characters or less.
A: who | cut -d" " -f1 | sort -u / who | cut -d' ' -f1 | sort -u / who | cut -d" " -f1 | sort | uniq / who | cut -d' ' -f1 | sort | uniq / who | cut -c1-8 | sort -u / who | cut -c-8 | sort -u / who | cut -c1-8 | sort | uniq / who | cut -c-8 | sort | uniq / who | awk '{print $1}' | sort -u / who | awk '{print $1}' | sort | uniq / who | sed 's/ *//g' | sort | uniq / w | cut -c-8 | sort -u / who | cut -c1-8 | sort | uniq | more

Q: I created a new file in the last 24 hours using vi. I can't remember what I called it or where in my home directory structure I put it. What command can I use to find it? Assume that the command should work from anywhere on the system.
A: find ~ -mtime -1 / find ~ -mtime -1 -name "*" / find ~ -name "*" -mtime -1 / find $HOME -mtime -1 / find $HOME -mtime -1 -name "*" / find $HOME -name "*" -mtime -1 / find ~/ -mtime -1 / find ~ -mtime -1 -print

Q: List all files and directory names in your current directory or below it that end in ".c". Do not list any other file or directory names. Single command. No pipes.
A: find . -name "*.c" / find . -name '*.c' / find ./ -name "*.c" / find ./ -name '*.c' / find -name "*.c" / find -name '*.c' / ls -pR * | grep "\.c$" / find . -name '*.c' -print

Q: Write a command to delete all files in your current directory that have an 'a' or an 'A' in their names. You want to be able to verify(y or n) each removal.
A: rm -i *[Aa]* / rm -i *[aA]* / rm -i *a* *A* / rm -i *A* *a* / rm -i *[a]* *[A]* / rm -i *[A]* *[a]* / rm -i *[aA]* .*[aA]* / rm -i *{A,a}* / rm -i ./*[Aa]*

Q: Write a command to display the contents of the file called "emotions" with all occurrences of the pattern "hate" changed to "love". Do not change any other characters, words, sequences, or phrases.
A: sed 's/hate/love/g' emotions / sed "s/hate/love/g" emotions / sed s/hate/love/g emotions / cat emotions | sed 's/hate/love/g' / cat emotions | sed "s/hate/love/g" / cat emotions | sed s/hate/love/g' / cat emotions | sed 's/'hate'/'love'/g' / cat emotions | sed s'/hate/love/g' / sed 's/hate/love/g' < emotions / sed 's/hate/love/g' emotions | more / more emotions | sed 's/hate/love/g' / sed s/hate/love/g < emotions

Q: Move all files that start with an uppercase character to the parent directory of your current directory EXCEPT for ones that begin with the letter "M".
A: mv [A-LN-Z]* .. / mv [A-LN-Z]* ../ / mv [A-LN-Z]* ../. / mv [A-LN-Z]* ./.. / mv [A-LN-Z]* ./../ / mv [A-LN-Z]* ./../. / mv [ABCDEFGHIJKLNOPQRSTUVWXYZ]* .. / mv [ABCDEFGHIJKLNOPQRSTUVWXYZ]* ../ / mv [ABCDEFGHIJKLNOPQRSTUVWXYZ]* ../. / mv [A-L]* [N-Z]* .. / mv ./[ABCDEFGHIJKLNOPQRSTUVWXYZ]* ../ / mv [ABCDEFGHIJKLNOPQRYSTVWXYZ]* ../ / mv [ABCDEFGHIJKLNOPQRSTUVWXYZ]* ../* / mv [ABCDEFGHIJKLNOPQRSTUVWQYZ]* ../. / mv [ABCDEFGHIJLKNOPQRSTUVWXYZ]* .. / mv [THEQUICKBROWNFOXJUPSOVERTHELAZYDOG]* ../ / mv ./[ABCDEFGHIJKLNOPQRSTUVWXYZ]* ..

Q: Write a command to compress the file "bigstuff".
A: compress bigstuff / gzip bigstuff / zip bigstuff bigstuff / zip bigstuff.zip bigstuff / tar w/ valid options / compress -v bigstuff

Q: Start the script s10 in the background. Assume that your $PATH does not hold your current working directory.
A: ./s10 & / nohup ./s10 & / . ./s10 & / bash s10 & / ksh s10 & / sh s10 &

Q: Now stop(pause or suspend) your background job. (Do not use the kill command.) Remember this a two step process.
A: fg; ctrl-z / fg; ctrl-Z / fg job#; ctrl-z / fg job#; ctrl-Z / fg %job#; ctrl-z

Q: Write a command that displays the contents of the file "cdata", completely replacing every line that starts with a digit with the word "deleted". The results are displayed (standard out), but the original file ("cdata") is not to be changed.
A: sed s/^[0-9].*$/deleted/ cdata / sed s/^[0-9].*/deleted/ cdata / sed 's/^[0-9].*$/deleted/' cdata / sed 's/^[0-9].*/deleted/' cdata / sed "s/^[0-9].*$/deleted/" cdata / sed "s/^[0-9].*/deleted/" cdata / sed "/^[0-9]/s/.*/deleted/" cdata

Q: Write just a regular expression (not a complete command) that matches sequences that contain only two upper or lower case alphabetic letters. Do not use quotes in your answer.
A: [a-zA-Z][a-zA-Z] / [A-Za-z][A-Za-z] / [a-zA-Z][A-Za-z] / [A-Za-z][a-zA-Z] / grep [a-zA-Z][a-zA-Z] / [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]

Q: Write just a regular expression that matches all LINES that end with the pattern: xyzzy (Match the entire line).
A: ^.*xyzzy$ / .*xyzzy$ / '^.*xyzzy$' / '.*xyzzy$' / "^.*xyzzy$" / ".*xyzzy$"

Q: In sentence form, describe exactly what the following REGULAR EXPRESSION matches.

ab.*ab
Feedback: The pattern abab with anything between the first ab and the last ab.

Q: In sentence form, describe exactly what the following REGULAR EXPRESSION matches.

^HELP
Feedback: HELP at the beginning of the line.

Q: In sentence form, describe exactly what the following REGULAR EXPRESSION matches.

[Hh]ello[^0-9]
Feedback: Six characters consisting of an upper or lower case "H" followed by "ello" followed by any character except a digit.

Q: Write a script that prompts for a filename. It should then copy the file to a directory in the current directory called "backups". The new file should have the same name.
Feedback: echo "Enter a filename : " read fname cp $fname backups

Q: Write a script that reports the current date and how many users are currently logged in. It should inform about what is being displayed.
Feedback: echo Todays date is date echo The current number of users logged in is who | wc -l

Q: Write the command(s) to display lines that are in file "random1" but not in the file "random2". You may assume that these are randomly arranged text files that need sorting.
Feedback: sort random1 > r1 sort random2 > r2 comm -23 r1 r2

Q: In vi, what command will allow you to save your file to a new file called bozo? Do not exit vi.
A: :w bozo / &ltesc&gt:w bozo / [ESC] :w bozo / :w bozo <enter>

Q: What are three vi commands you can enter to get into input mode?
A: a A o O i I R / I, i, a / i, a, A / i a A / i o a / I, i, A, a, O, o / i I a / i I o / a, i , I / A, I, O / i,a,o / i a o / i,I,o / a o i / i, capital i, A / I, i, and a / i I or a / i, a, I / a I o / i, a, and A / i and a and o / i, a, o, / a i A / a,A,i / i, o, a / i a R / i a I / i, I, R / i or a or I / i, A, R / O or o or A / I ; A ; O / a O o

Q: Write a command to email the file called "helpme" to user c12111.
A: mail c12111 < helpme / cat helpme | mail c12111 / tee < helpme | mail c12111 / mailx c12111 < helpme / cat helpme | mailx c12111

Q: Write the vi command to exit WITHOUT saving your changes. (Assume that you have made changes.)
A: :q! / [ESC] :q! / <esc>:q! / escape to get to command mode, :q!

Q: When in the vi editor, how can I delete 27 lines in one command?
A: 27dd / :1,27d

Q: How do I display all files with names staring with a lowercase letter and ending in 2001,2002, or 2003? Assume the files are located in the home directory of user "jsmith" and your current working directory is somewhere else.
A: ls ~jsmith/[a-z]*200[1-3] / ls -l ~jsmith/[a-z]*200[123] / ls -R ~jsmith | grep "^[a-z].*200[1-3]$" / ls -Rl ~jsmith | grep " [a-z].*200[123]$" / cd ~jsmith | echo [a-z]*200[1-3] / find ~jsmith -name "[a-z]*200[123]" / ls ~jsmith/[a-z]*200[123] / ls ~jsmith/[a-z]*{2001,2002,2003} / ls -al ~jsmith/[a-z]*200[1-3] / ls -l ~jsmith/[a-z]*{2001,2002,2003} / ls -a ~jsmith/[a-z]*200[123] / ls ~jsmith/[a-z]*200{1,2,3} / ls -d ~jsmith/[a-z]*{2001,2002,2003} / ls -d ~jsmith/[a-z]*200[123] / ls -d ~jsmith/[a-z]*200[1-3] / ls -l ~jsmith/[a-z]*200{1,2,3} / ls -la ~jsmith/[a-z]*200[123] / ls ~jsmith/[abcdefghijklmnopqrstuvwxyz]*{2001,2002,2003} / ls -l ~jsmith/[a-z]*200[1-3]

Q: Write a command to set the permissions on the file "myfile" to -rwxr-xr-- using numeric parameters (octal numbers) to set the the permissions.
A: chmod 754 myfile / chmod 0754 myfile

Q: Write a command to set the permissions on the file "myfile" to -rw-rw-r-- using classes (characters, not octal numbers) to set the permissions.
A: chmod u=rw,g=rw,o=r myfile / chmod ug=rw,o=r myfile / chmod a=r,ug+w myfile / chmod a=rw,o-w myfile / chmod a=r,ug=w myfile

Q: Write a series of commands to change the ownership of the file called "changeMe" to "frisco", the group to "hisGroup", and the permissions to rwx rw- ---.
Feedback: chmod 760 changeMe chgrp hisGroup changeMe chown frisco changeMe

Q: If umask is set to 027 and a file has permissions of rwxrw-rw-, after you copy it, what are the permissions (IN OCTAL) of the new file?
A: 740 / the perms are 740

Q: Write a command to start running the script "myScript". The standard output should be appended to the file called "addHere". While the standard errors should not appear on the screen but be discarded. Assume both files are located in your current directory. Assume "myScript" file is executable.
A: myScript >>addHere 2>/dev/null / ./myScript >>addHere 2>/dev/null / . myScript >>addHere 2>/dev/null / bash myScript >>addHere 2>/dev/null / bash -x myScript >>addHere 2>/dev/null / myScript >> addHere 2> dev/null / ./myScript >>addHere 2> /dev/null/ / ./myScript >> addHere 2>dev/null / ./myScript 2> /dev/null >> addHere / ./myScript 1>> addHere 2> /dev/null / ./myScript 2> dev/null >> addHere

Q: You are in a directory that contains the "tfile" file . List "tfile" but change every occurrence of the patterns "lave", "live", and "luve" to the pattern "love". Do not change any other words, sequences, or phrases.
A: sed 's/l[aiu]ve/love/g' tfile / sed "s/l[aiu]ve/love/g" tfile / cat tfile | sed 's/l[aiu]ve/love/g' / cat tfile | sed "s/l[aiu]ve/love/g" / sed 's/lave/love/g' tfile | sed 's/live/love/g' | sed 's/luve/love/g' / cat tfile | sed 's/'l[aiu]ve'/'love'/g' / cat tfile | sed 's/lave/love/g' | sed 's/live/love/g' | sed 's/luve/love/g' / sed 's/l[aiu]ve/love/g' < tfile / sed 's/l[uia]ve/love/g' tfile / cat tfile | sed 's/l[uia]ve/love/g'

Q: You are in a directory that contains only text files. Display the contents of files in this directory that have at least three characters in their names.
A: cat ???* sed -n '/.*/ p' ???* / cat ???* / more ???* / cat *???* / grep '^.*$' ???* / cat *??? / cat ???* .[!.]?* / cat ???* | more / less ???* / cat ./???* / cat *???* | more

Q: Write a command to find all files with names beginning with CIS121 under your parent directory or its sub-directories that have been modified within the last week.
A: find .. -name 'CIS121*' -mtime -7 / find .. -mtime -7 -name 'CIS121*' / find .. -name "CIS121*" -mtime -7 / find .. -mtime -7 -name "CIS121*" / find ../ -name 'CIS121*' -mtime -7 / find ../ -mtime -7 -name 'CIS121*' / find ../ -name "CIS121*" -mtime -7 / find ../ -mtime -7 -name "CIS121*"

Q: Display the status of all partitions on your current system. You want to know the size of each partition and how full it is.
A: df / df -k / df -h / df -kh

Q: Write a command that will tell any user how many blocks of data they are using in and below their home directory. They do not want to see detail, just the summary number.
A: du -s ~ / du -s $HOME

Q: Send the file "mydata" to the users "moe", "larry" and "curly" as a mail message.
A: mail moe larry curly < mydata / cat mydata | mail moe larry curly / mailx moe, larry, curly < mydata / mail moe,larry,curly<mydata / mailx moe larry curly < mydata / cat mydata | mail larry curly moe / mail larry moe curly < mydata / mail moe larry, curly < mydata / cat mydata | mail moe, larry, curly / cat mydata | mail {moe,larry,curly} / cat mydata | mailx moe, larry, curly

Q: Start the program "mylongprog" running in the background with the output going to a file called myout. You want it to have a low priority on the system.
A: nice -n 10 ./mylongprog > myout & / nice -n 20 ./mylongprog > myout &

Q: How do I set up a program called "runme" to run next Friday at 3:30 PM while I am in a meeting.
Feedback: at 3:30 pm Fri ./runme

Q: List all processes on the system with a long line of output on each.
A: ps -ef / ps -fe / ps -ef | more / ps -fe | more

Q: awk is:
- A scripting language.
- An extinct bird.
- A command to list all of your files
- A tool for making holes in things
- A command to report system usage.
A: A scripting language.

Q: Pine and elm are:
- commands to list files.
- programming languages that were popular in the 1980's.
- mail programs.
- made into Popsicle sticks.
- preferred by beavers for building dams.
A: mail programs.

Q: Phil's preferred method of getting to work (provided his bike and knees are working) is:
- Walking
- Running
- Driving
- Bicycling
- Flying
- Swimming
- Rolling
- Rolling
A: Bicycling

Q: Phil's jokes are always very funny and clever.
- Agree. He could make a living as a comedian. (I need the points.)
- Disagree. So much corn we could start an ethanol factory. (Phil respects honesty.)
- Jokes? What jokes?
A: Agree. He could make a living as a comedian. (I need the points.); Disagree. So much corn we could start an ethanol factory. (Phil respects honesty.); Jokes? What jokes?