unix what is unix? getting connected basic unix commands help! working with directories running...
TRANSCRIPT
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
Which UNIX?
• SunOS Sun Microsystems• IRIX Silicon Graphics• HP-UX Hewlett Packard• Linux For IBM PC compatibles
UNIX Internals (Simplified)
• Kernel– System Internals
• Shell– Command Interpreter– Programming language
• File System• Process Management
UNIX Shells
• C-Shell• Bourne Shell• Korn Shell• T-Shell• bash
Terminal Emulation Software
• DOS Based Telnet• Windows 9x/NT/XP, Telnet and X Windows• Networked Macintosh, Telnet
Graphical UNIX via Exceed
• X Concepts• Using the Exceed Software• Starting the Common Desktop Environment
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
Basic X Concepts
The Common Desktop Environment
Starting CDE- XSession Options
Setting the XServer Options
Using Exceed :XTerm
Using Exceed to Start an XClient
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
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
Format of UNIX commands
• command [option ...] [filename ...]
eg: ls
ls -l tutorial
more tutorial
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
Displaying a Text File
• more filename
Spacebar next screenful
Enter next line
q quit
? list commands
Copy, Rename and Remove
• Copy a file
cp oldfile newfile
• Rename a file
mv oldname newname
• Remove a file
rm afile
Searching Files
• grep string filestring = word or phrase
file = file or list of files
Redirection
• The output of a command usually goes to the screen
• Redirect the output to a file using ‘>‘ls -l > dirlist
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
Manual Pages
• man command
• man - k topic
• man - k topic | more
Example Manual Pages
• Synopsis
mv [ - ] [- fi] filename1 filename2
optional options
cp [ - ip] filename1 filename2
cp [ - iprR ] filename ... directory
rm [ - ] [ - fir ] filename ...
rmdir directory
Directory Structure
/home1/cs/cs4un1
usr
/ (root)
home1
cs me ph
cs4un2cs4un1
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
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
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)
Foreground Program Control
• Kill a program Ctrl C• Stop a program Ctrl Z
Note a stopped program still exists in the system
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
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
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
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
Editors
• Dtpad• nedit• vi• emacs
Desktop Note Pad Editor
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
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
T-Shell - Command Aliasing
• Definitions– alias ll ' ls -lF '– alias h ' history 24 '– alias dir ' ls '
• Setup– Add alias definitions to your .cshrc file
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
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.
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
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]
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
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.
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
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
Secure copy - scp
• Using SCPFast, easy method to copy single files from your Unix system to a remote Unix system.
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
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
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
UNIX Utilities
• tar• compress• sed• awk
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