day 2 review of itsk1601 – intro unix.. break up into cousin groups each cousin group will work as...
TRANSCRIPT
Day 2
Review of ITSK1601 – Intro Unix.
Break up into Cousin groups• Each cousin group will work as a team.
• Each team will need 5 blank sheets of paper.
• Be sure to write both cousins names at the top of each sheet of paper
• We will see 10 questions per round. Write your teams answers for all 10 questions on one page.– No late submissions of answers.– Only readable answers will be considered for credit.
10 pts extra credit possible.• You are working for 10 points of extra credit on the
first quiz.– If you get 50/50 questions correct, you would have 10 pts
added to your score on the first quiz.– 45/50 would get you 9 points.– 40/50 would get you 8 points– 35/50 would get you 7 points– 30/50 would get you 6 points– ……– 5/50 would get you 1 point.
Rules• While discussing your answer with your cousin, be
quiet so other teams cannot hear your answer.• No partial credit will be given for partially correct
answers. You gotta get it right.• Answer must be readable• You may use any notes/books/computer you want
during the game.• A correct answer may require the options which
would be passed to the command as well as the actual command.
• Judges (I.e. my) decision is final.
Round 1
Question 1• What UNIX command will show you help
information on a command?
Question 2• What UNIX command will show you a list of files
in the current directory?
Question 3• What UNIX command will show allow you to make
a copy of a file?
Question 4• What UNIX command will allow you change what
directory you are currently in?
Question 5• What UNIX command will change your current
directory to be one directory back from where you currently are?– e.g. You are currently in homeworks/hw1/answers. What
command would take you to homeworks/hw1
Question 6• What UNIX command will tell you the current
time?
Question 7• What UNIX command will show you the contents
of a file without stopping at each screen full? – I.e. What command dumps an entire file to the screen.
Question 8• What 2 UNIX commands will show you the
contents of a file but will stop at each screen full?
Question 9• What UNIX command is used to rename a file?
Question 10• What UNIX command is used to see the first 10
lines in a file?
Round 1
Answers
Question 1• What UNIX command will show you help
information on a command?
• man
Question 2• What UNIX command will show you a list of files
in the current directory?
• ls
Question 3• What UNIX command will show allow you to make
a copy of a file?
• cp
Question 4• What UNIX command will allow you change what
directory you are currently in?
• cd
Question 5• What UNIX command will change your current
directory to be one directory back from where you currently are?– e.g. You are currently in homeworks/hw1/answers. What
command would take you to homeworks/hw1
• cd ..
Question 6• What UNIX command will tell you the current
time?
• date
Question 7• What UNIX command will show you the contents
of a file without stopping at each screen full? – I.e. What command dumps an entire file to the screen.
• cat
Question 8• What 2 UNIX commands will show you the
contents of a file but will stop at each screen full?
• more and less
Question 9• What UNIX command is used to rename a file?
• mv
Question 10• What UNIX command is used to see the first 10
lines in a file?
• head
Round 2
Question 1• What UNIX command will allow you to make a
directory called Enda
Question 2• What UNIX command will remove a directory
called Enda. You can assume the directory is in the current directory and is already empty
Question 3• What UNIX command will delete the file called
Bob. You can assume Bob is in the current directory
Question 4• What UNIX command will tell you how many
words are in a file?
Question 5• What UNIX command will allow you to run an
interactive chat session with another user on your system?
Question 6• What UNIX command will show you what the user
enda is currently doing? I.e. what commands they are currently running. Assume you are not enda.
Question 7• What UNIX command will show you the
differences between the file 1.txt and 2.txt.
Question 8• What UNIX command will show you a calendar for
the month of May, 2001?
Question 9• What UNIX command repeats some text to the
screen?
Question 10• What UNIX command is used to view electronic
email?– There is more than 1 correct answer here.
Round 2
Answers
Question 1• What UNIX command will allow you to make a
directory called Enda
• mkdir Enda
Question 2• What UNIX command will remove a directory
called Enda. You can assume the directory is in the current directory and is already empty
• rmdir Enda
Question 3• What UNIX command will delete the file called
Bob. You can assume Bob is in the current directory
• rm Bob
Question 4• What UNIX command will tell you how many
words are in a file?
• wc –w <filename>
• I’ll accept just wc
Question 5• What UNIX command will allow you to run an
interactive chat session with another user on your system?
• talk
Question 6• What UNIX command will show you what the user
enda is currently doing? I.e. what commands they are currently running. Assume you are not enda.
• w enda
Question 7• What UNIX command will show you the
differences between the file 1.txt and 2.txt.
• diff 1.txt 2.txt
Question 8• What UNIX command will show you a calendar for
the month of May, 2001?
• cal 5 2001
Question 9• What UNIX command repeats some text to the
screen?
• echo
Question 10• What UNIX command is used to view electronic
email?– There is more than 1 correct answer here.
• pine
• elm
Round 3
Question 1• What EXACT UNIX command will delete the
directory homeworks and all files/subdirectories contained within.– You can assume homeworks is located in your current
directory
Question 2• What exact UNIX command will move all files in
the current directory who’s name begins with tex to the directory tex-files.– You may assume tex-files already exists, and is located
in the current directory
Question 3• What exact UNIX command would delete any file
which has a x in its file name, in this directory or any sub directory?
Question 4• What UNIX command will take the first 23 lines of
every file in the current directory and put them into a new file called first-lines.
Question 5• What UNIX command will make the file public.txt
readable to everyone on the system?– You may assume the file is in your current directory
Question 6• Assume you have a file (x.txt) which looks like this:
27 chocolate
32 mint
33 orange
99 lemon
100coffee
• What command would return the file showing the items sorted numerically ascending by the number at the front of each line
Question 7• 2 different people need to be able to edit the same
file. The file is currently located in /files/a.txt.
• Each user should see the file in their home directory.
• If either user edits their file, they should be editing the actual file /files/a.txt
• What Unix command would you need to type in each users home directory to make this true?
Question 8• What Unix command would allow you to search for
all occurances of the text Edna and replace it with the Enda in the file mylife.txt
Question 9• What SINGLE Unix command would show you any
messages in the logfile which contain either the words kernel or the IP address 10.1.1.1– The messages file is located in /var/log/message
Question 10• What SINGLE Unix command would find only
lines in /var/log/messages which contain kernel AND 10.1.1.1
Round 3
Answers
Question 1• What EXACT UNIX command will delete the
directory homeworks and all files/subdirectories contained within.– You can assume homeworks is located in your current
directory
• rm –r homeworks
Question 2• What exact UNIX command will move all files in
the current directory who’s name begins with tex to the directory tex-files.– You may assume tex-files already exists, and is located
in the current directory
• mv tex* tex-files
Question 3• What exact UNIX command would delete any file
which has a x in its file name, in this directory or any sub directory?
• rm –r *x*
Question 4• What UNIX command will take the first 23 lines of
every file in the current directory and put them into a new file called first-lines.
• head –23 * > first-lines
Question 5• What UNIX command will make the file public.txt
readable to everyone on the system?– You may assume the file is in your current directory
• chmod a+r public.txt
Question 6• Assume you have a file (x.txt) which looks like this:
27 chocolate
32 mint
33 orange
99 lemon
100coffee
• What command would return the file showing the items sorted numerically ascending by the number at the front of each line
• sort –n x.txt
Question 7• 2 different people need to be able to edit the same
file. The file is currently located in /files/a.txt.
• Each user should see the file in their home directory.
• If either user edits their file, they should be editing the actual file /files/a.txt
• What Unix command would you need to type in each users home directory to make this true?
• ln (-s) /files/a.txt .
Question 8• What Unix command would allow you to search for
all occurances of the text Edna and replace it with the Enda in the file mylife.txt
• sed s/Edna/Enda/g mylife.txt
Question 9• What SINGLE Unix command would show you any
messages in the logfile which contain either the words kernel or the IP address 10.1.1.1– The messages file is located in /var/log/message
• egrep ‘kernel|10.1.1.1’ /var/log/messages
Question 10• What SINGLE Unix command would find only
lines in /var/log/messages which contain kernel AND 10.1.1.1
• grep kernel /var/log/messages | grep 10.1.1.1
Round 4
Question 1• Imagine you have a directory with the following
permissions:
• Can users who are a member of the group managers see a list of all files in that directory?– Why? Why Not?
drwx--x--x 2 enda users 4096 Mar 21 13:06 scripts
Question 2• If you have a file called important.txt and you want
to make sure that you cannot delete it. How can you change its permissions to help prevent this?
Question 3• How could you use the command who to find out a
list of all users who are currently logged on. – Show no additional information other than username– Ensure that each username is only output once even if
they are logged in multiple times
Question 4• What UNIX command will look for any the word
Enda in the file stuff.txt– Be sure you look for enda, Enda, ENDA etc.– Be sure you do not return words like calENDAr.
Question 5• What UNIX command would count how many
times the user enda logged in on May 14.– Use the last command to find this information.– Be sure you only look for enda’s information– Be sure you only look for entries on May 14.
Question 6• What SINGLE Unix command can you use to
make the following directory:– /home/enda/1/2/3/4/5/6/7/8/9– You may assume you are currently in /home/enda– None of the sub directories exist.
• I.e. Right now, in /home/enda there is now directory called 1.
Question 7• You have a file which contains a bunch of words.
– One word per line
• You want to see all words which begin with the letter c, but you need them in REVERSE alphabetical order.– Thus you should get:
• czar• cyclone• cutoff• count• club• cat
Question 8• What Unix command would append a copy of the
file 2.txt to the end of the file 1.txt?
Question 9• Imagine you only have the cat command, and the
ability to redirect
• You start with a file that has 10 lines in it.
• What is the least number of commands you could use to make a file with 1000+ lines in it?
• What command would you be running?
Question 10• Assume you are in vi in escape [command] mode
– How would you do each of the following in a single command:
a. Delete the next 100 lines
b. Add 10 blank lines beneath the current line
c. Find the next occurrence of the word Fido in the document
d. Find the matching close } to this open {.You can assume your cursor is on top of the { for this one.
Round 4
Answers
Question 1• Imagine you have a directory with the following
permissions:
• Can users who are a member of the group managers see a list of all files in that directory?– Why? Why Not?
• Nope, you require read permission ls in a directory, for Others, no read permission exists.
drwxr-x--x 2 enda users 4096 Mar 21 13:06 scripts
Question 2• If you have a file called important.txt and you want
to make sure that you cannot delete it. How can you change its permissions to help prevent this?
• chmod u-w file
Question 3• How could you use the command who to find out a
list of all users who are currently logged on. – Show no additional information other than username– Ensure that each username is only output once even if
they are logged in multiple times
• who | awk ‘{print $1}’ | sort | uniq
Question 4• What UNIX command will look for any the word
Enda in the file stuff.txt– Be sure you look for enda, Enda, ENDA etc.– Be sure you do not return words like calENDAr.
• grep –i ^enda$ stuff.txt
Question 5• What UNIX command would count how many
times the user enda logged in on May 14.– Use the last command to find this information.– Be sure you only look for enda’s information– Be sure you only look for entries on May 14.
• last | grep “May 14” | grep enda | wc -l
Question 6• What SINGLE Unix command can you use to
make the following directory:– /home/enda/1/2/3/4/5/6/7/8/9– You may assume you are currently in /home/enda– None of the sub directories exist.
• I.e. Right now, in /home/enda there is now directory called 1.
• mkdir –p /home/enda/1/2/3/4/5/6/7/8/9
Question 7• You have a file which contains a bunch of words.
– One word per line
• You want to see all words which begin with the letter c, but you need them in REVERSE alphabetical order.– Thus you should get:
• czar
• cyclone
• cutoff
• count
• club
• cat
• grep c file | sort –r
Question 8• What Unix command would append a copy of the
file 2.txt to the end of the file 1.txt?
• cat 2.txt >> 1.txt
Question 9• Imagine you only have the cat command, and the
ability to redirect
• You start with a file that has 10 lines in it.
• What is the least number of commands you could use to make a file with 1000+ lines in it?
• What command would you be running?
• cat file >> file
• Repeat 7 times, to get 1280 lines
Question 10• Assume you are in vi in escape [command] mode
– How would you do each of the following in a single command:
a. Delete the next 100 linesb. Add 10 blank lines beneath the current linec. Find the next occurrence of the word Fido in the documentd. Find the matching close } to this open {.
You can assume your cursor is on top of the { for this one.
• a. 100d• b. 10o• c. /Fido• d. %
Round 5
Question 1• What single command will send 100 messages with
the word “Yo” to the user enda’s screen?
Question 2• Write a simple script which will output “Yes” if
enda is currently logged in and “No” if he is not.
Question 3• What Unix command would give you the answer to
the following math problem:
• (100 * 50) / 5
Question 4• Imagine you have a file called users with a list of
user names in it.– Write a simple script which one at a time will check if
that user is logged on, if they are send them the message “Hey”
Question 5• Write a script which when run, decides what season
it is. And tells you.– For simplicity lets assume the following:– Winter: Dec, Jan, Feb– Spring: Mar, Apr, May– Summer: Jun, Jul, Aug– Fall: Sep, Oct, Nov
Question 6• Write a script which renames the files
– 1.txt, 2.txt, 3.txt
• To the new name:– file1.txt, file2.txt, file3.txt
• The script should do this for all files up to 22.txt
• Be sure the user never sees any errors even if a given file (17.txt) doesn’t exist.
• Use a loop.
Question 7• Write a script which takes one parameter, a file
name.– If the file exists
• Show us the file using more
– Otherwise• Give an error “I could not open you file called xxx”
• Be sure xxx is replaced with the actual file the user typed.
Round 5
Answers
Question 1• What single command will send 100 messages with
the word “Yo” to the user enda’s screen?
let x=0
while [ $x –lt 100 ]
doecho “Yo” | write enda
let x=$x+1
done
Question 2• Write a simple script which will output “Yes” if
enda is currently logged in and “No” if he is not.
if who | grep enda
then
echo “Yes”
else
echo “No”
fi
Question 3• What Unix commands would give you the answer to
the following math problem:
• (100 * 50) / 5
let x=(100*50)/5
echo $x
Question 4• Imagine you have a file called users with a list of user
names in it.– Write a simple script which one at a time will check if that user is
logged on, if they are send them the message “Hey”
for name in `cat users`
do
if who | grep $name
then
echo “hey” | write $name
fi
done
Question 5• Write a script which when run, decides what season it is.
And tells you.– For simplicity lets assume the following:
– Winter: Dec, Jan, Feb
– Spring: Mar, Apr, May
– Summer: Jun, Jul, Aug
– Fall: Sep, Oct, Nov
• if date | grep –i dec –o date | grep –i jan –o date | grep feb• then• echo “Winter”• elif date | grep –i mar –r date | grep –i Apr …
Question 6• Write a script which renames the files
– 1.txt, 2.txt, 3.txt
• To the new name:– file1.txt, file2.txt, file3.txt
• The script should do this for all files up to 22.txt• Be sure the user never sees any errors even if a given file (17.txt) doesn’t exist.• Use a loop.
let x=1while [ $x –lt 22 ]do mv $x.txt file$x.txt 2> /dev/null let x=$x+1done
Question 7• Write a script which takes one parameter, a file name.
– If the file exists• Show us the file using more
– Otherwise• Give an error “I could not open your file called xxx”
• Be sure xxx is replaced with the actual file the user typed.
if [ -f $0 ]then more $0else echo “I could not open your file called $0”fi