Professional Documents
Culture Documents
Intro To UNIX
Intro To UNIX
Intro To UNIX
Introduction
1
A History of computing
What is a computer?
Used to be a person whos job it was to
compute the results of a set of equations.
One of the original uses was to compute ballistic
trajectory tables for various artillery pieces.
7
The printer
Your printer:
You need it connected to a bus.
The CPU needs to know which bus to use.
You need to know how the printer recognizes
data that is meant for it to print. i.e. you need a
way of mechanically identifying the printer on
the bus.
You have to agree that it and only it should be
able to intercept that data (or other devices
could get confused).
How does the printer talk back to the CPU? 8
The CPU and the character
The CPU has a character in a register that it
wants to print
The CPU must know that the printer is ready to receive
characters.
The appropriate BUS selection switches must be set by
the CPU.
The appropriate identifier (address) has to be set on the
bus to uniquely identify the printer.
The CPU then places the data on the data bus and
sends it to the printer.
The CPU must then wait for an acknowledgement from
the printer that the character was received.
9
Coding the PRINT function
Can you imagine coding the PRINT function
every time you wanted to write a piece of
code?
10
A general purpose computer
Instructions for the CPU are stored in memory and not hard
wired
12
Phase 2: Multi-
Multi-user systems
What happens when you try to accommodate
multiple users on a system?
The Kernel.
User applications can only run in a virtualized
environment.
The kernel manages access rights and resource
consumption for all processes.
They have zero access to the underlying hardware.
All access to recourses is strictly managed by the
kernel.
15
The BOOT process
How does your computer go from being a dumb piece of silicon to being a
usable computer?
18
UNIX History (contd)
1973 UNIX philosophy
developed:
Write programs that do one
thing and do it well:
e.g. only write one sort program!
20
UNIX User interface
Eventually, graphical user interfaces were
developed.
Unlike most other operating systems
however, you can swap out one window
manager for a different one.
You can also, in some cases choose
different desktop managers as well.
GUI wars: which interface is prettiest, which
is more lightweight (which one looks more
like Windows???)
21
UNIX Today
Supports many users running many programs
at the same time, all sharing the same
computer system
Information Sharing
Geared towards facilitating the job of creating
new programs
Sun: SunOS, Solaris; GNU: Linux; SGI: IRIX;
Free BSD; Hewlett Packard: HP-UX; Apple: OS
X (Darwin)
22
UNIX
1) Everything in *NIX is CASE SENSITIVE !!!
Lab1 is different from lab1 which is different from
LAB1 etc.
24
The UNIX System
Linux can come in a number of different
flavours:
Single user systems (GUI desktops)
Server class systems - allows simultaneous
multi-user access (no GUI)
Though the difference is basically just what
applications are installed/running
26
System Calls (Library calls)
System calls
Interface to the kernel
Program
Code
Library fread
29
Environment variables
A set of variables the shell uses for certain
operations
Variables have a name and a value
Current list can be displayed with the env
command
A particular variables value can be displayed
with echo $<var_name>
Some interesting variables: HOME, PATH,
PS1, USER, HOSTNAME, PWD
30
Setting environment variables
Set a variable with
Ksh/bash: <name>=<value>
tcsh: setenv <name> <value>
Examples:
TERM=vt100
PS1=myprompt>
PS1=$USER@$HOSTNAME:
PS1=multiple word prompt>
PATH=$PATH:$HOME
DATE=`date`
31
Aliases
Aliases are used as shorthand for frequently
used commands
Syntax:
ksh: alias <shortcut>=<command>
tcsh: alias <shortcut> <command>
Examples:
alias ll=ls -lF
alias la=ls -la
alias m=more
alias up=cd ..
alias prompt=echo $PS1
32
Repeating Commands
Use history to list the last 100 commands
33
Login scripts
You dont want to enter aliases, set environment
variables, set up command line editing, etc. each
time you log in
All of these things can be done in a script that is
run each time the shell is started
For ksh:
~/.profile - is read for a login shell
~/.kshrc
For tcsh
~/.login
~/.cshrc
34
Example .profile (partial)
# set ENV to a file invoked each time sh is
started for interactive use.
ENV=$HOME/.shrc; export ENV
HOSTNAME=`hostname`; export HOSTNAME
PS1="$USER@$HOSTNAME>"
set -o vi
echo ".profile was read"
35
stdin, stdout, and stderr
Each shell (and in fact all programs) automatically
open three files when they start up
Standard input (stdin): Usually from the keyboard
Standard output (stdout): Usually to the terminal
Standard error (stderr): Usually to the terminal
36
Redirecting stdout
Instead of writing to the terminal, you can tell a
program to print its output to another file using the
> operator
Examples:
man ls > ls_help.txt
echo $PWD > current_directory
cat file1 >> file2
37
Redirecting stderr
Instead of writing errors to the terminal, you can
tell a program to write them to another file using
the:
ksh: 2> operator
tcsh: >& operator
Examples:
Mail user@domain.com < message
interactive_program < command_list
39
Pipes and filters
Pipe: a way to send the output of one
command to the input of another
40
Examples of filtering
ls -la | more
cat file | wc
man ksh | grep history
ls -l | grep dkl | wc
who | sort > current_users
41
UNIX Filesystem
The filesystem is your interface to
physical storage (disks) on your machine
storage on other machines
output devices
etc.
Everything in UNIX is a file (programs, text,
peripheral devices, terminals, )
There are no drive letters in UNIX! The filesystem
provides a logical view of the storage devices
42
Working directory
The current directory in which you are
working
pwd command: outputs the absolute path
(more on this later) of your working directory
Unless you specify another directory,
commands will assume you want to operate
on the working directory
43
Home directory
A special place for each user to store
personal files
When you log in, your working directory will
be set to your home directory
Your home directory is represented by the
symbol ~ (tilde)
The home directory of user1 is represented
by ~user1
44
UNIX file hierarchy
/
45
Path names /
Relative path
start at working directory bar.c abcd
.. refers to level above; . refers to working dir.
If /users/dkl/cois3380h is working dir, all these
refer to the same file
../foo.txt ~/foo.txt ~dkl/foo.txt
46
Types of files
Plain (- in the first bit)
Most files
Includes binary and text files
Directory (d)
A directory is actually a file
Points to another set of files
Link (l): A pointer to another file or directory
Special: e.g. peripheral devices
47
Changing directories
Change the working directory with the cd
command
cd <dir_name>
Use absolute or relative path names
cd by itself equivalent to cd ~
48
Output of ls -lF
$ ls -lF
total 110
-rwx------ 1 rhurley staff 6732 Jul 3 11:52 a.out*
drwx------ 9 rhurley staff 512 May 18 2007 Library/
-rw------- 1 rhurley staff 239 May 2 12:55 execex.c
file name
modify date
group
owner size
number of links
permissions The F option appends a qualifier to the
listed file name. *=executable,
/=directory...
file type
49
Creating links
ln s <curr_file> <link_name>
50
File permissions
Permissions used to allow/disallow access
to file/directory contents
Read (r) 4, write (w) 2, and execute (x) 1
For owner, group, and world (everyone)
chmod <mode> <file(s)>
chmod 700 file.txt (only owner can
read, write, and execute)
chmod g+rw file.txt
51
File Ownership
Each file has a single owner
52
File Modification Date
Last time the file was changed
53
Looking at file contents
cat <filename(s)>
concatenate
output the contents of the file all at once
more <filename(s)>
Output the contents of a file one screen at a time
Allows forward and backward scroll and search
You can use the less command as well
54
Moving, renaming, copying, and
removing files
mv <file1> <file2> (rename)
cp <file1>
[<file2>|<dir>|<dir/file2>] (copy)
rmdir <dir_name>
Remove a directory (only works for empty
directories)
rm r <dir_name>
Remove a directory and all of its contents, including
subdirectories
56
Wildcards in file names
All of the commands covered here that
take file names as arguments can also
use wildcards
* for any string, e.g. *.txt, obj*, a*.*
? for any character, e.g. doc?
[ ] around a range of characters, e.g. [a-c]*
57
Getting help on UNIX commands
man <command_name> shows you all the
documentation for a command
(https://www.kernel.org/doc/man-pages/)
1: User commands; man-pages includes a very few Section 1 pages that document
programs supplied by the GNU C library.
2: System calls documents the system calls provided by the Linux kernel.
3: Library functions documents the functions provided by the standard C library.
4: Devices documents details of various devices, most of which reside in /dev.
5: Files describes various file formats, and includes proc(5), which documents the /proc file
system.
7: Overviews, conventions, and miscellaneous.
8: Superuser and system administration commands; man-pages includes a very few Section
8 pages, mainly documenting programs supplied by the GNU C library.