Introduction to Unix BorisBoris KonevKonev [email protected] http://www.csc.liv.ac.uk/~konev Important information Instructor: – Boris Konev – Office: 1.12 – Email: [email protected] – Web resources: www.csc.liv.ac.uk/~konev/COMP110 NoNo lectureslectures onon Monday!!Monday!! Objectives • Basic structure of the operating system • What makes Unix special? • Unix System Design • Essential commands • Essential concepts • Shells • Shell programming • Text processing • Unix utilities Why Bother Studying Unix? • Most powerful computers (supercomputers) use the Unix operating system • Unix runs the Internet • Unix is used as an embedded system in hardware – networking, user appliances (DVD players) • A knowledge of Unix is likely to be helpful in your future career, regardless of where you pursue it. History of Unix 1960s “multics” project (MIT, GE, AT&T) 1970s AT&T Bell Labs 1970s/80s UC Berkeley 1980s DOS imitated many Unix ideas Commercial Unix fragmentation GNU Project 1990s Linux now Unix is widespread and available from many sources, both free and commercial Unix Systems • Commercial – SunOS/Solaris Sun Microsystems – Digital Unix (Tru64) Digital/Compaq – HP-UX Hewlett Packard – Irix SGI – UNICOS Cray – Mac OS X Apple – … • Free – NetBSD, FreeBSD, … – Linux – … What makes Unix so special? (1) • Portability (runs on almost every hardware) • Old and popular – it is easy to find information and get help • Simplicity, elegance & flexibility • Time-sharing: multi-tasking & multi-user environment • Unix is very stable – computers running Unix almost never crash What makes Unix so special? (2) • Unix is very efficient – it gets maximum number crunching power out of your processor (and multiple processors) – it can smoothly manage extremely huge amounts of data – it can give a new life to otherwise obsolete Macs and PCs • System design decisions (made by programmers for programmers) • Free and open source flavors available (Linux, *BSD) • It is not Windows ☺ The Unix Philosophy • A large set of primitive tools, which can be put together in an infinite number of powerful ways • An example: – Three separate tools are necessary to develop software: • Text editor • Compiler • Debugger – MSVC is an “IDE” (“Integrated Development Environment”) • All three tools are found in one shrink-wrapped box – (There are IDE tools for Unix) Unix Has Home Drawbacks • Unix computers are controlled by a command line interface – NOT user-friendly – difficult to learn, even more difficult to truly master • Hackers love Unix – there are lots of security holes (first software viruses were Unix-specific) – most computers on the Internet run Unix , so hackers can apply the same tricks to many different computers • There are many different versions of Unix with subtle (or not so subtle) differences Mac OS X The K Desktop Environment (KDE) Gnome Operating Systems Managing Hardware and Software Disk Screen Keyboard Drive Printer Application Software Utilities Unix Structure Kernel: controls hardware, creates processes, implements multi-tasking, manages file system Programs interact with the kernel • Unix Utilities: compilers, text processors,… • Shell: interprets user commands and sends them to kernel • GUI: based on X Window System • User programs Getting Started—Logging In Unix is a multi-user operating system • Login and password prompt to log in • login is user’s unique name • password is changeable; known only to user, not to system staff (!!) /like the debit card PIN number/ • Unix is case sensitive Passwords (1) Do: • make sure nobody is looking over your shoulder when you are entering your password. • change your password often • choose a password you can remember • use eight characters, more on some systems • use a mixture of character types – include punctuation and other symbols Passwords (2) Don’t: • use a word (or words) in any language • use a proper name • use information in your wallet • use information commonly known about you • use control characters • write your password anywhere • EVER give your password to anybody Command Line Interface (1) A command is a program that tells the Unix system to do something. It has the form: command options arguments • “Whitespace” separates parts of the command line • An argument indicates on what the command is to perform its action • An option modifies the command, usually starts with “-” Example: $ ls –l –a Papers Command Line Interface (2) • Not all Unix commands will follow the same standards • Options and syntax for a command are listed in the “man page” for the command Some First Commands (1) $ date Sun Feb 29 18:27:09 GMT 2004 $ who konev pts/0 Feb 27 18:15 konev pts/1 Feb 27 18:15 konev pts/2 Feb 27 18:22 konev pts/3 Feb 28 19:32 konev pts/4 Feb 29 18:17 (konev- lt.laptop.csc.liv.ac.uk) $ who –q konev konev konev konev konev # users=5 Some First Commands (2) $ finger $ finger <username> Who is logged in? $ finger <real name> $ man <command name> UNIX Manual Pages Hands-on Practice • In the department: – “Open Unix session” • At home: – A range of free Unix-like systems is available • FreeBSD (www.freebsd.org) • NetBSD (www.netbsd.org) • SUN Solaris (www.sun.com) • Linux Linux Distributions • RedHat – probably the best-known Linux company in the world • SUSE – popular in Europe, especially in Germany. Acquired by Novell in late 2003. • Mandrake – French distribution (special attention to usability) • Debian – completely non-commercial project • Knoppix – great for trying out Linux without getting your hands dirty as it runs directly from a CD, no installation required (www.knoppix.com) The Hierarchical File System Ordinary (plain) files - text, data, programs, etc Directories – files containing references to other files (folders) Special files - interfaces to hardware (e.g. /dev/rmt8), named pipes,… Unix Filenames • Unix is case sensitive (myfile.txt and MyFile.txt are different) • UNIX filenames contain only letters, numbers, and the _ (underscore), . (dot), and - (dash) characters. • Unix does not allow two files to exist in the same directory with the same name. – Whenever a situation occurs where a file is about to be created or copied into a directory where another file has that exact same name, the new file will overwrite (and delete) the older file. – Unix will generally may alert you when this is about to happen, but it is easy to ignore the warning. Filename Extensions • Most Unix filenames start with a lower case letter and end with a dot followed by one, two, or three letters: myfile.txt – However, this is just a common convention and is not required. – It is also possible to have additional dots in the filename. • For example, myfyle.txt.gz • The part of the name following the dot is called the “extension.” Some common extensions • The extension is often used to designate the type of file. • By convention: – files that end in .txt are text files – files that end in .c are source code in the "C” language – files that end in .html are HTML files for the Web – Compressed files have the .zip or .gz extension • Unix does not require these extensions (unlike Windows), but it is a sensible idea and one that you should follow The working directory At any given time when interacting with Unix, you are “working in” or “connected to” some directory. This is called your ``working directory.'' You will typically change your working directory (with the cd command, discussed later) several times during a single session. The pwd command prints the name of the current working directory. $ pwd [print working directory] Files & Directories $ file <filename(s)> $ ls <directory> $ ls –a $ ls –l To copy, move & remove a file $ cp <source-file> <destination-file> $ mv <source-file> <destination> $ rm <filename> Directories Making, removing & changing directories $ mkdir <directory-name> $ rmdir <directory-name> $ cd <directory-name> Displaying the current path $ pwd Wildcard Operators Asterisk * matches any character sequence, e.g. in file names Question mark ? matches any single character Brackets [ ] match specified characters $ cp *.doc WordFiles/ $ cp *.??? WordFiles/ $ rm ab*c $ ls art[12] Shortcuts • There are some important shortcuts in Unix for specifying directories – . (dot) means "the current directory" – .. means "the parent directory" - the directory one level above the current directory, so cd .. will move you up one level – ~ (tilde) means your Home directory, so cd ~ will move you back to your Home. • Just typing a plain cd will also bring you back to your home directory Unix File Protections • File protection (also known as permissions) enables the user to set up a file so that only specific people can read (r), write/delete (w), and execute (x) it. • Write and delete privilege are the same on a Unix system since write privilege allows someone to overwrite a file with a different one. File Owners and Groups • Unix file permissions are defined according to ownership. The person who creates a file is its owner. – Everyone is a user – You are the owner of files in your Home directory and all its sub-directories • In addition, there is a concept known as a Group. – Members of a group have privileges to see each other's files. – Users are in at least one group View File Permissions A “long” ls listing shows file permissions: $ls -l … -rw------- 1 konev csc 477658 Feb 21 17:20 main_save.ps -rw------- 1 konev csc 2040 Feb 3 17:33 michael -rw-r--r-- 1 konev csc 365089 Jun 4 2003 old.ps drwx--x--x 3 konev csc 1024 Feb 21 17:29 one_file … The first character in the attribute string indicates
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages55 Page
-
File Size-