\problem[1] Look up the man page for the file command, and use it to answer the following questions:
\begin{enumerate}
\item What did you type to look up this man page (give the entire command)?
\begin{enumerate}
\item[]\answer\shellcmd{man file}
\end{enumerate}
\item What is the name of the author of the file program who based it on the Unix System V version without looking at anybody else's code?
\begin{enumerate}
\item[]\answer Ian Darwin
\end{enumerate}
\item Which command flag can be used with the file command to have it suppress prepending filenames to the output lines?
\begin{enumerate}
\item[]\answer\shell{-b, --brief}
\end{enumerate}
\item Which command flag can be used with the file command to tell it to try and look inside of compressed files?
\begin{enumerate}
\item[]\answer\shell{-z, --uncompress}
\end{enumerate}
\item What command line flag to the file command causes the output to not translate unprintable characters to octal representation?
\begin{enumerate}
\item[]\answer\shell{-r, --raw}
\end{enumerate}
\item Name 5 different types of information you can discover about a command using man.
\begin{enumerate}
\item[]\answer Description, Options, Environment, Examples, and History.
\end{enumerate}
\end{enumerate}
\section{THE UNIX FILESYSTEM}
\problem[2] Answer the following questions about absolute and relative filenames:
\begin{enumerate}
\item What is an absolute filename?
\begin{enumerate}
\item[]\answer An absolute filename is a filename that starts from the root directory, and goes all the way to it's location. Ex: \shell{/home/user/documents/text.txt}.
\end{enumerate}
\newpage
\item What is a relative filename?
\begin{enumerate}
\item[]\answer A relative filename is a filename that starts from the current dirrectory that the user is currently in. Ex: If a user is in \shell{/home}, then \shell{user/documents/text.txt}.
\end{enumerate}
\item Assume you have a directory containing a computer program. This program reads and writes to a file that is always located at \shell{/opt/help/files.txt}. If you are going to be moving the directory to different locations on your computer, but the computer program continues to read and write to that same file, should you use an absolute or relative filename to refer to that file?
\begin{enumerate}
\item[]\answer Absolute filename as that file can then be accessed from anywhere in the system.
\end{enumerate}
\item Would \shell{keep\_files/accounts/myFile.txt} be considered absolute or relative?
\begin{enumerate}
\item[]\answer That is a relative filename.
\end{enumerate}
\item Would \shell{/home/apowers/pictures/trip\_to\_nebraska/} be considered absolute or relative?
\begin{enumerate}
\item[]\answer That is an absolute filename.
\end{enumerate}
\item Would \shell{../data/test.jpg} be considered absolute or relative?
\begin{enumerate}
\item[]\answer That is a relative filename.
\end{enumerate}
\end{enumerate}
\problem[3] Answer the following questions about the \shell{`.'} and \shell{`..'} directories assuming you are currently in the \shell{/usr/lib/headers/} directory for each question:
\begin{enumerate}
\item What specific directory does \shell{`..'} refer to (in this case)?
\begin{enumerate}
\item[]\answer\shell{/usr/lib/}
\end{enumerate}
\item What specific directory does \shell{`.'} refer to (in this case)?
\begin{enumerate}
\item[]\answer\shell{/usr/lib/headers/}
\end{enumerate}
\item If you were to run the command \shellcmd{cd ../../local}, what would be the new current working directory?
\begin{enumerate}
\item[]\answer\shell{/usr/local/}
\end{enumerate}
\item If you were to run the command \shellcmd{cd ./x64}, what would be the new current working directory?
\begin{enumerate}
\item[]\answer\shell{/usr/lib/headers/x64/}
\end{enumerate}
\item Are the \shell{`.'} and \shell{`..'} directories considered to be visible or hidden?
\begin{enumerate}
\item[]\answer Hidden, as any filename or directory that starts with `.' is automatically considered hidden. They also do not show up by default when running \shellcmd{ls}.
\end{enumerate}
\end{enumerate}
\newpage
\section{LISTING FILES}
\problem[4] Answer the following questions about the \shell{ls} command:
\begin{enumerate}
\item What \shell{ls} command line flags will display the sizes and file classifications?
\begin{enumerate}
\item[]\answer\shell{-F} displays file classifications, \shell{-s} displays sizes in terms of blocks.
\end{enumerate}
\item What command line of the \shell{ls} command will display the files in the \shell{/bin} directory in a single column along with index number (inode) and file size in blocks?
\begin{enumerate}
\item[]\answer\shellcmd{ls -1is /bin}
\end{enumerate}
\item The command \shellcmd{ls -t} displays the files sorted by \rule{1cm}{0.15mm} time, newest first.
\begin{enumerate}
\item[]\answer\underline{modification}
\end{enumerate}
\item The command \shellcmd{ls -Rm /} causes \shell{ls} to \rule{1cm}{0.15mm} list all files and subdirectories in the root directory with the list of entries separated by commas.
\begin{enumerate}
\item[]\answer\underline{recursively}
\end{enumerate}
\item Give a command for listing all of the files inside of the \shell{/opt} directory (including hidden files), and sorted from least-recently modified to most-recently modified.
\begin{enumerate}
\item[]\answer\shellcmd{ls -tra /opt}
\end{enumerate}
\item The \shell{ls} command can colorize the output it displays (yours may or may not be turned on by default, but the man page will instruct you on how to turn it on). Using color to \rule{1cm}{0.15mm} file types allows the user to quickly locate files by type.
\begin{enumerate}
\item[]\answer\underline{distinguish}
\end{enumerate}
\end{enumerate}
\section{MANAGING DISK SPACE}
\problem[5] Fill in the blanks for the following paragraph. In your solution, please list the labeled answers on separate lines. Hint: Use the man pages for compress, gzip, and bzip2.\vspace{0.25cm}
The compress command uses the adaptive (5a) \rule{0.8cm}{0.15mm}-\rule{0.7cm}{0.15mm} coding algorithm to reduce the size of files. The gzip command is a compression utility designed to be a replacement for compress. Gzip is based on the (5b) \rule{1cm}{0.15mm} algorithm, which is a combination of LZ77 and (5c) \rule{1cm}{0.15mm}. The bzip2 command uses the (5d) \rule{1cm}{0.15mm} algorithm. Bzip2 is the (5e) \textbf{slowest / fastest} of the three algorithms and only operates on (5f) \rule{1cm}{0.15mm} so it cannot compress a directory nor work as a file archiver.
\answer
\begin{enumerate}
\item\underline{Lempel-Ziv}
\item\underline{Deflate}
\item\underline{Huffman coding}
\item\underline{Burrows-Wheeler}
\item\underline{fastest}
\item\underline{files}
\end{enumerate}
\section{OWNERSHIP AND PERMISSIONS}
\problem[6] Answer each of the following questions assuming the permissions settings string is \shell{drwx-wx-w-}. Some may have multiple answers.
\begin{enumerate}
\item Are these permissions being set on a file or a directory?
\begin{enumerate}
\item[]\answer Directory
\end{enumerate}
\item Who has the most control in this case: the user, the group, or others?
\begin{enumerate}
\item[]\answer User
\end{enumerate}
\item Who has both write and execute permission, but doesn't have read permission: the user, the group, or others?
\begin{enumerate}
\item[]\answer Group
\end{enumerate}
\item Who has read permission: the user, the group, or others?
\begin{enumerate}
\item[]\answer User
\end{enumerate}
\item Who has write permission: the user, the group, or others?
\begin{enumerate}
\item[]\answer User, group, and others
\end{enumerate}
\item What is the primary purpose of having permissions/ownership in Unix?
\begin{enumerate}
\item[]\answer Data security between users.
\end{enumerate}
\end{enumerate}
\problem[7] Answer the following questions about the chmod command:
\begin{enumerate}
\item Symbolic notation uses characters to identify the user type and permissions, whereas numeric notation uses \rule{1cm}{0.15mm} in a bitwise format to change file permissions.
\begin{enumerate}
\item[]\answer Octal digits
\end{enumerate}
\item Using symbolic notation, how would you add read and execute permission for the others (everyone)?
\begin{enumerate}
\item[]\answer\shellcmd{chmod o+rx}
\end{enumerate}
\item Using symbolic notation, how would you set the permission of the group to be read and write, but no execute?
\begin{enumerate}
\item[]\answer\shellcmd{chmod g=rw}
\end{enumerate}
\newpage
\item Using numeric notation, how would you assign the permission string \shell{-rwx-wx-w-}?
\begin{enumerate}
\item[]\answer\shellcmd{chmod 732}
\end{enumerate}
\item Using numeric notation, how would you assign the permission string \shell{-rw-r----x}?
\begin{enumerate}
\item[]\answer\shellcmd{chmod 641}
\end{enumerate}
\item If you have a link to a file rather than the actual file, can you change the permissions of the link using chmod (hint: look up the man page for chmod)?
\begin{enumerate}
\item[]\answer No
\end{enumerate}
\item Which chmod flag allows you to recursively change the permissions of files inside of a directory, rather that the file/directory itself?
\begin{enumerate}
\item[]\answer\shell{-R}
\end{enumerate}
\end{enumerate}
\section{MANAGING FILES/DIRECTORIES}
\problem[8] Answer the following questions regarding managing files and directories:
\begin{enumerate}
\item What command would remove the directory \shell{/trashbin} and all of the files and subdirectories inside of it?
\begin{enumerate}
\item[]\answer\shellcmd{rm -rf /trashbin}
\end{enumerate}
\item What command flag can you use with \shell{cp} so that it doesn't accidentally overwrite a file if it already exists?
\begin{enumerate}
\item[]\answer\shell{-i}
\end{enumerate}
\item What command exists to delete a directory if and only if it is already empty?
\begin{enumerate}
\item[]\answer\shellcmd{rmdir}
\end{enumerate}
\item Which command can be used to rename a file or directory?
\begin{enumerate}
\item[]\answer\shellcmd{mv}
\end{enumerate}
\setcounter{p8}{\value{enumi}}
\end{enumerate}
For each of the following, give the necessary command. Pay attention to which types of filenames (absolute or relative) or permissions notation (symbolic or numeric) are specified. Use only one (1) command for each, and assume that each command affects the commands that follow it.
\begin{enumerate}
\setcounter{enumi}{\value{p8}}
\item Change to the directory \shell{/usr/share/}
\begin{enumerate}
\item[]\answer\shellcmd{cd /usr/share/}
\end{enumerate}
\item Create two new directories called \shell{``oldcode''} and \shell{``newcode''} inside of this directory
\item While still inside of \shell{/usr/share}, create two new files, one called \shell{``main.java''} inside of the \shell{``newcode''} directory and another called \shell{``calculate.py''} inside of the \shell{``oldcode''} directory. Use relative path/file names.
\item While still inside of \shell{/usr/share}, rename the \shell{``calculate.py''} file inside of the \shell{``oldcode''} directory to \shell{``calculate.backup''} using an absolute path/filename.
\item Set the permissions of the \shell{``main.java''} file (using symbolic notation) so that the group has read and write permissions, but no execute permission
\begin{enumerate}
\item[]\answer\shellcmd{chmod g=rw main.java}
\end{enumerate}
\item Using relative path/file names, make a copy of the \shell{``main.java''} file to the \shell{``oldcode''} directory called \shell{``main.save''}.
\begin{enumerate}
\item[]\answer\shellcmd{cp main.java ../oldcode/}
\end{enumerate}
\item Change to the parent directory \shell{/usr/share/} using \shell{`..'} notation.
\begin{enumerate}
\item[]\answer\shellcmd{cd ..}
\end{enumerate}
\item Delete all of the files inside of the \shell{``oldcode''} directory, including the \shell{``oldcode''} directory itself.
\begin{enumerate}
\item[]\answer\shellcmd{rm -rf oldcode}
\end{enumerate}
\item Inside of your current directory, remove the empty directory \shell{``tempcode''} (assume it exists and contains no files).
\begin{enumerate}
\item[]\answer\shellcmd{rmdir tempcode}
\end{enumerate}
\end{enumerate}
\newpage
\section{VIEWING FILES}
\problem[9] Answer the following questions assuming that the file \shell{``names.txt''} contains the following 9 lines of content:
\item Give the command for obtaining the lines starting at (and including) ``Dr. Evil'' and going to the end of the file.
\begin{enumerate}
\item[]\answer\shellcmd{tail -5 names.txt}
\end{enumerate}
\item Give the command for obtaining just the first two lines of the file \shell{``names.txt''}.
\begin{enumerate}
\item[]\answer\shellcmd{head -2 names.txt}
\end{enumerate}
\item Give the command for obtaining just the names in the file (from ``Bob'' to ``Chris'' inclusively) using the \shell{tail} and \shell{head} commands.