1 / 272

Unix and C Programming

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

nola
Download Presentation

Unix and C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix and CProgramming Dr. Cong Xing Dept. of Math & CMPS

  2. 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

  3. 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.

  4. Ex: What is the max memory space (in terms of bytes) can a 32-bit CPU address? 232 = 22 210 210 210 = 4GB memory 32-bit long register

  5. 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)

  6. 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

  7. 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

  8. 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.

  9. utilities shell user File sys kernel

  10. 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)

  11. 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

  12. Example: Mac OS X

  13. X terminal in Mac OS X

  14. 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

  15. 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

  16. Group id: you may be assigned to a group of users. • Login shell • Terminals • Called tty (abbr. for teletype) in Unix • Putty (use telnet or ssh)

  17. Getting Started • Use putty ssn or telent to login to eclipse

  18. Successful login shows:

  19. Use Window’s (old version) telnet to login to eclipse • Start Run telnet • Type o • Type host-name • type your id and password at prompt

  20. 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

  21. 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

  22. $ 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

  23. 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

  24. 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.

  25. 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.

  26. 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

  27. 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

  28. 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),

  29. 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 (-)

  30. avoid using any special symbols and Unix commands in file names. • Absolute pathnames • full pathnames that identify the location of a file in relation to root • ex: (tree on next slide) /home/al/cmps/hw1 /home/smith

  31. root / home smith al cmps math hw2 hw1

  32. ~ (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

  33. 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)

  34. 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)

  35. 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

  36. 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,

  37. 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

  38. name4 name1 name2 name3

  39. 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

  40. drwxr-xr-x 2 xing staff 512 Jan 23 11:40 test File type links owner group name Size (byte) Date & time Access control

  41. 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)

  42. 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)

  43. = -- 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

  44. 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)

  45. more ex: rwxrwxrwx = 777 rwxr--r-- = 744 rw-rw---- = 660 --------- = 000

  46. Conversion between binary and decimal numbers

More Related