330 likes | 613 Views
Introduction to Unix. Lesson 8. Introduction to UNIX. What is an operating system?. Input/ Output. Command Interpreter. Accounting. Operating system. Security. Communications. Program Development Tools. Memory Management. Scheduling. The UNIX operating system. Scheduler
E N D
Introduction to Unix Lesson 8
What is an operating system? Input/ Output Command Interpreter Accounting Operating system Security Communications Program Development Tools Memory Management Scheduling
The UNIX operating system • Scheduler • Allows more than one person to use the system at the same time. • Shares the system’s resources among the users, allowing each a slice of the resources. • Programs running in memory are called processes • File system • A directory structure used to organize files in UNIX • Shell • The UNIX system’s command interpreter • A program that reads the lines you type and interprets them. • Sits between the user and the internals of the system
History of UNIX • In 1965 Bell joined GE and MIT in a project to develop a new OS called Multics • Wanted to provide simultaneous computer access to a large community of users • A smaller version written by some at Bell including Ken Thompson and Dennis Ritchie for PDP-7, later ported to PDP-11 (in 1971). • Name came as play on Multics – Unics, or UNIX • Thompson started to develop a Fortran compiler for Unix, but ended up developing B language. • B was an interpretive language with the inherent speed problems characteristic of such languages • Decided to improve on it so created next language, C • In 1973 Unix rewritten in C
Unix Popularity grows… • At the time (70’s) AT&T was not allowed to market computer products. • Universities were requesting copies of Unix for educational purposes. • By 1977 Unix system sites had grown to about 500 of which 125 were universities. • Unix popular in phone companies and you can see heavy influence in phone equipment. • In 1982 AT&T combined several versions and created UNIX System III. Other additions were made and System V was born in 1983. • UC-Berkeley had developed a variant for VAX machines which was called BSD. • By 1984 there were about 100,000 sites running UNIX
The variations of UNIX • BSD (Berkeley Software Distribution) • XENIX – version for microcomputers developed by MS • SunOS – UNIX variation by Sun • POSIX – an independent effort to define a standard OS environment – actually a family of standards. • System V release 4 (SVR4) – combined elements of System V release 3, BSD, SunOS, and Xenix to provide a common environment • Solaris – a version for Sun, 2.3 was POSIX compliant. • Linux – PC version by Linus Torvalds in 1991. • IRIX – a proprietary version used by Silicon Graphics • HP-UX – variant developed and sold by HP • AIX – IBM’s version for use on IBM workstations
Some differences to be aware of for Microsoft OS users • UNIX is case sensitive, thus • CC FILE1 is not the same as cc file1 • UNIX is open source, thus source code is readily available for it. • UNIX is not proprietary (as a whole) so its evolution is not controlled by a single organization/corporation • NT/2000 and UNIX are both multitasking, but UNIX also is multiuser (supports simultaneous users)
UNIX file system / bin etc usr dev home sh date who hosts passwd hosts.equiv src bin games tty1 hda1 cdrom user1 user2 user3 Redhat file1 .rhosts
LINUX • A number of different versions • Redhat • BSD • Slackware • Caldera • Debian • Incorporates the use of shells • Bash (Bourne again shell) variation on traditional Bourne shell – default. • pdksh (Public Domain Korn Shell) variation on original UNIX Korn shell. • tcsh – an enhanced version of the original Berkley C shell csh.
Some common Linux functions Function Program Editors vi, emacs Shells bash, tcsh, pdksh Text processing tetex, troff Tools awk (gawk– file/DB manipulation) Network programs telnet, ftp Electronic mail Elm, Pine
Programming languages available • C/C++ • JAVA • LISP • Prolog • Ada • Perl • Tcl/Tk • Fortran-to-C translator • Pascal-to-C translator • Compiler tools (lex and yacc (flex and bison))
Interacting with the Linux OS • The Shell is the interface between the user and the Linux OS • How you interact with the system will depend on how the system was configured. • Command Line Interpreter • GUI • Gnome • KDE
Some common CLI commands • ls – provide list of files in current directory • ls -l provides additional info on each file • ls -a lists all files in the directory (hidden) • ls -al combines the above two • ls doc* lists files that start with doc • Wildcards: * for any set of characters, ? for single character. • cp – copy a file • cp fileone filetwo copies fileone into filetwo, creating filetwo if it needs to • cd – change directory • cd docs changes current directory to docs • cd / changes to root directory • cd .. changes to parent directory
Some more commands • rm – remove (delete) a file • rm fileone deletes fileone • rm file* deletes all files that begin with ‘file’ • rm * deletes all files • rm * file deletes all files (space between * and file) • cat – display contents of a file • cat fileone displays contents of fileone • more – displays contents of a file screen by screen • more fileone displays contents of fileone
And just a few more commands • mv – renames or moves a file • mv fileone newname renames ‘fileone’ to be ‘newname’ • mv fileone docs/fileone moves fileone from current directory to ‘docs’ directory • mv fileone docs/newname moves fileone from current directory to ‘docs’ directory and renames it • mkdir – create a directory in current directory • mkdir docs creates a directory called ‘docs’ • mkdir /home/gwhite/docs creates a directory called ‘docs’ in directory /home/gwhite • rmdir – remove directory • rmdir docs removes directory called ‘docs’
A couple more quick Linux commands • pwd • lists current working directory • chmod 777 <filename> • Changes permission of <filename> to allow anybody to access it • chmod 700 <filename> • Changes permission of <filename> to allow only the owner to access it
And more • who – lists all users currently connected along with when, how long, and where they logged in. • finger – provides information about other users on your network • logout – logs you out of the system (ends your session) • halt – shuts down Linux
Some commands everybody should know • passwd – used to change your password. • man<topic> – used to obtain information about a topic • apropos <keyword> – used to find commands that are related to keyword
Devices • Files and directories contained on different HW devices (e.g. floppy drives, CD’s) and hard disk partitions are called file systems. • The Linux partition used to install the Linux system on is called the root partition. • The root partition ( indicated by a single slash, /) contains the main file system and user subdirectories. • To access files on another file system, say a CD-ROM, you need to attach that file system to your main system. • Attaching a file system is called mounting the file system.
Mounting a file system • The first step is to set up an empty directory to which you want to mount the file system. • Most Linux distributions, including Red Hat, have pre-created directories for this purpose. • /mnt/cdrom • /mnt/floppy • To mount a floppy, for example, you would: • mount device mountpoint • mount /dev/fd0 /mnt/floppy • When done, you need to unmount the device: • umount device-or-mointpoint (*** notice the spelling ***) • umount /mnt/floppy • Make sure you aren’t still using that device or it won’t let you unmount it. • These are sysadmin commands and not user commands!
Archive files • The tar utility (tape archive) creates archives for files and directories. • The tar utility is ideal for making backup copies of files or for combining several files into a singe file for transmission. • Command examples: • tar cvf myarch.tar mydir • Creates archive of mydir directory and calls the single file myarch.tar (the ‘v’ displays each filename as it is archived).` • tar xf myarch.tar • Extracts all files and subdirectories from the file myarch.tar
Compressed Archives • A compressed archive is an archive file created with tar and then compressed with gzip. It will generally have .tar.gz as extensions. • To install such a file, you first need to uncompress it with gunzip, then extract it with tar. • gunzip savefile.tar.gz • tar xvf savefile.tar • Instead of gunzip, you may also use gzip –d • You may also combine both with: • tar xzvf savefile.tar.gz
Installation of software packages • rpm is used to manage and install software packages. • The –i option is used to install software • rpm –i newsoftwarefile • RPM stands for “RedHat Package Manager” • An RPM software package operates as its own installation program for a software application. • Linux software applications often consist of multiple files that may need to be installed in different directories. • The program is most likely installed in /usr/bin • Installation may also require changes to config files
C • gcc (compiler for C), g++ (compiler for C++) • A sample C program (stored in file hello.c)#include <stdio.h>int main() { (void) printf(“Hello, World!\n”); return0; /* just to be nice */ } • gcc –o hello hello.c • (-o says executable version to be called hello) • now to invoke we type “hello”
Makefiles $ make gcc –c main.c gcc –c edit.c gcc –o game main.o edit.o $ File named makefile game: main.o edit.o gcc –o game main.o edit.o main.o: main.c gcc –c main.c edit.o: edit.c gcc –c edit.c If we were to edit main.c, then $ make gcc –c main.cgcc –o game main.o edit.o$
Editing -- the vi editor • Still one of the most widely used editors in the UNIX world today • A keyboard-based editor (emacs is another) • Uses the keyboard to specify commands and receive user input • Certain keys perform certain functions • Delete, insert, cursor movement, save, quit
vi commands • To edit a file with vi • vi <filename> • If <filename> exists it will load that file, if it doesn’t it will create it. • To exit, type ‘:’ • This moves the cursor to the command line at the bottom of the screen, then • ‘q’ quits the editor • ‘q!’ quits without saving • ‘w’ will save the file
vi commands • The vi editor in Linux (actually Vim) allows you to use the arrow keys to move around. • To insert text • ‘a’ enters text after the cursor • ‘i’ enters text before the cursor • To stop entering text, hit <esc> • To delete text • ‘dw’ deletes the word the cursor is on • ‘dd’ deletes the line the cursor is on • ‘x’ deletes the character the cursor is on • <del> and <backspace> also work • To search • /<pattern> searches forward for <pattern> • ‘n’ repeats previous search