copyright 2009, university of alberta introduction to unix produced by jon johansson presented by...
TRANSCRIPT
Copyright 2009, University of Alberta
Introduction to UnixIntroduction to Unix
Produced by Jon Johansson
Presented by Waldemar Lysz
AICT
University of Alberta
May 4, 2009
Copyright 2009, University of Alberta
Copyright 2009, University of Alberta
Topics
• What is Unix?
• Your Unix environment
• The file system directory structure
• SSH connections
• Unix commands
• Compilers
UNIX is a registered trademark of The Open Group in the United States and other countries
LINUX is a trademark or a registered trademark of Linus Torvalds
UNIX Is an Operating System
Copyright 2009, University of Alberta
Copyright 2009, University of Alberta
Unix History: The People who brought us Unix
Douglas McIlroy
Ken Thompson Dennis Ritchie
Copyright 2009, University of Alberta
Unix History
• 1969: Unix first written by AT&T employees
• Ken Thompson• Dennis Ritchie• Douglas McIlroy
• ~1985: development of the AT&T Unix splits into two main streams
• BSD (Berkley Source Dist.)• System V
• 1983: GNU project starts• 1991: Linux kernel
development begins
http://en.wikipedia.org/wiki/Image:Unix_history-simple.png
BSD System V Linux
ATT Unix
Copyright 2009, University of Alberta
Linux Unix-like OS
Linus Torvalds
Copyright 2009, University of Alberta
Unix-like GNU Project• Started by Richard Stallman in
1983• Develop a complete Unix-like
operating system composed entirely of free software
• Need lots of components:• a kernel → Linux• compilers• editors• text formatters• mail software• many other things …
Richard Stallman
GNU Logo
Copyright 2009, University of Alberta
Unix You Can Try• IRIX
is the System V-based Unix Operating System with BSD extensions developed by Silicon Graphics (SGI)
nexus.westgrid.ca• AIX
(Advanced Interactive eXecutive) is an operating system developed by IBM based on UNIX System V
cortex.westgrid.ca• Linux
is a clone of the Unix operating system• Linux kernel has been written from scratch by Linus Torvalds and
others• GNU tools developed through the GNU Project
cluster.srv.ualberta.ca
Copyright 2009, University of Alberta
Unix Components
You do not need to know anything about the kernel in order to use a UNIX system!
Copyright 2009 University of Alberta
Unix Components – Kernel
• The Kernel is the core of the UNIX system.• Loaded at system start up (boot)• memory-resident control program
• Manages the entire resources of the system, presenting them to you and every other user as a coherent system.
• Provides services to user applications such as device management, process scheduling, etc.
You do not need to know anything about the kernel in order to use a UNIX system!
Copyright 2009 University of Alberta
Unix Components – KernelExample functions performed by the kernel are:
• managing the machine's memory and allocating it to each process
• scheduling the work done by the CPU so that the work of each user is carried out as efficiently as is possible
• accomplishing the transfer of data from one part of the machine to another
• interpreting and executing instructions from the shell • enforcing file access permissions
You do not need to know anything about the kernel in order to use a UNIX system!
Copyright 2009 University of Alberta
Windows ShellA graphical user interface (GUI)
• allows a user to interact with the computer using a pointing device such as a mouse
• select words from drop down menus • select images such as icons on the display screen • icons represent commands for movement, activation or
some other action
aka the WIMP interface• Windows• Icons• Menus• Pointing Device
Copyright 2008, University of Alberta
Browse directoriesBrowse directories
Edit filesEdit files
Command LineCommand Line
Copyright 2009, University of Alberta
Unix Interface
• high performance Unix machines are generally accessed remotely
• connect through a command line
Copyright 2009, University of Alberta
Unix Commands: Syntax• Usual command-line syntax is:
command• an executable to be run, you instruct what a system should do• the first word on the command line
option• this specifies how the command is run. Options are prefixed with a dash ” -
" character.
argument• what is to be affected, it could be a file, directory, stdin, stdout, user,
process, etc.
• Example format: command option(s) argument(s)
ls –al /home/wdl
Copyright 2009, University of Alberta
Unix Commands: man pages• get help with commands through the man pages,
(man commands), for example:
• you might like to read:
• In Unix case matters!• For Example: LS is not equal to ls
$ man ps
$ man ls
$ man intro
Copyright 2009, University of Alberta
Unix Commands: man pages
While viewing a man page you have few commands:
Spacebar move one screen further
Enter move one line further
b moves one screen back
/pattern searches forward for "pattern"
?pattern searches backward for "pattern"
n the next occurrence of the
"pattern"
q quits the man(1) command
h prints a help screen;
Copyright 2009, University of Alberta
Unix Commands• Example of command options and output (most commands have many options, see the man pages for details).• The ls command with options to list all files in long format:$ ls -la
• file names starting in dot are normally hidden • permissions are: Read, Write, eXecute • columns are owner, group, and all
Copyright 2009, University of Alberta
Unix Components – Shell• Whenever you login to a Unix system you are placed
in a shell program.• the shell's prompt is usually visible at the cursor's position on your
screen.• to get your work done, you enter commands at this prompt.
• The shell is a command interpreter.• it takes each command and passes it to the operating system
kernel to be acted upon.• it then displays the results of this operation on your screen.
• Several shells are usually available on any UNIX system, each with its own strengths and weaknesses.
Copyright 2009, University of Alberta
Unix Components – Shell• Different users may use different shells.
• the system is set up with a default shell, which can be overridden or changed
• The most commonly available shells are: • Bourne shell (sh) • C shell (csh) • Korn shell (ksh) • TC Shell (tcsh) • Bourne Again Shell (bash)
• Each shell also includes its own programming language• command files, called "shell scripts" are used to accomplish a series of
tasks
Copyright 2009, University of Alberta
Bourne Shell (sh)• This is the original Unix shell written by Steve Bourne
of Bell Labs. • /bin/sh, /sbin/sh• It is available on all UNIX systems.• This shell does not have the interactive facilities provided by
modern shells such as the C shell and Korn shell.
• The Bourne shell provides an easy to use language with which you can write shell scripts.
Copyright 2009, University of Alberta
Bourne Again SHell (bash)• a public domain shell written by the Free Software
Foundation under their GNU initiative. • fairly standard default shell on Linux distributions• bash provides all the interactive features of the C
shell (csh) and the Korn shell (ksh)• bash’s programming language is compatible with the
Bourne shell (sh)• bash is one of the more popular shell choices
Copyright 2009, University of Alberta
Agenda
• What is Unix?
• Your Unix environment
• The file system directory structure
• SSH connections
• Unix commands
• Compilers
UNIX is a registered trademark of The Open Group in the United States and other countries
LINUX is a trademark or a registered trademark of Linus Torvalds
Copyright 2009, University of Alberta
Environment• Your working environment is defined whenever you
login or start another shell. • This environment is set using the values that the shell finds
in the initialization files (which it always reads as it starts up).• You can change your working environment by editing these
initialization files and setting new values for the various variables.
• Each shell handles its initialization files in a different way
Copyright 2009, University of Alberta
Environment• Your working environment is defined whenever you login
or start another shell. • To see the list of environment variables being used:
printenv
• You can print the value of a particular environment variable with the “echo” command:
echo $SHELL
• You set an environment variable like this:
$ jon@um01:~>MY_NAME="Jon"
$ jon@um01:~>echo $MY_NAME
$ Jon
Copyright 2009, University of Alberta
Unix Components – Utilities• UNIX provides several hundred utility programs, often
referred to as commands. • You can accomplish universal functions, such as:
• editing • file maintenance • printing • sorting • programming support • online info • etc.
• And they are modular, i.e., single functions can be grouped to perform more complex tasks.
Copyright 2009, University of Alberta
Exercise 1:
Logging in and getting some basic information about the system.
Copyright 2009, University of Alberta
Agenda
• What is Unix?
• Your Unix environment
• The file system directory structure
• SSH connections
• Unix commands
• Compilers
UNIX is a registered trademark of The Open Group in the United States and other countries
LINUX is a trademark or a registered trademark of Linus Torvalds
Copyright 2009, University of Alberta
The Unix File System
• A file system is a logical method for organizing and storing large amounts of information in a way which makes it easy to manage.
• The file is the smallest unit in which information is stored.
Copyright 2009, University of Alberta
The Unix File System/ Root directory of the file system./bin User utilities fundamental to both single-user and multi-
user environments./sbin System programs and administration utilities
fundamental to both single-user and multi-user environments./boot Programs and configuration files used during operating
system startup/dev Device nodes; see intro(4)./etc System configuration files and scripts./tmp Temporary files. The contents of /tmp are usually NOT
preserved across a system reboot. /usr The majority of user utilities and applications./var Multi-purpose log, temporary, transient, and spool files. /home User home directories on many Linux systems/root Home directory for the root account
Copyright 2009, University of Alberta
The Unix File System
• the file system resembles an inverted tree• the tree is anchored in the root directory
• designated with a ‘/’
Copyright 2009, University of Alberta
The Unix File System
• every item in the unix file system tree is either a directory or a file• a directory is like a file folder
• a directory can contain files, and other directories• a directory contained within another is called the child of the other
Copyright 2009, University of Alberta
The Unix File System
• different unix distributions put user home directories in different places
• you are placed in your home directory when you log in• the directory that you are in now is called the “current working
directory”• check the path with ‘pwd’ (print working directory)
Copyright 2009, University of Alberta
The Unix File System
• the location of an object in the file system is described by a “path”
• the “absolute path” includes all the directories starting from “/”• the “relative path” includes only subdirectories of the current
working directory
Copyright 2009, University of Alberta
The Unix File System
Slash / means the root directory
Tilde ~ means your home directory
Dot . means right here, current directory
Dot Dot .. means up one level
Copyright 2009, University of Alberta
File System Commands
ls list directory contents
cd change the current working directory
pwd print the name of the current/working directory
Copyright 2009, University of Alberta
Unix Commands
grep get regular expressionFinds word in a stream of text
| pipe text from one command to the next. This symbol is normally a shifted “\” key
Copyright 2008, University of Alberta
Exercise 2:Understanding the structure of the file
system and obtaining information about it.
Copyright 2009, University of Alberta
Agenda
• What is Unix?
• Your Unix environment
• The file system directory structure
• SSH
• Unix commands
• Compilers
UNIX is a registered trademark of The Open Group in the United States and other countries
LINUX is a trademark or a registered trademark of Linus Torvalds
Copyright 2009, University of Alberta
SSH- Connecting To Unix Host• Secure Shell (ssh) is a set of programs to:
• log into another computer over a network, • to execute commands in a remote machine, • and to move files from one machine to another.
• It provides strong authentication and secure communications over un-secure channels. • It is intended as a replacement for telnet, rlogin, rsh, and rcp. • For SSH2, there is a replacement for FTP: sftp.
Copyright 2009, University of Alberta
SSH• Secure Shell also provides secure X connections and
secure forwarding of arbitrary TCP connections. • ssh connects and logs into the specified hostname • the user must prove his/her identity to the remote
machine using one of several methods• see the man page for details• we only use the password
Copyright 2009, University of Alberta
SSH - How it Works• ssh works by the exchange and verification of
information, using public and private keys, to identify hosts and users• we will only be concerned with a password exchange• after you've authenticated (successfully logged in)
communications are encrypted
Copyright 2009, University of Alberta
SSH daemon• sshd is the daemon that listens for connections from
clients• it forks a new daemon for each incoming connection• the forked daemons handle key exchange,
encryption, authentication, command execution, and data exchange.
Copyright 2009, University of Alberta
SSH
In order to connect to a remote machine you must:
1. run the ssh client on your desktop machine
2. the client connects to the sshd server running on the remote machine
3. the client and server establish a connection and run through a protocol which attempts to establish that you have the right to make a connection
4. enter your password
Copyright 2009, University of Alberta
How to run SSH• To login to a remote host:
ssh <hostname>
• To login to a remote host with a different username:ssh -l <username> <hostname>
• To login to a remote host and send a command:ssh <hostname> <command>
• To login to a remote host and forward X11:ssh +x <hostname>
Copyright 2009, University of Alberta
SSH – scp Unix Data Mover• Secure Copy, scp, is used in copying files over the
network securely• It uses ssh for data transfer, and uses the same
authentication and provides the same security as ssh• How to run scp:
scp <source> <destination>• where the source and destination can be paths in the
local file system or have the formuser@host:/dir/for/file
Copyright 2009, University of Alberta
SSH – scp to use scp to copy a file to a remote system:
scp localdir/to/filelocation user@host:/dir/for/file
to use scp to copy a remote file to the local system:scp user@host:/dir/for/file localdir/to/filelocation
to keep the file attributes of the source file from the source host, use -p:scp -p user@host:/dir/for/file localdir/to/filelocation
scp test [email protected]:/home/dsk05/cshome/jon
scp [email protected]:/scratch_large/jonj/ibm/test .
Copyright 2009, University of Alberta
SSH – More Info
• Tutorials• http://csociety.ecn.purdue.edu/~sigos/projects/ssh• http://kimmo.suominen.com/docs/ssh/
• FAQ:• http://www.employees.org/~satch/ssh/faq
Copyright 2009, University of Alberta
Exercise 3:1. Connect to remote sites
2. Moving data between machines• use one of other lab machines or:
• cluster.srv.ualberta.ca• nexus.westgrid.ca• cortex.westgrid.ca
Copyright 2009, University of Alberta
Agenda
• What is Unix?
• Your Unix environment
• The file system directory structure
• SSH
• Unix commands
• Compilers
UNIX is a registered trademark of The Open Group in the United States and other countries
LINUX is a trademark or a registered trademark of Linus Torvalds
Copyright 2009, University of Alberta
Unix Commands: man pages• get help with commands through the man pages,
(man commands), for example:
• you might like to read:
• In Unix case matters!• For Example: LS is not equal to ls
$ man ps
$ man ls
$ man intro
Copyright 2009, University of Alberta
Unix Commands: more/less• The commands more and less are “pagers”
• They display text on the screen one page at a time• more <filename>
• press the space-bar to display the next page• press the enter-key to display the next line• press the q to exit the program • this is how man pages are displayed
• less is like more, but is more flexible• it allows the up and down arrow keys to be used to scroll
around a document
Copyright 2009, University of Alberta
Unix Commands: Text Editors• a text editor is a program which enables you to create and
manipulate character data (text) in a computer file• a text editor is not a word processor although some text editors
do include word processing facilities• text editors often require "memorizing" commands in order to
perform editing tasks• the more you use them, the easier it becomes• there is a "learning curve" in most cases
Copyright 2009, University of Alberta
Unix Commands: Text Editors
There are several text editors available by default on most UNIX systems:
ed standard line editor ex extended line editor vi visual editor; full screen;
• uses ed/ex line-mode commands for global file editing a favourite of system administrators
sed stream editor for batch processing of files
In addition other editors may be available: emacs a full screen editor and much more
a favourite of programmers
pico an easy "beginner's" editorand countless others….
Copyright 2009, University of Alberta
Unix Commands: Text Editors• nedit – the Nirvana editor
• initially developed by Mark Edel for Fermilab • it is now distributed under the GNU General Public License
nedit has an interface similar to text editors on Microsoft Windows and Macintosh!
Copyright 2009, University of Alberta
Unix Commands: File Manipulation
cp copy files and directoriesgrep print lines from the input stream matching a
patternrm remove files or directoriesumask set initial file permissions on a newly-created
filechown changes the user and/or group ownership of
each given filechgrp changes the group ownership of each given file
Copyright 2009, University of Alberta
Directory Manipulationcd change the current working directory
pwd print working directory
ls list directory contents
mkdir creates directories with the specified names
rmdir removes empty directories• To remove a nonempty directory, together with everything
below, use “rm -r foo”
Copyright 2009, University of Alberta
Unix Commands: tar“Tape Archive” program: tar• Save a bunch of files into a single archive
• historically this archive was on tape, now it’s frequently just a regular file
• To generate a tar file:• tar -cvf filename.tar list-of-files
• this puts the files into tar format and stores them in filename.tar
• To extract files from a tarfile:• tar -xvf filename.tar
Copyright 2009, University of Alberta
Unix Commands: tar• Some of the options for tar are:
c create a new tarfile
v verbose, print out the file names as they are archived
f use the next argument as the archive file
t list the files
x extract files from an archive
(Remember to use a “-” for options)
Copyright 2009, University of Alberta
Unix Commands: Processes ps process status
top monitor system activity
kill end a process
^z suspend
bg run the suspended job in the background
who show who is logged on
su substitute user
Copyright 2009, University of Alberta
Exiting the system
logout exit a login shell• a login shell is the shell you get when you're
prompted with your username and you have to enter your password
exit exit the shell• a non-login shell is a shell that is started
after we login• we typically use these to work in, for
example bash, sh, csh , ksh, or another shell
Copyright 2009, University of Alberta
Exercise 4Practice a couple of useful commands:
1. tar (tape archive)
2. compression
Copyright 2009, University of Alberta
Agenda
• What is Unix?
• Your Unix environment
• The file system directory structure
• SSH
• Unix commands
• Compilers
UNIX is a registered trademark of The Open Group in the United States and other countries
LINUX is a trademark or a registered trademark of Linus Torvalds
Copyright 2009, University of Alberta
Compilers
There are a variety of compilers available for different systems
• gnu compiler is available for many systems• GCC stands for “GNU Compiler Collection”. • GCC is an integrated distribution of compilers for several
major programming languages. • currently includes C, C++, Objective-C, Objective-C++,
Java, Fortran, and Ada
Copyright 2009, University of Alberta
Compilers• Common compiler flags:
-o specify executable name
-O2 optimization level
-g debugging
Copyright 2009, University of Alberta
Compilers• The makers of large machines generally provide
compilers and libraries designed to provide executables which make the best use of the hardware
• Try to use the manufacturer’s compilers on a system for best performance
Copyright 2009, University of Alberta
Compiler Names
Language Cortex Nexus Glacier
Fortran IBM XL 10.1 (xlf_r, xlf90_r, xlf95_r, f77)
MIPSpro Compilers Version 7.4 (f77, f90) GNU 3.2.2 (g77)
Portland Group 6.0-5 (pgf77, pgf90) Intel 8.0 (ifort) Absoft 8.2 (f90) GNU 3.2.2 (g77)
C IBM XL C 8.0 (xlc, cc, c89, c99) GNU 3.3.2 (gcc)
MIPSpro Compilers Version 7.4 (cc, c89, c99) GNU 3.2.2 (gcc)
Portland Group 6.0-5 (pgc, pgcc) Intel 8.0 (icc) GNU 3.2.2 (cc, gcc)
C++ IBM XL C/C++ 8.0 (xlC) GNU 3.3.2 (g++)
MIPSpro Compilers Version 7.4 (CC) GNU 3.2.2 (g++)
Portland Group 6.0-5 (pgCC) Intel 8.0 (icc) GNU 3.2.2 (g++)
Copyright 2009, University of Alberta
Compiling• The one step compile and link:
→ a.out
• the program doesn’t depend on libraries that the linker can’t find
• get an executable named “a.out”• no matter what the name of the source file is
• Run the executable with the command:
$ gcc prog.c
$ ./a.out
Copyright 2009, University of Alberta
f77 prog.f
prog.fcompile
prog.o
linka.out
libraries
Creating an executable is really a two-step process:1. Generate an “object” file (extension “.o”)
→ prog.o
2. Link the object to any library dependencies to get the executable
→ prog
Compilers
$gcc –c –o prog.o prog.c
$gcc –o prog prog.o
Copyright 2009, University of Alberta
Exercise 5:
• Edit files
• Compile
• Move files between machines
Copyright 2009, University of Alberta
Exercise 6:
• monitor and kill processes
Copyright 2009, University of Alberta
Unix – More Info on Line
• Tutorials• http://library.thinkquest.org/05aug/00669/en/history/software/u
nix.html• http://www.ee.surrey.ac.uk/Teaching/Unix/unixintro.html• http://www.unixtutorial.org/
• FAQ:• http://www.faqs.org/faqs/unix-faq• http://www.unixguide.net/unix/programming/
Copyright 2009, University of Alberta
More Info on Line
Copyright 2009, University of Alberta
Need more?