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

Change Your Password

You can change your password with the passwd(1) command.

Man pages

The man (for manual) pages document UNIX commands. They are organized in chapters. Generic user commands are in chapter 1, system administration 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 chapter number when you write them. For example the command ls is often written 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 are they in?

Essential UNIX commands

If you don't know the following commands, learn them.
pwd - print working directory
cat - prints a file to the screen
ls - list files
cd - change directory
more, less - page-at-a-time display of 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 "hidden" files using "ls"?
Question 5.  What hidden files do you have in your home directory (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 the previous question?
Question 8.  When you open a shell window you will be in your home directory.  What is the full pathname to your home directory?
Question 9.  Create a chmod(1) command that gives read and write access to you, gives only read access to the group and to the world for a fictional file called "hello.txt".

Filename Wildcards

For each of the following filename wildcards, give me one filenemame that does 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 the command emacs in the background. Type jobs.

Question 14.  What job number and process id did 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 lines of ~jmache/sec/messages to a file called my.info.

Pipes

UNIX commands may be chained together with pipes. A pipe redirects the standard output of one process into the standard input of another process. For example, "ls -1 | wc -l"  (i.e., ls -ONE | wc -ELL) will count 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" UNIX user.

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

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

Question 19.   Create a UNIX command line that answers the question, how many users use the Bourne-Again Shell (bash).

Command Substitution

Question 20.  Create a command line that writes the following line of information to a file called "users.dat".
There are N users.
Where N is replaced by the actual number of people that can use the lab.  Use "cat /etc/passwd" to get a full list of all users.
 

Regular Expressions and grep

Question 1.  For each of the following questions, give me one word that does 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 file ~jmache/sec/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 #).

Question 3.  Create a grep command that prints out all lines whose first entry is "nisplus", i.e., "nisplus" appears after the colon.

find

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

Question 4.  Create a "find" command that starts your home directory and prints out the names of all the files that haven't been changed in at least 60 days.

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

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

tar archives

The traditional means of distributing collections of files in UNIX is via tar(1) archives, usually compressed. Copy the archive file sample.tar.gz from ~jmache/sec.

Uncompress the archive using the gunzip(1) command.

List the contents of the archive with the '-t' flag of tar(1).

Question 7.  What files are in the archive?

Extract the files from the archive with the '-x' flag of tar.

Question 8.  Edit the file "gv" from the archive and add your name to the top.  Save and print out the file "gv" .

Advanced Operations

Question 9.  Write a command sequence that prints all the usernames whose real name (field 5) contains no lower-case letters.  Use cat /etc/passwd to get access to user information.

Question 10.  You suspect someone tried to break into the system on September 5.  You want to find  all the users that logged in that day.  The last(1) command prints out a list of the all the users that have logged in in the last few days.  Create a command that prints out a sorted list of users that logged in on September 5.  You'll need the sort(1) command too.