1 / 25

Compsci215 Tut1

Compsci215 Tut1. Me Jerry Ren Postgraduate in compsci Graduated in 2007 with an average GPA 8.4 jerryjren@gmail.com. Unix. First developed for a game in 1969 by Ken Thompson and Dennis Ritchie The whole system was re-write in 1973 in “C” Linux, Mac OS X, FreeBSD all based on Unix.

Télécharger la présentation

Compsci215 Tut1

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. Compsci215 Tut1 • Me • Jerry Ren • Postgraduate in compsci • Graduated in 2007 with an average GPA 8.4 • jerryjren@gmail.com

  2. Unix • First developed for a game in 1969 by Ken Thompson and Dennis Ritchie • The whole system was re-write in 1973 in “C” • Linux, Mac OS X, FreeBSD all based on Unix

  3. Why study unix unix windows Close design Monolithic User-centric popular • Open design • Modular • Programmer-centric • Popular on servers

  4. Install unix? • Use UNIX server at uni • Or install Ubuntu Linux on your own pc • A free partition • Some internet usages • Use virtual box • http://www.virtualbox.org/ • Mount ubuntu image and install

  5. The Shell • commandinterpreter • Using putty on MS Windows • Login.cs.auckland.ac.nz • Upi, password • Programs and commands are run on a server

  6. Common commands 1 • echo - print a string • ls - list files / directories • cd - change directory • exit - cause the shell to exit with a status • cat - display contents of a file • who - display who’s logged in • pwd - print the absolute pathname of the current working directory

  7. Common commands 1 • mesg - do or do not disturb • write - write to other people • whoami - display the login name of the current user • touch – to create a new file • mkdir – to create a new directory • rm – remove a file • man - your most useful helper

  8. REMEMBER!! • Unix is case sensitive • A file called this and This is different • Command cd and CD is different

  9. man • man is the most useful command in shell • If you have any question, ask the “man” • To quit, type “q” or “ctrl + z” • Eg. man ls

  10. man

  11. ls command xye002$ ls music research teaching temp try xye002$ ls -Fa teaching ./ 210-2002/ 210-2004/ 215-2009/ 334-2005/ ../ 210-2003/ 215/ 334-2003/ ex1/ – The output of ls may vary from system to system (e.g. one - or multicolumn output, different colours for different types of files) – The -l option provides a more detailed description of the files: xye002$ ls -l teaching total 16 drwxr-xr-x 7 xye002 root 2048 Aug 4 2003 210-2002 drwxr-xr-x 8 xye002 staff 2048 Aug 13 2003 210-2003

  12. cp and mv command • xye002$ cp temp saved_temp • Tow copies • xye002$ mv temp saved_temp • Only one copy, same to rename

  13. rm command • To remove a file • xye002$ rm temp • To remove a folder • xye002$ rm –r folder

  14. Create and editing file • To Create a file • touch file1 • To open this file • cat file1 • To edit it by using vi or emacs • vi file1 • How to use vi. • Type “a” start editing • To quit without save, “Esc”, “:q”, enter • To quit with save, “Esc”, “:wq”, enter

  15. wildcards • * (asterisk or “splat”) The asterisk indicates there are zero or more of the preceding element • ? The question mark indicates there is zero or one of the preceding element • + The plus sign indicates that there is one or more of the preceding element • . The dot matches any single character • [abc] (the character class) A set of characters enclosed by the rectangular brackets [ and ] It matches a single character in the class, i.e. an a, b, or c • [x-z] (the range specification inside the class) matches a single character in the range x-z • [!x-z] ( negating the character class in all the shells but the C-shell): matches a single character but not in the range x-z

  16. Examples of using wildcards $ ls ch01 ch02 ch03 ch04 chap1 chap2 $ ls c*2 ch02 chap2 $ ls c*? ch01 ch02 ch03 ch04 chap1 chap2 $ ls ch?[23] ch02 ch03 $ ls *[2-4] ch02 ch03 ch04 chap2 $ ls *[!2-4] ch01 chap1

  17. File with special char • How to create a file called “ch*” or “hello world” • Use escaping and quoting • touch ‘hello world’ • rm ‘ch*’

  18. Different Quoting • " (double quote) stops wildcard expansion • ’ (single quote) stops wildcard expansion and variable substitution • ‘ (magic quote or grave accent) runs the quote statement and replaces quotation with the output

  19. Different Quoting • Double quote • $echo “path is $PATH” path is /usr/local/742/ns-allinone/bin:/usr/local/742/ns-allinone/tcl8.4.14/unix:/usr/local/742/ns-allinone/tk8.4.14/unix:/usr/local/742:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/game • Single quote • $echo ‘path is $ PATH’ path is $PATH

  20. Everything is a file in Unix • Current directory (.) • Parent directory (..) • Home directory (~)

  21. File redirection • ls -l > listing Creates (or overwrites the contents of) the file called listing, which contains the output from ls • rev < davinci.txt > english.txt Uses both input and output file redirection simultaneously rev takes input from davinci.txt, writes output to english.txt Reverses every line in davinci.txt and outputs to english.txt

  22. Change permission code • Create a shell script and how to run it • touch myscript.sh $ ls -l total 0 -rw-r--r-- 1 xye002 all 4 Jul 20 15:00 myscript.sh • chmod u+x myscript.sh $ ls -l total 0 -rwxr--r-- 1 xye002 all 4 Jul 20 15:00 myscript.sh

  23. more commands • cut • paste • sort • Uniq • head • tail • tr • cmp, comm and diff

  24. Any questions?

  25. Symbolic vs Hard links • Symbolic links exist in contrast to hard links. Hard links may not normally point to directories and they can not link paths on different volumes. Symbolic links may point to any file or directory irrespective of the volumes on which the source and destination reside. • http://en.wikipedia.org/wiki/Symbolic_link

More Related