\documentclass{ictlab} \RCS $Revision: 1.1 $ \usepackage{alltt,key,color,answer2} \ifx\pdftexversion\undefined \else \usepackage[pdfpagemode=None,pdfauthor={Nick Urbanik}]{hyperref} \fi \renewcommand*{\subject}{Operating Systems and Systems Integration} \newcommand*{\labTitle}{Lab 2, 3 Linux Study Guide 2 Supplement} \definecolor{light-blue}{rgb}{0.4,0.4,1} \newcommand*{\gl}[1]{\textcolor{light-blue}{#1}} % good link \newcommand*{\ex}[1]{\textcolor{green}{#1}} % executable file \newcommand*{\bl}[1]{\colorbox{red}{\textcolor{white}{\textbf{#1}}}} % bad link \begin{document} \section{Exercise (1)} \label{sec:exercise-1} \begin{enumerate} \item What command will determine the version number of your kernel? \begin{explanation} Look at the list of commands on the last slide labelled ``Basic commands (27)''; it's one of those: \begin{itemize} \item \texttt{which} \item \texttt{uname -a} \item \texttt{hostname} \item \texttt{date} \item \texttt{date +\%Y\%m\%d\%H\%M\%S} \item \texttt{df -k} \item \texttt{du -sk dir\_pathname} \item \texttt{who} \item \texttt{whoami} \item \texttt{su} \end{itemize} \end{explanation} \item How could you find the percentage of your root partition that is used? \begin{explanation} It is also one of the commands listed above. \end{explanation} \item Use \texttt{sudo} to \texttt{find} files under the \texttt{/etc} directory that match the following criteria: \begin{itemize} \item Filename starting with \texttt{ta} \item Filename starting with \texttt{ta} and filesize smaller than 100\,bytes \item Filename starting with \texttt{a} and file type is link \item Filename starting with \texttt{a} and file owner is ``\texttt{news}'' \end{itemize} \begin{explanation} Use the \texttt{find} command. Add the \texttt{-ls} option to print details of files found so that you can check whether your search worked properly or not. Read the manual page for \texttt{find}; discuss with your neighbour how to tackle each part of this. \end{explanation} \end{enumerate} \section{Exercise (2) --- 1} \label{sec:exercise-2-1} \begin{enumerate} \item Find out the detailed file type (more than the 4 types) of following files: \sloppypar\texttt{/bin/vi}, \texttt{/bin/view}, \texttt{/etc/passwd}, \texttt{/dev/fd0}, \texttt{/dev/hda}, \texttt{/dev/isdn1}, \texttt{/bin/}, \texttt{/etc/rc.d/init.d/crond}, \texttt{/boot/vmlinuz-2.4.18-14}, \texttt{/boot/initrd-2.4.18-14.img}? \begin{explanation} Hint: read about the \texttt{file} command: \texttt{man file}. \end{explanation} \item Create a subdirectory, named \texttt{lab2\_3}, under your home directory. Copy the scripts \texttt{student\_cp} and \texttt{at\_cron} from the network directory at \texttt{/home/nfs/ossi-part-time/scripts} to \texttt{\$HOME/lab2\_3/}: \begin{alltt} $ \texttt{cd} $ \textbf{mkdir lab2_3} $ \textbf{cp -a /home/nfs/ossi-part-time/scripts/student_cp lab2_3} # Now press the up-arrow key and edit the above command line so it # looks like this: $ \textbf{cp -a /home/nfs/ossi-part-time/scripts/at_cron lab2_3} \end{alltt} Run the script \texttt{student\_cp}. This script will copy all files (except \texttt{/bin/}, \texttt{/dev/fd0}, \texttt{/dev/hda}, \texttt{/dev/isdn1}) in part a to directory \texttt{\$HOME/lab2\_3}. \item after copying, how could you use one command to know the sum of filesizes of all files in \texttt{\$HOME/lab2\_3/}? \begin{explanation} Hint: See section~\vref{sec:exercise-1}; it's one of the commands listed there. \end{explanation} \end{enumerate} \section{Exercise (2) --- 2} \label{sec:exercise-2-2} \begin{enumerate} \item \texttt{\$HOME/lab2\_3/passwd} is a file containing information of each user account with the following format: \begin{alltt} Username:password:uid:gid:comment:home-dir:shell-type \end{alltt} \item How can you check for the existence of the usernames of the users ``\texttt{root}'', ``\texttt{bin}'', ``\texttt{daemon},'' and find out what their their uid and home directory are? \begin{explanation} Hint: you might consider using the commands \texttt{grep} and \texttt{cut}. \end{explanation} \item What command can easily find the total number of accounts in file \texttt{\$HOME/lab2\_3/passwd}? \begin{explanation} Hint: what command can count lines? \end{explanation} \item Copy \texttt{\$HOME/lab2\_3/passwd} to \texttt{\$HOME/lab2\_3/passwd.new} and compare these 2 files \item \label{ste:part-g}modify the first and second lines of file \texttt{\$HOME/lab2\_3/passwd.new} with any editor and compare these 2 files again. \item How could you generate a new file \texttt{\$HOME/lab2\_3/passwd\_2} which contains only username, uid, home-dir fields, separated by a vertical bar ``\verb+|+'', for each account? \item How could you generate another file \texttt{\$HOME/lab2\_3/passwd\_3} which is sorted by value of uid of file in part~\ref{ste:part-g}? \end{enumerate} \section{Exercise (3)} \label{sec:exercise-3} \begin{enumerate} \item Archive all files in directory \texttt{\$HOME/lab2\_3/} into a single file, named ``\texttt{tarfile.tar}'', without compression. \item How would you list what files are archived in ``\texttt{tarfile.tar}''? \item Create a directory \texttt{\$HOME/lab2\_3/extract/} and extract all files in ``\texttt{tarfile.tar}'' into this new directory. \item Compress all files in \texttt{\$HOME/lab2\_3/extract/} \end{enumerate} \section{Exercise (4)} \label{sec:exercise-4} \begin{enumerate} \item What is done by the script \texttt{at\_cron}? \begin{enumerate} \item create a new file \texttt{\$HOME/lab2\_3/filesize} if this file does not exist. \item Then append ``\texttt{Hello...\bs n}'' to this file. \end{enumerate} \item \label{ste:part-a}Schedule script \texttt{\$HOME/lab2\_3/at\_cron.ksh} to run at one minute later once. What is the result? \item Redo part \ref{ste:part-a}, but schedule to run at 9:10\,p.m. What is the value of the job id? \item \label{ste:part-c}Schedule script \texttt{\$HOME/lab2\_3/a\t\_cron.ksh} to run every one minute and observe the result 2 minutes later. \item Un-schedule what you did in part \ref{ste:part-c}. \end{enumerate} \end{document}