Introduction to UNIX
Download
Report
Transcript Introduction to UNIX
Introduction to UNIX
Introduction
What is UNIX?
UNIX is an operating system which was first developed in the
1960s, and has been under constant development ever since. By
operating system, we mean the suite of programs which make the
computer work. It is a stable, multi-user, multi-tasking system for
servers, desktops and laptops.
UNIX systems also have a graphical user interface (GUI) similar to
Microsoft Windows which provides an easy to use environment.
However, knowledge of UNIX is required for operations which
aren't covered by a graphical program, or for when there is no
windows interface available, for example, in a telnet session.
Types of UNIX
There are many different versions of UNIX, although they share
common similarities. The most popular varieties of UNIX are Sun
Solaris, GNU/Linux, and MacOS X.
.
Introduction to UNIX
2
The UNIX Operating System
The UNIX operating system is made up of three
parts; the kernel, the shell and the programs.
The kernel
The kernel of UNIX is the hub of the operating system
It allocates time and memory to programs and handles the filestore
and communications in response to system calls.
An illustration of the way that the shell and the kernel work
together
suppose a user types rm myfile (which has the effect of removing
the file myfile)
The shell searches the filestore for the file containing the program
rm, and then requests the kernel, through system calls, to execute
the program rm on myfile
When the process rm myfile has finished running, the shell then
returns the UNIX prompt % to the user, indicating that it is waiting
for further commands.
Introduction to UNIX
3
The UNIX Operating System
The shell
The
shell acts as an interface between the user and the
kernel.
When a user logs in, the login program checks the username and
password, and then starts another program called the shell.
The shell is a command line interpreter (CLI) - it interprets the
commands the user types in and arranges for them to be carried
out.
The commands are themselves programs; when they terminate,
the shell gives the user another prompt (% on our systems).
The
adept user can customize his/her own shell, and users
can use different shells on the same machine.
History - The shell keeps a list of the commands you have
typed in. If you need to repeat a command, use the cursor
keys to scroll up and down the list or type history for a list
of previous commands.
Introduction to UNIX
4
Files and processes
Everything in UNIX is either a file or a process.
A
process is an executing program identified by a unique
PID (process identifier).
A file is a collection of data. They are created by users using
text editors, running compilers etc.
Examples of files:
a document
the text of a
(report, essay etc.)
program written in some high-level
programming language
instructions comprehensible directly to the machine and
incomprehensible to a casual user, for example, a collection
of binary digits (an executable or binary file);
a directory, containing information about its contents, which
may be a mixture of other directories (subdirectories) and
ordinary files.
Introduction to UNIX
5
The Directory Structure
All the files are grouped together in the
directory structure. The file-system is arranged
in a hierarchical structure, like an inverted
tree. The top of the hierarchy is traditionally
called root (written as a slash / )
Introduction to UNIX
6
The Directory Structure
In the diagram below, the home directory of the undergraduate student "ee51vn"
contains two sub-directories (docs and pics) and a file called report.doc.
The full path to the file report.doc is "/home/its/ug1/ee51vn/report.doc"
Introduction to UNIX
7
UNIX at BC – SSH Secure Shell Client
The preferred connection method is SSH (Secure Shell Client) which does
not transmit your password in the clear across the internet, as telnet and ftp
do.
If you are running a Linux, Unix or Mac system, ssh is probably available on
your system.
For MS windows users install packages are available at:
SSH includes sftp ( Secure File Transfer Protocol ) and scp ( Secure Copy ). See
the Andersen textbook for more details.
http://acc4.its.brooklyn.cuny.edu/~sysadm/ssh/win/SSHSecureShellClient-3.2.9.exe
http://acc6.its.brooklyn.cuny.edu/~sysadm/ssh/win/SSHSecureShellClient-3.2.9.exe
ftp://acc5.its.brooklyn.cuny.edu/pub/sysadm/SSHSecureShellClient-3.2.9.exe
These Windows products are licensed for use by Brooklyn College only.
Using one of the lab's Unix machines, the command "lab_machines" will
return a list of available Unix machines. i.e.
atrium11.its.brooklyn.cuny.edu 146.245.252.11
atrium12.its.brooklyn.cuny.edu 146.245.252120
acc2.its.brooklyn.cuny.edu 146.245.252.72
fldsun228.its.brooklyn.cuny.edu 146.245.252.228
Introduction to UNIX
8
UNIX at BC - SSH
Once SSH is installed, click on the icon and SSH Secure Shell (left) will appear
Click on the “Quick Connect” icon; this will bring up the “Connect to Remote Host” popup
Enter the Host Name (e.g., atrium96.its.brooklyn.cuny.edu) and User Name and click Connect
You will be prompted for your password
Another popup will allow you to name the profile information for future reference
Introduction to UNIX
9
UNIX at BC - SSH
Now you’re connected at ready to roll
Introduction to UNIX
10
UNIX at BC – SSH Transfer
To transfer files between your local PC and the Unix machines, click on the SSH Secure
File Transfer icon
Click on Quick Connect and follow the same procedure as in connecting with SSH Shell
You will have two windows – one for your local machine and one for the Unix server. Drag and
drop files from one to the other
Introduction to UNIX
11
UNIX at BC - Telnet
Open a browser and enter the url
telnet://atrium4.its.brooklyn.cuny.edu/
This will open a DOS window, connect you to
the college’s SUN servers and prompt you for
an id and password
When completed, you will see a prompt of the
form $ atrium4:/users1/rudowsky>
Now you’re in business
Introduction to UNIX
12
UNIX at BC
See David Arnow’s “Getting Started with UNIX” guide
Basic commands:
ls [-a|-l] List files in the directory
mkdir <dir name> make a directory
rm <filename> remove a file
mv <oldfilename> <newfilename>
cat <filename> display a file
cp
rename a file
<original_filename> <copy_filename> copy a
file
command > <output_filename> redirect the output of a
command e.g., ls –l > list
g++ xyz.cpp –o xyz compiles a C++ program named
xyz.c and saves the compiled progam as xyz
exit
Introduction to UNIX
13
UNIX at BC
ls does not, in fact, cause all the files in your
home directory to be listed, but only those ones
whose name does not begin with a dot (.)
Files beginning with a dot (.) are known as
hidden files and usually contain important
program configuration information. They are
hidden because you should not change them
unless you are very familiar with UNIX!!!
To list all files in your home directory including
those whose names begin with a dot, type
ls -a
Introduction to UNIX
14
UNIX at BC
When you type ls -a in a directory, two special directories
called (.) and (..) appear
In UNIX, (.) means the current directory, so typing cd .
means stay where you are
(..) means the parent of the current directory, so typing cd ..
will take you one directory up the hierarchy
NOTE: there is a space between cd and the dot
Note: typing cd with no argument always returns you to your home
directory. This is very useful if you are lost in the file system.
Pathnames enable you to work out where you are in relation to
the whole file-system.
For example, to find out the absolute pathname of your home-directory,
type cd to get back to your home-directory and then type pwd
pwd (print working directory)
Introduction to UNIX
15
UNIX at BC
Home directories can also be referred to by the
tilde ~ character. It can be used to specify paths
starting at your home directory.
ls
~/unixstuff will list the contents of your
unixstuff directory, no matter where you currently
are in the file system
ls ~ will list the contents of your home directory no
matter where you currently are in the file system
ls ~/.. will list the contents of the parent of your
home directory no matter where you currently are
in the file system
Introduction to UNIX
16
Your Directory Structure
Your assignments should be maintained in a
directory tree with the following structure:
Directly
beneath your home directory, there should be
a subdirectory named cis15.
Directly beneath cis15, there should be a subdirectory
named homework
Within homework, there should be a
subdirectory for each assignment.
Thus,
your files for homework #3 will be in the
directory home/cis15/homework/hw-3 (where home is
your home directory
Put all C++ code, input and output files in that
directory. Subdirectories can be created as needed.
Introduction to UNIX
17
Formatting Your Code
Please use proper indentation-- reading code is like reading and
essay-- improperly indented code is like text without punctuation,
capitalization, and the other conventions of proper writing. You must
develop the habit of proper indentation.
Please give some thought to your identifier and function names-single letters such as i or x are fine for loop/array indexes or
symbols in a mathematical equation, but beyond that, the variables
should be names reflecting the data/function they hold/perform.
The first line of output from your program should contain your name,
Unix id, course number and homework number.
Each source file you submit should have a comment at the top
containing the same information as above plus the name of the file.
For example:
/*
/*
/*
/*
/*
Introduction to UNIX
Ira Rudowsky
rudowsky
CIS 15 EM6 Spring 07
Assignment hw-1
hw-1.cpp
*/
*/
*/
*/
*/
18
C++ IDEs
One way to work on your assignments is to code and
debug on your local machine using an IDE (Dec/C++
http://www.bloodshed.net/devcpp.html or Code::Blocks
http://www.codeblocks.org are two possibilities) and then
transfer you code to the Atrium servers. (SSH Secure File
Transfer or Core FTP LE
http://www.coreftp.com/download.html and selecting the
SSH/SFTP option.
To edit files on the Unix server, two possible editors are
vi or pico (shows you useful commands in the editor
window). The Andersen book explains both or you can
Google tutorials for either editor and find numerous
sources of information online.
The Unix compiler is invoked by the g++ command (see
below for more).
Introduction to UNIX
19
UNIX at BC
Most of the machines are running Solaris 9, the rest Solaris 8.
The GUIs available are Sun's openwin, CDE and gnome.
Both gcc and sun's compilers are available. Only the
command line compilers are usually used.
cc and CC are the front ends to Sun's C and C++ compilers.
gcc and g++ are the front ends to gcc's C and C++ compilers.
Use an editor to write the code, save the file e.g., abc.c
cc -flags or CC -flags prints available compiler options
g++ test1.cpp -o test1 produces file test1 if there are
no errors
Run the program by its name test1
The default output name is a.out is you omit the –o option
Introduction to UNIX
.
20
UNIX at BC
A lot of information regarding the Unix servers can be found at
http://acc6.its.brooklyn.cuny.edu/AtriumSunGuide/Table_of_Contents.html
This includes
General Information
Unix Commands
Korn Shell
Regular Expressions
Floppies, Mtools
Tar
Editing Vi, Pico
Compilers, Debuggers
OpenWindows
Email, Pine, Talk
MailTool
Browsers Netscape, Lynx
Gopher
NewsReaders Trn, Xrn
NcFtp
Rules
Introduction to UNIX
21