1 / 36

Lecture 1: Introduction, Basic UNIX

Lecture 1: Introduction, Basic UNIX. Advanced Programming Techniques. Why are we here?. What’s a computer Why do we run programs? What is needed to create a program?. Applications. Shell . Kernel (OS). Hardware. Structure of a typical OS. There are many standard applications:

quant
Download Presentation

Lecture 1: Introduction, Basic UNIX

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. Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques

  2. Why are we here? • What’s a computer • Why do we run programs? • What is needed to create a program?

  3. Applications Shell \ Kernel (OS) Hardware Structure of a typical OS • There are many standard applications: • file system commands • text editors • compilers • text processing

  4. Logging In • Create Acct • www.cs.drexel.edu/Account.php • Cluster • PuTTY/SSH • Log in • Password

  5. Home Directory • The user’s personal directory. E.g., • /home/kschmidt • /home/vzaychik • Location of many startup and customization files. E.g.: .vimrc .bashrc .bash_profile .forward .signature .plan .logout

  6. Unix Filesystem • Files • Directories • Other special files

  7. / bin etc home/ tmp usr hollid2 scully bin etc netprog unix X ls who The Filesystem (eg)

  8. Pathnames • Unique, on a given filesystem • Absolute vs. relative • ./ ../ ~/

  9. Pathname Examples / bin/ etc/ home/ tmp/ usr/ Hollid2/ scully/ bin/ local/ netprog unix/ X ls who Syllabus /usr/bin/ls /home/hollid2/unix/Syllabus

  10. Commands for Traversing Filesystem • ls • pwd • cd • rm • cp • mv • mkdir • rmdir

  11. Viewing files • cat • less, more • od • Comparing files • diff • cmp

  12. Copying, removing, linking • rm – remove file • mv – move (rename) file • cp – copy file • ln – create hard (inode) or soft (symbolic) links to a file • touch – update file modification time, create an empty file if file doesn’t exist

  13. Commands for directories • mkdir make directory • rmdir remove directory • Directories can also be moved or renamed (mv), and copied (cp –r)

  14. Commands for Archiving • tar – Tape Archive • makes a large file from many files • gzip, gunzip • compression utility • tar on Linux does compression with the z option: $ tar czf 571back.tgz CS571 $ tar xzf assn1.tgz

  15. File Permissions • Three types: • read abbreviated r • write abbreviated w • execute abbreviated x • There are 3 sets of permission: • user • group • other (the world, everybody else)

  16. ls -l and permissions -rwxrwxrwx UserGroup Others Type of file: - –plain file d –directory s – symbolic link

  17. Bourne-again Shell (bash) • Shells • Startup • Upon login (interactive), at the shell prompt • customization files: • /etc/profile • .bash_profile • .bashrc

  18. Command syntax • First token is the “command” • Come in 3 flavors: • alias • shell builtin • External programs (utilities) • $PATH • Use type

  19. Command Options and Arguments commandoption(s) arguments • Options (flags) • Short • Long • Option args • Arguments

  20. man Pages • man • info

  21. Some simple commands • date – print current date • who – print who is currently logged in • finger usr – more information about usr • ls -ao – lists (long) all files in a directory • du -sh – disk usage summary, human readable • quota

  22. Standard I/O • The shell establishes 3 I/O channels: • stdin (0) • stdout (1) • stderr (2) • These streams my be redirected to/from a file, or even another command

  23. Basic control codes • Ctrl-D (^D) • set ignoreeof • Ctrl-C (^C) • Ctrl-U (^U) • Ctrl-Z (^Z) • Ctrl-L (^L)

  24. Shell metacharacters • Some characters have special meaning to the shell: • I/O redirection < > | • wildcards * ? [ ] • others & ; $ ! \ ( ) space tab newline • These must be escaped or quoted to inhibit special behavior

  25. Shell Variables • Values • Assignment • Reading

  26. Shell maintains variables • Some common ones: $PATH – list of directories to search for utilities $PS1 – Primary prompt $HOME – user’s home directory $USER – user’s login name $PWD – current working directory

  27. set command (shell builtin) • The set command with no parameters will print out a list of all the shell variables • Sets options in the shell • -o • -noclobber • -ignoreeof

  28. Quoting • Escape char • Strong quoting • Weak quoting

  29. I/O Redirection • > - output to a file (clobber) • >> - append • < - input from a file • 2> - redirect stderr

  30. Pipes – connecting processes • A pipe is a holder for a stream of data. • A pipe can be used to hold the output of one program and feed it to the input of another. prog1 prog2 STDOUT STDIN

  31. filters • Programs that read some input (but don’t change it), perform a simple transformation on it, and write some output (to stdout) • Some common filters… • wc – word count (line count, character count) • tr – translate • grep, egrep – search files using regular expressions • sort – sorts files by line (lexically or numerically) • cut – select portions of a line • uniq – Removes identical adjacent lines • head, tail – displays first (last) n lines of a file

  32. The Unix Philosophy • Stringing small utilities together with pipes and redirection to accomplish non-trivial tasks easily • E.g., find the 3 largest subdirectories: $ du –sh * | sort –nr | head -3 120180 Files 22652 Zaychik 9472 tweedledee.tgz

  33. pipes and combining filters • Connect the output of one command to the input of another command to obtain a composition of filters • who | wc -l • ls | sort -f • ls -s | sort -n • ls -l | sort -nr -k4 • ls -l | grep ‘^d’

  34. Process Control • Processes run in a subshell • Subshells inherit exported variables • Each process is has an ID (pid) and a parent (ppid) • Use the ps utility to look at some processes: $ ps PID TTY TIME CMD 350 pts/4 00:00:00 bash 22251 pts/4 00:00:00 vim 22300 pts/4 00:00:00 ps

  35. Job Control • The shell allows you to manage jobs • place jobs in the background • move a job to the foreground • suspend a job • kill a job

  36. Editors • A text editor is used to create and modify text files. • The most commonly used editors in the Unix community: • vi (vim on Linux) • $ vimtutor • emac • $ emacs • Then, hit ctrl-h t (that’s control-h, followed by ‘t’) • You must learn at least one of these editors

More Related