unix what is unix? getting connected basic unix commands help! working with directories running...

54
UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Upload: howard-sherman

Post on 18-Jan-2016

270 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

UNIX• What is UNIX?• Getting Connected• Basic UNIX Commands• Help!• Working with Directories• Running Programs• Editors• The Shell• Exercise

Page 2: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

What is UNIX?

• Multi-Tasking O/S• Multi-User O/S• Available on a range of Computers

Page 3: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Which UNIX?

• SunOS Sun Microsystems• IRIX Silicon Graphics• HP-UX Hewlett Packard• Linux For IBM PC compatibles

Page 4: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

UNIX Internals (Simplified)

• Kernel– System Internals

• Shell– Command Interpreter– Programming language

• File System• Process Management

Page 5: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise
Page 6: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

UNIX Shells

• C-Shell• Bourne Shell• Korn Shell• T-Shell• bash

Page 7: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Terminal Emulation Software

• DOS Based Telnet• Windows 9x/NT/XP, Telnet and X Windows• Networked Macintosh, Telnet

Page 8: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Graphical UNIX via Exceed

• X Concepts• Using the Exceed Software• Starting the Common Desktop Environment

Page 9: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Basic X Concepts

• X Server runs on local machine– PC Exceed

– UNIX Workstation Included in OS

– Apple Mac Exodus

• X Client runs on remote machine– Graphical Application

• xterm

• file manager

• Modelling Package

Page 10: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Basic X Concepts

Page 11: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

The Common Desktop Environment

Page 12: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Starting CDE- XSession Options

Page 13: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Setting the XServer Options

Page 14: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Using Exceed :XTerm

Page 15: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Using Exceed to Start an XClient

Page 16: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Rules of Engagement

• UNIX is case sensitive• Commands are in lower case• Backspace and Del Keys correct typing errors• Ctrl U clears the command line• Ctrl C Aborts a program or command• Do Not use the arrow keys

Page 17: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Filenames

• Filenames can comprise: a-z, A-Z alphabetic characters

0-9 digits

.-_+ special characters

mon+tue_01.06-03-96

• Wildcards * means any character or sequence of

characters

Page 18: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Format of UNIX commands

• command [option ...] [filename ...]

eg: ls

ls -l tutorial

more tutorial

Page 19: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

List Directory• ls list directory• ls -l list directory in long format• ls -a list all (inc. hidden) files

-rw------ l course01 57 Oct 18 11:05 hello.c

Number ofbytes in file

AccessPermissions

Date and time last modified

Page 20: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Displaying a Text File

• more filename

Spacebar next screenful

Enter next line

q quit

? list commands

Page 21: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Copy, Rename and Remove

• Copy a file

cp oldfile newfile

• Rename a file

mv oldname newname

• Remove a file

rm afile

Page 22: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Searching Files

• grep string filestring = word or phrase

file = file or list of files

Page 23: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Redirection

• The output of a command usually goes to the screen

• Redirect the output to a file using ‘>‘ls -l > dirlist

Page 24: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Piping

• Feeding the output of one command into the input of another command

• The symbol ‘|’ is called a pipecommand | command

• eg: ls -al | more

ls -la | grep Nov

Page 25: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Manual Pages

• man command

• man - k topic

• man - k topic | more

Page 26: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Example Manual Pages

• Synopsis

mv [ - ] [- fi] filename1 filename2

optional options

cp [ - ip] filename1 filename2

cp [ - iprR ] filename ... directory

rm [ - ] [ - fir ] filename ...

rmdir directory

Page 27: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Directory Structure

/home1/cs/cs4un1

usr

/ (root)

home1

cs me ph

cs4un2cs4un1

Page 28: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Directories

• pwd print working directory• cd change directory

cd move to home directory

cd .. move up one level

cd mydir move into a subdirectory

cd /var/adm move to an absolute directory

Page 29: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Managing Filestore• Each user has an allocation of filestore (Disk

Space)• Monitor filestore usage with the ‘quota’

command

EG: quota -vDisk quotas for username (uid 20002)Filesystem usage quota limit timeleft files quota limit

timeleft/stoat-g 20 2000 4000 13 1000

1500

• The quota value can be exceeded for 7 days

quota < usage < limit for 7 days

• The limit value can not be exceeded

usage < limit always

• If usage > quota for 7 days account is expired and files can not be created

Page 30: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Running programs• Two modes of operation foreground and background

– Foreground Interact with program via keyboard/screen

– Background No connection with keyboard/screen

Submit to backbround by Appending ‘&’

EG: myprog >& myfile &

The symbols ‘>&’ redirect output and any errors to the file myfile

Another method of submitting programs to the background is via a batch processing system, such as Sun Grid Engine (as used on Titania)

Page 31: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Foreground Program Control

• Kill a program Ctrl C• Stop a program Ctrl Z

Note a stopped program still exists in the system

Page 32: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Program control within current shell

• jobs Lists jobs (programs)• bg %job_id Place a job in the background• fg %job_id Return a job to the foreground• stop %job_id Stop a job• kill %job_id Kill a job

jobs

[1] + Running time.sh > out

stop %1

[1] + Stopped (signal) time.sh > out

bg %1

[1] + time.sh > out &

kill %1

Terminated

Page 33: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Program control using ‘ps’ and ‘kill’

• ps Report process status

