Here is a general outline of the key concepts and commands (arranged by topic) that you should know for Exam 01.
The exam will have the following format:
Commands: Identify which command performs a certain task.
Short Answers: Briefly answers about the Shell, Files, Processes, Networking, Pipelines, and the Unix Philosophy.
Debugging: Fix some simple shell scripts.
Filters: Use Unix filters to answer some questions.
Scripting: Write a shell script that utilizes command line arguments and filters.
Parts 1 through 3 is to be done first on paper. However, parts 4 and 5 can be done with the aid of your laptop and the Internet (but not other people).
This check list is meant to be representative, rather than exhaustive (ie. there may be questions that show up on the exam that are not shown below).
What is Unix?
What is a shell?
How would do you use git to:
Create a copy a repository.
Create a new branch.
View the changes you've made.
Save a change you've made.
Share the changes you'ved made.
Retrieve the changes from a remote location.
What are aliases? How do you create one? How do you make them permanent?
What are environment variables? What does the PATH
environment
variable control? How would you modify it?
Version control system for managing our files.
What is a file?
What is the general layout or hierarchy of a typical Unix filesystem?
What is an inode and what information does it store?
What is the difference between an absolute and relative path?
How do Unix file permissions work? How would you set them to restrict access for certain operations and certain classes?
You should be able to translate from octal to rwx
triplets and
back.
What is the difference between a hard link and a soft link?
List the contents of a directory (long, human-readable, sorted)
Set permissions using octal and symbolic arguments.
View the inode information fora file.
View the total disk usage for a file or directory.
Create hard and soft links.
Search directory for files by name and type.
What is a process? What attributes does it have?
What does it mean to signal a process? What do different the
different signals do (TERM
, INT
, KILL
, HUP
)?
How do we suspend, foreground, and background a process?
List the processes for the current user and for the whole system.
Interactively view and manage processes.
Signal a process by PID.
Measure how long it takes a process to execute.
Signal a process by name.
What three files does every process start with?
How do you redirect the output of a command into a new file?
How do you redirect the output of a command and append it to a file?
How do you redirect the output of one command as the input to another?
How do you direct the contents of a file into the input of command?
What is /dev/null
? How would you use it to output stderr
but ignore
stdout
of a program?
What is a here document and how would you use it?
What is bandwidth and latency? How are they different? How would we measure both of them?
What is an IP address? How is a domain name related to it?
What is a network port?
Transfer a file from one machine to another.
List the IP addresses of the current machine.
Maintain a persistent shell session.
General purpose tools to communicate with TCP-based network services.
Communicate using HTTP (ie. download files from the web).
Measure the latency from host to remote machine.
What is a shell script? What is a she-bang and why do we need it (or what does it do)?
You should know the basics of the shell programming language:
variables
capturing STDOUT
if statement
case statement
for loop
while loop
function
trap
How do you debug a shell script? What different modes do we have to help us figure out what a script is doing?
Bourne shell interpreter.
Perform checks on file types and values.
Extract or compress tarballs.
Extract zip archives.
The following scripts contain errors. Identify and correct all the bugs.
This script checks each file passed via command line arguments and reports if the file is readable.
for $file in '$@'; do [-r $file] | echo file is readable! done
This script checks each file passed via command line arguments and reports if the file is readable.
is_readable() { test -r $@ } while ( -n "$@" ); do is_readable($@) | echo file is readable! done
Write the following shell script:
$ ./column.sh -h Usage: column.sh [-n N -d D -S -R] column -n N Number of items to display (default is 5). -d D Delimiter to use (default is ","). -S Sort output. -R Randomize output. This script selects a column (default is 1) from the CSV input and then displays the first N items.
Examples:
$ ./column.sh -d : < tmnt.txt Leonardo Donatello Raphael Michelangelo $ ./column.sh -d : -n 1 < tmnt.txt Leonardo $ ./column.sh -d : -n 1 3 < tmnt.txt katana $ ./column.sh -d : -S 3 < tmnt.txt bo katana nunchucks sai $ ./column.sh -d : -R 3 < tmnt.txt nunchucks katana sai bo
Note: The tmnt.txt
file is described below.
What are the three tenets of the Unix Philosophy?
What are regular expressions?
You will need to know the basic metacharacters such as
.
*
[]
[^]
^
$
()
|
\n
{m, n}
You will also need to be familiar with the basic character classes and their character set equivalents such as:
[:alpha:] = [a-zA-Z]
[:lower:] = [a-z]
[:upper:] = [A-Z]
[:space:] = [ \t\r\n\v\f]
[:digit:] = [0-9]
What are filters? What do they do and how are they related to the Unix Philosophy?
Extract fields or characters.
Order text.
Remove duplicates.
Randomize input.
Translate from one set of characters to another.
Search based on pattern.
Search and replace or extract text based on regular expressions.
Display first few lines of input.
Display last few lines of input.
Perform complex manipulation of text.
Given the file tmnt.txt
, which contains:
Leonardo:blue:katana Donatello:purple:bo Raphael:red:sai Michelangelo:orange:nunchucks
What is the result of the following shell commands?
cut:
echo "Leonardo,Donatello,Raphael,Michelangelo" | cut -d , -f 1
echo "Leonardo,Donatello,Raphael,Michelangelo" | cut -d , -f 1,3
echo "Leonardo,Donatello,Raphael,Michelangelo" | cut -d , -f 2-
echo "Leonardo,Donatello,Raphael,Michelangelo" | cut -b 1,15,39
tr:
echo "Pizza! Pizza!" | tr '!' '?'
echo "Pizza! Pizza!" | tr 'iaz' '145'
echo "Pizza! Pizza!" | tr -d '[n-z]'
echo "Pizza! Pizza!" | tr -d '[:punct:]'
grep:
cat tmnt.txt | grep '^[LM]'
cat tmnt.txt | grep 'e.*o'
cat tmnt.txt | grep -Eo '^[^: ]+'
cat tmnt.txt | grep -Eo '[a-zA-Z]+[al]{2}[^:]*'
sed:
cat tmnt.txt | sed -nr 's/Leonardo/Splinter/p'
cat tmnt.txt | sed -r '/lo/d'
cat tmnt.txt | sed -nr 's|.*:o([^: ]+).*|O\1|p'
cat tmnt.txt | sed -nr 's/.*([LD][^:]+)[: ]+([^:]+).*/\2/p'
Given the tmnt.txt
file above, write Unix pipelines that perform the
following tasks:
List only the names of the turtles in sorted order.
List only the colors of the turtles in sorted order.
List only the weapons of the turtles in sorted order.
List only the turtles whose names in lo
.
List only the turtles with last names with two consecutive vowels.
Count how many colors begin with a b
.
Count how many colors end with an e
.
List only the turtles names whose name ends with a vowel and whose weapon ends with a vowel.
List only the turtles names with two of the same consecutive letter (i.e.
aa
, bb
, etc.)
List the colors that don't end with a vowel.
List the weapons that contains a repeat letter anywhere in the string.