adnan niazi november 2014. unix lecture goals goal 1: know basic unix commands and their use. goal...
TRANSCRIPT
UNIX Lecture Goals
Goal 1: Know basic UNIX commands and their use.
Goal 2: Understand the basic structure of a
common Unix system.
Goal 3: Know how to find information on more
advanced UNIX commands and their use.
New Concepts
Shell A “shell” is an interface to a system, we’ll use
BASH, the Bourne Again Shell.
Recursion Something that repeats in a way similar to
itself. (eg. a mirror reflecting a mirror …)
Variable A symbol representing a non-static value.
Pointer A variable that stores a reference to another
variable.
UNIX History
1969 – First Version of UNIX developed at Bell Labs by
AT&T
1975 – UNIX 6, the first to be widely available outside Bell
Labs. The first “Berkeley Software Distribution”
(BSD) is released.
1989 – UNIX System V, the last traditional UNIX version.
1991 – Linus Torvalds begin developing Linux.
“UNIX-like”
Today – UNIX itself, what’s now called “traditional UNIX” is not used, except by enthusiasts.
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.
In fact, most operating systems today except windows are “UNIX like”.
The command line
Host, tells
you
where you
are!User, tells you who you are!
The prompt! This is where
you write stuff
Command line structure
Format:
$ command [switches] [arguments]
Square brackets mean
“optional”!
The prompt! Tells you your scope.
Switches control the behavior of the command
Arguments are the “target” of the command
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.
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
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.
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
List ls
Copy cp
Remove rm
Change Directory cd
Print Working Directorypwd
less look inside file
head print start of file
tail print end of file
cat print entire file
nano edit file
Basic Linux File Structure
/dev This is where all the hardware is!
/etc This is where important stuff lives
/home This is where user files are
/root This is where the boss hangs out
/tmp This is where the system stores temp files
/usr/local This is where most programs are
/var/log This is where the log files are
Directory Tree
/
homeetc vardev usr
loglocalerikhenrikmartin
Documents
Pictures
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
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!