ps -f -u username UID PID PPID C STIME TTY TIME CMD

username 24816 24585 0 16:23:04 pts/50 0:00 sleep 2

username 20169 19956 0 16:05:45 pts/50 0:01 -csh

username 24585 20169 0 16:35:07 pts/50 0:00 /bin/sh time.sh

• kill Terminate process

– Find its process ID (PID) using the ps command– Kill the process using the kill command

kill 24585

– Sometimes kill on its own does not work so trykill -KILL 24585

Page 34: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Programe Control using top

• top is a separate utility and not part of the OStop -Uusername

– k kill program (process) k PID, k -KILL PID

– h help

– q quit top

Page 35: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Vi Text Editor

• Very powerful• Available on all versions of UNIX• No in-built help• Man page gives detailed help

• Vi has three modes– Command– Text entry– Last line

Page 36: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Editors

• Dtpad• nedit• vi• emacs

Page 37: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Desktop Note Pad Editor

Page 38: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

T-Shell - Filename Completion

• Complete a partially typed filename– Operation

• Type enough characters to uniquely identify the name• Press the ‘Tab’ key (for C – shell use ‘Esc’ key)• If the response is a ‘bleep’ press Ctrl-d to list possible matches

– Setup• Add the following to your .cshrc file• set filec

Page 39: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

T-Shell -Repeating Previous Commands

• Operation– history List previous commands

– !! re-run last command

– !n re-run the nth command

– !str last command starting with str

eg: !vi

• Setup– Add the following to your .cshrc file

– set history=40

Page 40: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

T-Shell - Command Aliasing

• Definitions– alias ll ' ls -lF '– alias h ' history 24 '– alias dir ' ls '

• Setup– Add alias definitions to your .cshrc file

Page 41: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

The Secure shell protocol

• SSH is a new method of communications over the Internet that encrypts data end-to-end

• Replaces telnet, ftp, rsh and rcp• Components

– Secure shell ssh– Secure ftp sftp– Secure copy scp

Page 42: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Secure Shell

• Program to log into another computer over a network• Execute commands on a remote machine• Move files from one machine to another• Provides strong authentication and secure

communications over insecure channels.• Intended as a replacement for rlogin, rsh, rcp, and

rdist.

Page 43: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

ssh

• You only need the SSH client. The server is unnecessary, unless you wish to connect back to your home machine via the Internet using SSH.

• Connecting to a WRG node

ssh -l wrsmg maxima.leeds.ac.uk • To use X-windows add the "-X" flag

– SSH will then carry Xwindows traffic over the Internet to connect• Range of options for changing ports, specifying authentication

files, encryption algorithms etc….– Use man ssh for help with options

Page 44: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Secure ftp (sftp)

• Establishes an FTP-style file transfer session between the Unix systems

• sftp command always used in the form: sftp user@server– e.g.from titania sftp [email protected]

Page 45: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Transferring Files Using sftp

From the SFTP prompt (sftp>) can do the following: • get command to retrieve a file from the remote Unix

server. – get test.txt

• put command to transfer a file from your Unix system to the remote Unix system you are connected to. – put file2.txt

Page 46: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Navigating file systems using sftp

From the SFTP prompt (sftp>) can do the following: • ls command to display the contents of a directory on

the remote Unix system you are connected to. – ls /home/user. Will display the contents of the

directory /home/user on the remote Unix system.• cd and lcd commands change current remote

directory, or current local directory. – e.g. cd /home/user. Will change the current

remote directory to /home/user.

Page 47: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Summary of sftp commands 1

•mget Retrieve multiple files from server•Mput Transfer multiple files to server•pwd Display remote working directory •quit or exit Quit sftp •rename oldpath newpath Rename remote file •rmdir path Remove remote directory •rm path Delete remote file •version Show SFTP version •? Synonym for help

Page 48: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Summary Listing of SFTP commands 2 ascii Use text transfer mode

help Display the help text

image Use binary transfer mode

lls [ls-options [path]] Display local directory listing

lmkdir path Create local directory

ls [path] Display remote directory listing

mkdir path Create remote directory

put local-path [remote-path] Upload file

Page 49: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Secure copy - scp

• Using SCPFast, easy method to copy single files from your Unix system to a remote Unix system.

Page 50: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Retrieving a file using SCP

• To retrieve a file from a remote Unix system, the syntax is: scp username@server:file local-file– username= username on the remote system– server= the name of the remote Unix system– file= the file to retrieve from the remote system – local-file= the location you wish to save the file to on your

local Unix system

Page 51: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Transferring a file to a remote Unix system using SCP• The syntax is: scp local-file username@server:file

– local-file= the file to transfer from the local system– username= username on the remote system– server= the name of the remote Unix system– file= the location you wish to save the file to on the remote

Unix system

Page 52: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Transferring Multiple Files

• mget and mput with sftp• Use tar and compress to package a directory tree

– scp transfers the packaged directory tree– uncompress and extract directory tree using tar

Page 53: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

UNIX Utilities

• tar• compress• sed• awk

Page 54: UNIX What is UNIX? Getting Connected Basic UNIX Commands Help! Working with Directories Running Programs Editors The Shell Exercise

Exercise Tutorial• Turn on PC• Login to your PC Managed NT account

login digley/mep98xxxpassword:

• Login to titania

– Start XSession or telnet titania

Login using the provided username and password