Unix and C Programming. Dr. Cong Xing Dept. of Math & CMPS. Access to Unix/Linux. Our Unix/Linux – (www.nicholls.edu ) telnet in MS Windows Unsecured Not supported any more (by most Unix systems) Putty – freeware, (telnet, ssh ) http://www.putty.nl/download.html
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Access to Unix/Linux • Our Unix/Linux – (www.nicholls.edu) • telnet in MS Windows • Unsecured • Not supported any more (by most Unix systems) • Putty – freeware, (telnet, ssh) • http://www.putty.nl/download.html • Login id and password • Id: ex: xing (lower case) • Password: set it up (first time login) • Change your password • Type passwdat prompt • Exit Unix • Type: logout
Introduction to Unix • Some useful terms: • Bit: a binary digit, either 0 or 1 • Byte: a grouping of 8 bits • Kilo (K): thousand (10^3) • Mega (M): million (10^6) • Giga (G): billion (10^9) • Hertz: used to measure clock speed. 1 hz = 1 pulse per second. 3 Ghz = 3 billion pulse per second.
Flops: short for floating point operations per second. Also used to measure the speed of computers. • The origin of Unix • Unix: The best OS people have written so far • Dennis Ritchie and Ken Thompson from AT&T • Multics – a failed OS, 1969 • GE, MIT, and AT&T (joint project)
Space Travel – a game • Space Travel rewritten on PDP-7 • Unix was born in 1971 • Naming: Unics (a pun on Multics) Unix • Turning Award (1983) • http://awards.acm.org/homepage.cfm?srt=all&awd=140
Unix and C • Unix written initially in assembly language (PDP series) (non-portable) • In 1973, Unix was rewritten in C • C was made for writing Unix
Major Components of Unix • Kernel: master control program. It manages resources and handles multitasking. • File System: organization of data. • Shell: interface between users and kernel. It interprets user commands and passes them to kernel. • Utilities: software tools built in Unix.
Versions of Unix • System V Unix: developed at AT&T. AT&T Unix is the original Unix. Most Unix systems on market are based on this. (e.g. IBM AIX and Sun Solaris) • BSD Unix: modified at Berkeley and as popular as AT&T Unix. (MacOS X is based on BSD Unix)
Unix-like systems: systems that work much like Unix, but do not use any part of AT&T Unix. (e.g. Linux and Minix) • X Window System • A GUI for Unix, developed at MIT • X terminals: a hybrid I/O device, has CPU and memory and can run X but not a complete computer in itself. (early days, when I was at grad school) • X terminal emulator: software simulation of X terminals
Books? • Any introductory Unix book can help • Or, any online tutorial • Understanding Unix by Stan Kelly-Bootle • Unix for Dummies by J.R. Levine and M.L. Young
Your Unix Account • The system administrator creates your account (and delete your account). • System administrator is the “super user” who can access any user’s account • Your account info: • Account name (id) • Password • Home directory
Shell prompt • $ -- Bourne shell, Korn shell, or bash shell • % -- C shell or TC shell • Will use $ throughout the slides • Script session • $script (to start a session) • $exit (to end a session) • Password change • $ passwd • Follow instructions
Trying out some simple commands • $ date Fri Jan 20 11:26:24 CST 2006 • $ w (check who is on the system) 11:30am up 116 day(s), 20:30, 3 users, load average: 1.92, 1.70, 1.67 User tty login@ idle JCPU PCPU what xing pts/6 9:11am 27 -bash xing pts/7 11:08am w root pts/4 10Oct05 2days bash
$ whoami • $ who • Email (built-in w/ Unix) • $ Mail <address> -- to send an email • $ Mail -- to read emails • Type x (or ^d or ^D) to quit reading emails • Elm: a menu-driven e-mailer (not built-in, needs to be installed) • Unix manual • $ man <any command> -- manual page for the command
Logging out • $ logout or • $ exit or • $ ^D • One of the above has to work • Spelling • Unix or UNIX? The latter is traditional, the former acceptable
Unix File System • File • Traditionally: a collection of related data • Unix extends the traditional meaning of file • To Unix, everything is a file (e.g., printer, disk drive,….) • File types • Ordinary files: common computer files • Special files: device file, represent physical devices.
Directory files: ordinary files and special files are organized into directory files or directories. • Ordinary files divided into two groups • Text files: (also called ASCII files) contains text and created/modified by text editors. • Binary files: containing non-textual data. Read and processed by programs.
Home and Working directories • Home directory: the directory when you log in the system. • Each user has a unique home directory • E.g.: /home/xing • To go to home directory (from anywhere): $ cd • Working directory: the current directory in which you are working. • Check what is your working directory: $ pwd
Unix File Tree • Files in Unix are organized in the form of a tree, typically as: Root (/) bin var dev etc home tmp usr Users’ home directories
Bin: short for “binary”. Contains shell software and common Unix commands • Dev: short for “devices”. Holds device files. • Etc: miscellaneous admin files (such as user list and passwords) • Home: holds users’ home directories • Tmp: temporary files are kept here. • Usr: user-related files, on-line manual are kept here. home directories (for some version of Unix),
Var: holds files whose contents varies frequently. Ex: users’ mail boxes are typically in /var/mail directory • File Names • 1 – 255 character long, combination of: • A – Z • a – z • 0 – 9 • period (.), underscore (_), dash (-)
~ (tilde) represents the absolute pathname of your home directory • ~<username> represents the absolute pathname of the home directory of that user • Relative pathnames • relative to working directory • . -- the current working directory • .. -- parent of current working directory
ex: given the previous tree, assume you are at /home/smith, then $cd ../al/cmps/ changes to cmps directory • Listing files • $ ls -- list all files in working directory • $ ls ../al/cmps -- lists all files in /home/al/cmps (assume pwd is /home/smith)
Hidden Files and Directories • a file or directory is hidden if it cannot be listed by ls. • $ ls -a -- to list all files and directories • Moving Files • $ mv oldfilepathname newfilepathname • ex: $ mv hw1 ../math/ ( suppose at /home/al/cmps)
Copying Files • $ cp filepathname1 filepathname2 • ex: : $ cp hw1 ../math/ $ cp ./hw1 ../math/ ( suppose at /home/al/cmps) • Creating Files by Redirecting • redirect the “standard output” • ex: $ ls > file1 -- result is saved in file1
note: redirection into an existing file overwrite the file • “double redirection” >> fixes the problem: • $ ls >> file1 -- result is appended to file1 • Links (hard, and symbolic) • One file may have more than one name • Each file has a unique i-node – an internal data structure representing the location (disk sector) of the file, the mode of the file,
creation date & time, and other info. • A (hard) link is a name that refers to a file’s i- node. • A link is created using the ln command • Ex: $ lnexistingfnnewfn • A symbolic link is a name that refers to another (file) name. • Ex: $ ln –s exitingfnnewfn
Long Listing • More info about files can be shown by $ ls –l drwxr-xr-x 2 xing staff 512 Jan 23 11:40 t -rw-r--r-- 1 xing staff 8 Apr 26 2004 test drwxr-xr-x 2 xing staff 512 Aug 24 00:06 test1
File access control: • First 3 symbols control what owner can do • Next 3 symbols control what group can do • Last 3 symbols control what public can do • for first position: d means directory - means file • r (read) – examine (but not change) the contents of a file • w (write) – change the contents of a file • x (execute) – run the file (program)
ex: rwxrwx--- owner and group users have read, write, and execute privileges, public has no privileges r--r--r-- everyone has read privilege only • changing file modes (1) • u – user (owner) • g – group • o – others (public) • a – all (owner, group, public)
= -- assign a permission (remove others) • + -- add a permission • - -- remove a permission • ex: • $ chmod u+x filename add execution to user • $ chmod g-rw filename remove read, write permission from group • $ chmod a=r filename add read to everyone and remove anything else • $ chmod u=rw,go=r filename give user read and write, everyone else read
changing file modes (2) • for each position, 1 indicates yes (permitted), 0 indicate no (not permitted) • ex: r--r--r-- is denoted by 100100100 • break down into 3 parts and regards each part a binary number, and convert it to decimal • then r--r--r-- can be denoted as 444 (1002=410)