Normally lab exercises will be found online (linked from the
course schedule), and not printed and given to you. This lab is
http://www.cse.lehigh.edu/~brian/course/2016/sysadmin/labs/lab01.html.
There are usually lots of details in a lab, so read carefully.
Using Linux
The HP workstations in this lab have fast multi-core CPUs, dual
ethernet interfaces, lots of RAM, a workstation-class Nvidia graphics card, and a
widescreen monitor. What they don't have is a hard drive. You'll get
one of those next week. Fortunately, if not told otherwise, they will boot to give
you remote access to a dedicated workstation in the other lab (PL122).
Please log in using your CSE password. The PL122 workstations run a version of Linux, which is a powerful and reliable operating system based on UNIX principles.
If you are not familiar with Red Hat/Fedora Linux, explore the system!
In particular, make sure you know where to find
the Terminal (which opens a window with a shell prompt where you can type
commands). You'll often need it
in the future, as much of what we do will be at the command line.
-
Be friendly
Introduce yourself to your neighbors. It's good to be friendly,
and in some future labs, you'll need to work with a partner.
Find a web browser, and log into CourseSite and take a look at this
course. If your profile on coursesite does not include a picture that is
just a head-and-shoulders shot, please do a selfie or ask someone in
the room to take
another picture of you, send it to you, and then please update your
picture so that I can recognize your face on the system.
In the course, notice that there is a link to the web pages that are set
up for the course,
and check what the reading assignment is for today and
our next lecture, and to see what is in homework #1.
(We won't use CourseSite much except for grading purposes.)
You'll need to find today's lab to see the rest of the instructions!
The X-Window System
The GUI for Linux/UNIX (called X-Windows) is mostly similar to what you may be accustomed, but there are some important differences.
One of the differences is copying and pasting.
The X-Window system provides a simple and intuitive way to copy and paste
using a mouse. Whenever you highlight text (anywhere) using the left mouse
button, that text is available for pasting. Pasting is performed by clicking
on the middle mouse button (or scroll wheel or both buttons together on a
simpler two-button mouse).
One thing that makes X-Windows great is the ability to log into a
machine remotely, and then have a program use your local display.
(It turns out this is how you were able to log in remotely to a machine
in 122.) You
can do this too -- just ssh from your machine to another, such as
another system in this lab (that is, type something similar to ssh
-X sunlab), and then run a program (that uses a GUI) on the other
machine and see it show up on your screen. This separation of display
and execution makes it easy to use high-powered, centralized servers,
even though you might not be able to sit in front of them. Lehigh
provides number of such
computational servers.
Start learning about the shell
How to find information about shell commands/utilities:
-
Type man <program> for any system command, most utilities
-
Type info <program> for any GNU utility or program (and examine man pages!)
-
Check your reference books
-
The rest: Google, instructor, etc.
What if you don't know the name of the program?
In what follows, be certain to use man to learn about the
commands mentioned. Normally we will not explain all aspects of a
command, and in some cases, enough information is not provided here to
know how to do something.
Optional arguments to ls
The ls command is how you list the files in the current directory.
ls -l lists files in a long
format (size, permissions, etc.). What option to ls will show files that
start with a period (a.k.a., hidden files)?
Finding programs to run
How does the shell know what program to run when you type it?
The whereis command will look for programs in a bunch of
standard places. Use whereis to find the location for du (which
is a program that tells you how much disk storage is being used). (The du.1.gz
and du.1p.gz files are man page entries.)
But if there were more than one, which one is chosen to be run when you type du? Use the
which command to find out.
In any case, you can always specify the complete
(or relative) path of a program to override the default binary.
Now use whereis to find out where gcc is installed. Compare that result
to the location returned by which for gcc.
So how does UNIX decide what programs you can run, just by typing their
name? It uses your path, which is an environment variable (i.e.,
something that you can change) called PATH. Type env to see all
your environment variables. Your shell will look in each directory in the
order specified in your path to see if there is a program with the name
you entered. One of those directories should match the directory in which
gcc is found (which you saw earlier with which).
Wildcards and escapes
Instead of explicitly specifying a filename or directory as a parameter to a
program, you can use wildcards (e.g., instead of tab completion). [In the
examples that follow, the text in bold represents text that a user
typed; the remainder is either my shell prompt or the output of the
program.]
Note that in the next examples, ls is showing the contents of the
directory (or directories) passed as parameters to ls.
io:~/cse271.131% ls *
DONE
In reality, the shell expanded the wildcard to instead be the list of
filenames that match, so that the program that is called never sees the
wildcards---it just sees the parameters as if the user had typed them.
io:~/cse271.131% ls ?w?
DONE
io:~/cse271.131%
Arguments to commands are separated by whitespace, so spaces and other
special characters must be escaped or quoted, as in:
io:~% touch "this is a test"
io:~% touch this\ is\ a\ test
io:~% ls th*
this is a test
touch is a program that will create a new (empty) file if one
does not exist, and will change the last-modification-time of an existing
file.
Copying and moving UNIX files
cp and mv work more or less similarly. You give them a
list of source files and a destination (except that mv removes the source
files). mv is also used to rename files.
Examples:
Copy mozilla180.jpg to the images directory
% cp mozilla180.jpg images/
Copy this_dir and all its subdirectories to /tmp
% cp -r this_dir/ /tmp
Move Makefile and all .c and .h files to the cse213
directory
% mv Makefile *.c *.h cse213/
Move a file from /tmp to the current directory
% mv /tmp/d4x-2.02-2.i386.rpm .
Rename a file
% mv foo.c rename.c
Creating and Removing Directories
mkdir and rmdir are the usual programs, but sometimes using
rm is easier.
io:~% mkdir test1
io:~% mkdir test2
io:~% touch test1/hello
io:~% rmdir test1
rmdir: directory "test1": Directory not empty
io:~% rmdir test2
io:~% rm -rf test1
io:~%
Text-based Web browsing
Sometimes it is helpful to be able to browse the web from the machine to
which you are connected, rather than the one you are sitting in front of. For
example, some websites are restricted to users within some domain (such as
.lehigh.edu). Fortunately, most UNIX installations have one or more
text-based web browsers installed. The most common is called
lynx. Use lynx to visit your favorite web page and see whether
the page is still useful (since it won't show graphics, javascript
or flash, etc.).
Wrapping up
If you are relatively new to Linux, you should start browsing
some sections of
Introduction to
Linux (an older version is available at
http://www.tldp.org/LDP/intro-linux/html/). If
you are not yet an expert at using bash, you might start by reading
Section 2.1 of USLAH and then try
the Bash Guide for Beginners and
the Advanced Bash-Scripting
Guide (at http://www.tldp.org/LDP/abs/html/).
Become familiar with your system.
In the shell, use df to see what drive partitions
are installed and their size (we'll be working with partitions in a future
lab). Run top to see how much memory is
available and what processes are running. Run uname -a to see what
version of the kernel is running. A linux-specific command that gives more information about the system is lsb_release -a.
In order to sign the sheet to show that
you have completed the lab, you will need to:
- show me your picture in CourseSite
- show me the output of using ls when including files that start with a period
- tell me how to rename a file in Linux/UNIX
- show an open terminal with the output of lynx on your choice of webpage
- give me an example of at least one term used in this lab that you
looked up or asked someone its meaning
Note that I strongly urge you to go through
the tutorials and to explore -- in future weeks some of the labs will be
considerably more demanding, and anything you learn today will be one less
concept you'll have to figure out next time.