In this lab, we will learn, first-hand, the fundamentals of navigatingand using the UNIX operating system.  Read through and follow theexercises below.

Man pages

The man (for manual) pages document UNIX commands. Theyare organized in chapters. Generic user commands are in chapter 1, systemadministration commands are in chapter 8, file formats are in chapter 5,etc.

If you know the command you want to read about, simply type

man command-name
If you want to search the man pages index by keyword, type
man -k keyword
A common convention for writing about UNIX commands is to include the chapternumber when you write them. For example the command ls is oftenwritten ls(1) since it lives in chapter 1.

Man pages are written according to some conventions:

Question 1.  Take a look at the man page for ls(1) . Describe, in English, the "Synopsis" for ls.

You can quit looking at a man page by typing "q".

Question 2. What are the standard sections of a man page?Read a few man pages so you can briefly describe the purpose of each section.

Question 3.  Find all the man pages that mention the word"calendar".  What man pages mention "calendar" and what chapters arethey in?

Essential UNIX commands

If you don't know the following commands, learn them.
pwd - print working directory
cd - change directory
more (or less) - page-at-a-time display of files
cat - prints a file to the screen
ls - list files
wc - count words, lines, and characters
head - display the top lines of input
tail - display the bottom lines of input
mv - moves/renames a file
cp - copies a file
rm - removes a file
mkdir - makes a directory
rmdir - removes a directory (must be empty)
Question 4.  What command-line option is required to list "dot"files using "ls"?
Question 5.  What hidden files do you have in your homedirectory (you don't have to list all of them)?
Question 6.  What group owns your home directory?
Question 7.  What command(s) did you use to answer theprevious question?
Question 8.  When you open a shell window you will be inyour home directory.  What is the full pathname to your home directory?
Question 9.  Create a chmod(1) commandthat gives read and write access to you, gives only read access to thegroup and to the world for a fictional file called "hello.txt".

Filename Wildcards

For each of the following filename wildcards, give me one filenemame thatdoes and one filename that does not match:

Question 10.  *.c
Question 11.  ??c.d.e??
Question 12.  a*.c*d
Question 13.  [ab]*cd?

Processes and Jobs

Run a command (e.g. emacs ) in the background. Type jobs.

Question 14.  What job number and process iddid emacs get?

Kill the process using the "kill" command. Type jobs.

Question 15.  What did kill report when you ran it?

Redirection

Question 16.  Create a command that stores the first 10 linesof /var/log/daily.out to a file calledmy.info.

Pipes

UNIX commands may be chained together with pipes. A pipe redirects thestandard output of one process into the standard input of another process.For example, "ls -1 | wc -l"  (i.e., ls -ONE | wc -ELL) willcount the number of files in the current directory.

Question 17.  What does the "-1" (one) option mean for ls?

Use the cat command to view the file /etc/passwd. /etc/passwd normally contains entries for each "standard" UNIXuser.

Question 18. Create a UNIX command line which answers the questionof how many users are listed in the file /etc/passwd.

The last field in thepassword table is the shell that the user uses.

Question 19.   Create a UNIX command line that answersthe question, how many users use the plain shell (sh).


Regular Expressions and grep

Question 1.  For each of the following questions, give me one word thatdoes and one word that does not match:
a.  a*.c

b.  a[bcd]*([ef]*|[gh]+)ij

c.   a?b*c+$

d.   [ab]*[^cd]+ef?.*

Question 2.  Examine the filegrepme.txt (save it from http://webhost.lclark.edu/jmache/sec07/grepme.txt, one way is typing "curl http://webhost.lclark.edu/jmache/sec/grepme.txt > grepme.txt).Create a grep command that prints out all lines that are not comments(i.e., print all lines that do not begin with a #).How many lines of lines of output did you get?

Question 3.  Create a grep command that prints out all lineswhose first entry is "nisplus", i.e., "nisplus" appears after the colon.How many lines of lines of output did you get?

find

find(1) allows you to find files based on certain file properties.

Question 4.  Create a "find" command that starts your homedirectory and prints out the names of all the files that have been changedin less than 3 days.

Question 5.  Type "chmod 444 my.info". Create a "find"command that starts at the current directory and prints out all files thatthe owner (i.e. you) doesn't have write access to.

Question 6.  Create a "find" command that starts in yourhome directory and finds all "regular" files and counts the number of linesin each of them.  Hint: Use the "-exec" option.

Advanced Operations

Question 7.  You suspect someone tried to break into thesystem in September.  You want to find  all the users thatloggedin that month.  The last(1) command prints out a list of theall the users that have logged-in in the last few months.  Create acommand that prints out a sorted list of users that logged-in inSeptember.  You may want to use the commands sort(1), cut(1) and uniq(1).

X-tra Credit Question.  Write a command sequence that prints all theusernames whose first part of GCOS/ real name (field 5) contains no lower-case letters (i.e. is all upper case). Use cat /etc/passwd to get access to user information.