UNIX - SLU

advertisement
Adnan Niazi
November 2014
S
UNIX Lecture Goals
S Goal 1: Know basic UNIX commands and their use.
S Goal 2: Understand the basic structure of a common Unix
system.
S Goal 3: Know how to find information on more advanced
UNIX commands and their use.
New Concepts
S Shell
A “shell” is an interface to a system, we’ll use
BASH, the Bourne Again Shell.
S Recursion
Something that repeats in a way similar to
itself. (eg. a mirror reflecting a mirror …)
S Variable
A symbol representing a non-static value.
S Pointer
A variable that stores a reference to another
variable.
UNIX HISTORY
S
UNIX History
S 1969 – First Version of UNIX developed at Bell Labs by
AT&T
S 1975 – UNIX 6, the first to be widely available outside Bell
Labs. The first “Berkeley Software Distribution”
(BSD) is released.
S 1989 – UNIX System V, the last traditional UNIX version.
S 1991 – Linus Torvalds begin developing Linux.
“UNIX-like”
S Today – UNIX itself, what’s now called “traditional UNIX”
is not used, except by enthusiasts.
S There are many “UNIX-like” systems (also known as *nix
or UN*X) that are similar to UNIX while not conforming to
the Single UNIX Specification.
S In fact, most operating systems today except windows are
“UNIX like”.
UNIX History
1969
Unics
1971 to 1973
UnixTSS
1 to 4
1974 to 1975
UnixTSS
5 to 6
1969
Open Source
PWB/Unix
Mixed/Shared Source
1971 to 1973
Closed Source
1974 to 1975
1978
BSD
1.0 to 2.0
1979
1978
UnixTSS
7
1979
Unix 32v
1980
1980
BSD
3.0 to 4.1
1981
Xenix
1.0 to 2.3
1982
Sun OS
1 to 1.1
SCO Xenix
1984
UnixTSS
8
1985
AIX
1.0
BSD 4.3
1986
1987
UnixTSS
(Time Sharing
System)
9 to 10
1988
1989
Sun OS
1.2 to 3.0
1991
NEXTSTEP/
OPENSTEP
1.0 to 4.0
1992
BSD 4.3
Tahoe
SCO Xenix
W386
FreeBSD
1.0 to
2.2.x
1994
1995
1997
HP/UX
2.0 to 3.0
System V
R4
BSD
4.4 to
4.4 lite2
Minix
2.x
Linux
2.0 to 2.6.x
HP/UX
6 to 11
NetBSD
1.1 to 1.2
SCO Unix
3.2.4
OpenBSD
1.0 to 2.2
AIX
3.x to 7.1
Minix
3.x
Linux 3.x
1992
1994
1995
Solaris
2.1 to 10
1996
1997
1998
Unixware
7.x
1999
OpenBSD
2.3 to 5.0
Mac OS X
10.0 to 10.7.x
(Darwin)
2005
1988
1993
Unixware
1.x to 2.x
OpenServer
5.0 to 5.04
OpenServer
5.0.5 to 5.0.7
FreeBSD
3.3 to 8.2
1987
1991
NetBSD
0.8 to 1.0
Mac OS X
Server
2001 to 2004
1986
1989
NetBSD 1.3
2000
2011
HP/UX
1.0 to 1.2
FreeBSD
3.0 to 3.2
1998
2006 to 2010
1985
System V
R3
Sun OS
4
1996
1999
1984
1990
386BSD
Linux
0.95 to 1.2.x
1993
SCO Xenix
W286
1983
BSD NET/2
Linux 0.0.1
Minix
1.x
1982
System V
R1 to R2
SCO Xenix
V386
BSD 4.3
Reno
1990
1981
Xenix
3.0
BSD 4.2
1983
System III
2000
2001 to 2004
NetBSD
1.3 to 5.x
HP/UX
11i to 11i v3
OpenServer
6.0
OpenSolaris
2008.05 to
2009.
2005
2006 to 2010
2011
*NIX Systems
Mac OS X
*NIX
Command Line Basics
S
The command line
User, tells you
who you are!
Command line structure
Format:
$
command
[switches]
[arguments]
Why text?
Scary, complicated and tedious at first, but supercomputing is
impossible without it.
Text based commands allow scripting and automation, making
work re-usable and repeatable
Well designed commands allow fast and powerful data
manipulation that graphical interfaces can’t replicate.
Navigation Commands
List
ls
Change Directory
cd
Print Working Directory
pwd
listing
The Basic command
The command generates a compact list of files and
directories
listing
Adding switches:
The ‘l’ switch gives detailed (“long”) output
listing
… and adding arguments
The argument defines which directory or pattern to list.
print working directory
One of the easiest commands, prints your location in the
directory tree.
change directory
Self explanatory, changes your position in the directory tree.
Combining all the Navigation commands allow you to explore
the file system as efficient as a graphical interface!
TAB COMPLETION!!!
Never let typing slow you down!
Pressing <TAB> while typing automatically completes what
you are typing as long as the computer can “guess” it!
Tab turns
into
File System
Interaction Commands
Copy
cp
Move
mv
Remove
rm
copy
Makes a copy of a file with a new name
Copy always take two arguments; first the file to be copied, and
then the name of the new file.
copy
To copy a directory, you need to copy recursively.
The “-r” switch makes the command recursively copy
everything within the directory as well.
move
Move behaves exactly the same as copy, but removes the original
Moving does not care about recursion.
move
The move command is also used to rename things!
Moving something into a new name is the same as changing
the name after all!
remove
Used to remove files or directories.
There is no trash bin on the command line!
If you delete something it’s GONE!
remove
Remove a directory! You need to specify recursion with “-r”.
This is since it affects every file and not just the top one!
File Interaction Commands
less
look inside files
head
print beginning of file
tail
print end of file
cat
print entire file
nano
basic text editor
less
Light-weight program for looking inside text files
You exit less by pressing “q” and scroll one page with <space>
head
Prints the first rows from a file, defaults to 10 lines but can be
asked to print any number of lines.
tail
Prints the last rows from a file, defaults to 10 lines but can be
asked to print any number of lines.
cat
Prints every row from a file. Short for concatenate as it can be
used to concatenate files.
nano
Light-weight text editor.
Command help is available at the bottom of the screen!
( ^ means <ctrl>, so you exit with <ctrl>+x )
The Great Summary
Move
mv
less
look inside file
List
ls
head
print start of file
Copy
cp
tail
print end of file
cat
print entire file
nano
edit file
Remove
Change Directory
rm
cd
Print Working Directory pwd
BASIC LINUX
FILE SYSTEM
S
Basic Linux File Structure
S /dev
This is where all the hardware is!
S /etc
This is where important stuff lives
S /home
This is where user files are
S /root
This is where the boss hangs out
S /tmp
This is where the system stores temp files
S /usr/local
This is where most programs are
S /var/log
This is where the log files are
Directory Tree
/
dev
etc
home
usr
var
martin
henrik
erik
local
log
Pictures
Documents
notes.txt
script.sh
photo.jpg
Special files: . and ..
Hidden files in UNIX start with a “.”, these can be viewed with
the “-a” switch for ls.
There are also the special files “.” and “..” in each directory.
. is a pointer to self, i.e. it references the directory itself
.. is a pointer to parent, i.e. to the directory containing the
current directory.
File Permissions
First row is d
rwx
rwx
rwx this is the file permissions!
The first “d” means that the file is a directory, the three triplets
following is “read”, “write” and “execute” permissions for
“user”, “group” and “other”.
This data is followed by “owner user” (martin) “owner group”
(staff), file size, date and name
Changing Permissions
The command for changing permissions is chmod.
ex. $ chmod 750 myscript.sh
The number 755 is derived from the binary representation of
three permission bits, “read, write, execute”.
111 = read, write and execute = 1×22+1×21+1×20 = 7
101 = read and execute = 1×22+0×21+1×20 = 5
000 = no permissions = 0×22+0×21+0×20 = 0
Note that sometimes changing permissions requires sudo
Questions?
Tutorial!
There is a tutorial at http://sgbc.slu.se/unix/
The tutorial deals with the things that we have looked at in this
lecture as well as some extra bonuses!
Download