Transcript Slide 1

Very Quick &
Basic Unix
Steven Newhouse
Unix is user-friendly.
It's just very selective about who its friends are.
Acknowledgements

Ohio Supercomputing Centre (OSC)




With exercises:


Basic & Intermediate UNIX courses
http://www.osc.edu/hpc/training/bunix/
http://www.osc.edu/hpc/training/iunix/
http://www.ee.surrey.ac.uk/Teaching/Unix/
Further references


Google
http://en.wikipedia.org/wiki/Unix
©
UNIX and its history

Its an Operating System


Been around since the 70s



Rejuvenated in the 90s with Linux
Traditionally high-end machines


Liaison between the user (you) and the computer
Through Linux available nearly everywhere
Library
Programs work through a library
Shells
Compositional & layered
Java
©
Programs
Kernel
Hardware
Everything is a process


A process is the ‘unit’ of work in Unix
A process is owned by a particular user

Each user owns its own processes (partitioning)


‘root’ is the admin or super user


Cannot interfere with another user’s process
It can interfere with all processes
Processes come from other processes

They are ‘spawned’ or ‘forked’
©
The machine in front of you

It is up and running and with a login screen



You will be presented with a ‘desktop’
Growing similarity to Windows desktop


Login in using your username & password
Usability is one of the major Linux improvements
Your interaction with the machine through a
terminal

Start one up by navigating through the menu
©
The Terminal (xterm)


This window represents a ‘shell’ session
What is a shell?



A way of interacting with the computer
Allows you to enter (& execute) commands
By default you are in the Bash shell



There are several different flavours of shells
Over-time you may develop a preference
Not a concern now
©
Notation
(& try out the examples)

Typing a command into your terminal:
$ ls



$ represents the ‘prompt’ in your shell
ls is the command you want to run (followed by ENTER)
A command may have options prefixed by ‘-’ or ‘--’
$ ls –al

The ls command lists directory contents

Some commands have ‘arguments’
$ ls <directory name>
©
Self Help

Unix has many different commands



Different commands (applications) in a distribution
Different shells have different build in commands
Finding out about different commands



apropos – simple search engine for manual
pages
man <command> - display the command’s
manual page
<command> -help or <command> --help:
show the built in help text
©
What processes are running?

To see the currently running processes:

List the processes that you are running
$ ps

List the processes running on the machine
$ ps –e
$ ps -ef

To see an updated list of processes
$ top

Press q to quit
©
Exercise:
Find out which shell you are in

Get you shell to tell you about its environment
$ env

Displays a list of environment variables


Each variable has a name & value
One of these variables is the SHELL variable
SHELL=/bin/bash

To display a specific value use the echo
command:
$ echo $SHELL
/bin/bash
[is the screen output]
©
File Hierarchy
©
Useful Directory Commands


pwd: Tells you where you are in the directory
space
cd <destination> : Change directory



cd ~ : Change to your home (initial) directory
cd /home/users/sn : Change to an absolute
You will have a different
directory location
username than sn
cd ../sn : Change to a relative directory
location (up a level and then into the sn directory)
©
Other Useful Directory
Commands


mkdir <directory name> - Create a
directory
rmdir <directory name> - Remove a
directory
©
Manipulating files

Copy a single file (after creating it: $ touch testfile1)
$ cp testfile1 testfile2

Copy a directory (after creating it: $ mkdir testdir1)
$ cp –pr testdir1 testdir2

Move a single file or directory (sort of rename)
$ mv testfile2 testfile3

Delete a single file
$ rm testfile1

HINT: Use ls to examine how the directory has changed
after each command
©
Exercise:
Download a set of files
Using a browser: Easy point & click – NO
Using commands executed from the shell


1.
2.
3.
4.
5.
6.
Goto your home directory (cd)
Create a new sub-directory (mkdir)
Move into the subdirectory (cd)
Retrieve the file archive from the web (wget)
Expand the file archive (tar)
Look at what we’ve got (ls)
©
New Commands


wget <url> : Retrieve http or ftp based URLs
into the current directory (Web Get)
tar : Tape Archive (very old command!)


User to build or extract file & directory hierarchy from
an archive
Examine the contents:


$ tar --list –zvf <filename>
How would you extract the contents instead of list?

HINT: You may want to see what HELP you can get
©
And the finally….

The file archive is:


Examine the extensions:




http://www.ecs.soton.ac.uk/~sn/gs06.tar.gz
.tar – Tells you it’s a tar archive
.gz – Tells you it compressed with gzip
.tar.gz is frequently abbreviated to .tgz
People can lie… and then the commands will
normally complain
©
Examine the download

You have a directory (bin) with a file & a file



bin/gridschool
longfile.txt
Examine the contents of the longfile.txt using
various commands


more : Allows you to control how much text goes past. A
page at a time by pressing space, or a line at a time by
pressing return.
$ more longfile.txt
less : Similar to more but allows you to go backward (b
key) as well as forward (space)
$ less longfile.txt
©
Examine explicit parts of a file

head : Examine the start of a text file (or just the
first 5 lines)
$ head longfile.txt
$ head -5 longfile.txt

tail : Examine the end of a text file (or just the
last 5 lines)
$ tail longfile.txt
$ tail -5 longfile.txt

grep : Look for lines with specific text
$ grep HEAD logfile.txt
$ grep GET longfile.txt | more
$ cat longfile.txt | grep GET | more
cat: Dumps contents
to the screen ©
Combine commands
together by ‘piping’
Using your commands

Recap on commands:



Built in to the shell
Standalone executable applications
Standalone commands are in ‘well-known’
locations

How do you find out where a command is located?
$ which echo
$ which export

How does the shell know where to look…?
©
Finding an executable

The PATH variable tells the shell which
directories to look in for an executable


How do we find the value of the PATH variable



Directories separated by ‘:’
$ echo $PATH
$ env
How do we change the value:

BASH: export PATH=<newvalue>
©
Add in our own executable

Find the absolute location of the ‘bin’ directory in
the download

HINT: Navigate to the directory using:




cd to move into and out of directories
ls to examine the contents of the directory
HINT: Once you are in the bin directory use the pwd
command to find out its absolute path.
Add this directory to the PATH variable (one line)
$ export
PATH=$PATH:/home/users/sn/download/bin:
©
Verifying this has worked

Check the executable is there
$ which gridschool
It will tell you the full absolute path

Run the command
$ gridschool

Expected output:
Welcome user sn to ISSGC06
©
Editors

Very simple: vi


http://unixhelp.ed.ac.uk/vi/index.html
WYSIWYG: nedit

More ‘normal’ editor
©
Thank you…

Questions?
©