Unix and the Mac OS X Terminal an Introduction

Unix and the Mac OS X Terminal an Introduction

Unix and the Mac OS X Terminal An Introduction J. F.Weiher 2004 1 2 Basic Concepts GUI vs. Unix Command Line Directories Paths Input/Output 3 Basic Concepts GUI vs. Unix Recognition — Recall Order from Menu — Cook yourself Limited — Need to Learn Learning curve Shell 4 User Friendly? 5 Learning Curves Difficulty Time Time Time GUI Aqua CLI 6 Basic Concepts Command Line Syntax Critical Case Sensitive Command Name Options = Switches or Flags Arguments = Objects of Command Example ls -al ~/Documents 7 Basic Concepts Directories Root Subdirectories Users and Home 8 Basic Concepts Paths Full file designation = <path>/<filename> Paths - Absolute /Users/you/Documents - Relative Documents Mac OS X Typing Aids -drag file to terminal - tab completion 9 Basic Concepts Input/Output stdin and stdout Specification in command line overrides default Redirection > {file} >> {file} < {file} Pipes <cmd> | <cmd> 10 Getting Help man <command> -[hk] whatis <command> apropos <word> <prog> --help <prog> - h Experiment Research the item 11 Some Commands pwd cd <dir> 0-1 ls <dir> -[alFtrRd] 0-n file <file> 1-n touch <file> 1-n rm <file> -[i rR] 1-n mkdir <dir> 1-n rmdir <dir> 1-n 12 Example 1 Welcome to Darwin! • [localhost:~] weiher% who am I weiher ttyp3 Oct 11 07:03 [localhost:~] weiher% whoami weiher [localhost:~] weiher% pwd /Users/weiher [localhost:~] weiher% ls -al /Users drwxr-xr-t 5 root wheel 126 Apr 27 2002 . drwxrwxr-t 65 root admin 2166 Oct 5 20:58 .. drwxrwxrwt 6 root wheel 264 Sep 28 16:43 Shared drwxr-xr-x 16 km staff 500 Aug 22 2002 km drwxr-xr-x 28 weiher staff 908 Oct 11 04:01 weiher 13 Some Path Shortcuts Drag Path from GUI Tab completion Cut and paste within Terminal Window ~ = home directory . = current directory location .. = parent directory / = root directory 14 Example 2 [localhost:~] weiher% pwd /Users/weiher [localhost:~] weiher% cd .. [localhost:/Users] weiher% pwd /Users [localhost:/Users] weiher% cd .. [localhost:/] weiher% pwd / [localhost:/] weiher% cd ~ [localhost:~] weiher% pwd /Users/weiher [localhost:~] weiher% 15 More Commands man <command> mv <file…> <to> -[i f] 1-n, 1 cp <file…> <to> -[i] 1-n, 1 more <file> sp, b, q, ? 1 less <file> b f h /<text> 1 in search mode n = next; N = previous head <file> -[1 2 3…] 1 tail <file> -[1 2 3…] 1 wc < file> -l -w -c 1-n 16 Some Terminal Tricks <cmd>| pbcopy = output to clipboard pbpaste | <cmd> = input from clipboard ^<str1>^<str2>^ = substitute str2 for str1 Arrow keys for navigation history [m] !n !<chrs>:p set history = <n> echo $history open <dir> = orders Finder to open <dir> open -a <application> = launch it open -e <file> = edit <file> with TextEdit 17 Concatenate cat {file} list file to default output cat default input and output cat > {file} default input to file to ^D cat >>{file} same but append to file cat {file} | pbcopy copy file to clipboard pbpaste |cat display clipboard cat {file1} {file2}… > {output file} 18 More Terminal Tricks locate <path/file> or “*<str>” find <st-dir> [criteria] powerful but complex ‘<string>’ or “<string>” \ = quote next character backtick quotes `<expression>` ps -ax | grep <application> = returns PID kill - STOP <PID> kill -CONT <PID> kill <PID> sudo <cmd> 19 Special Characters * ? [ ] { } filename matching & expansion $ denotes variables ! ^ history reference & substitution & sends command to background | pipe > < I/O redirection 20 Special Characters (cont) ; command separator (and) && command separator (if) || command separator (or) Space argument separator Tab file completion in tcsh ( ) subshell execution ` quote for command substitution \ ‘ “ quote characters 21 Terminal a Rich Resource The directory /usr/share/misc […:/usr/share/misc] weiher% grep AGC Airport AGC:Pittsburgh/Allegheny County [localhost:/usr/share/misc] weiher% [:/usr/share/misc] weiher% grep 19810 zipcodes 19810:Wilmington, DE [localhost:/usr/share/misc] weiher% [:/usr/share/misc] weiher% grep Bremen inter.phone 49:421:Bremen:Germany, Fed. Rep. Of [localhost:/usr/share/misc] weiher% 22 Wildcards * in command line ? in command line [abc] in expressions or CL [^abc] in expressions or CL [a-dA-D] in expressions pr CL {chrs, chrs,chrs}in command line . in command line .. in command line 23 GREP Searches in 1-n files for a string grep [opts] <pattern> <file…> Options: -iclIrw More available but start simple grep -ic jim * grep -rl “Kontextkontrolle” /* grep -i "[tb]o[mb]" grepfile1 grep -i "[tb]o[mb]" grepfile? 24 Some More Utilities ftp <remote cpu> telnet <remote cpu> finger <user@remote cpu> uptime cal bc 25 ftp Example [localhost:~] weiher ftp udel.edu 220% copland.udel.edu FTP server (Version wu-2.6.2(1) Mon Aug 11 12:44:29 EDT 2003) ready. Name (udel.edu:weiher): weiher 331 Password required for weiher. Password: ****** 26 ftp Example pt 2 230 User weiher logged in. Remote system type is UNIX. Using binary mode to transfer files. ftp> cd public_html 250 CWD command successful 27 ftp Example pt 3 ftp> ls Bodmer* 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. -rw-r--r-- 1 weiher 0966 250927 Aug 30 17:09 BodmerWortschatzAlpha.pdf 226 Transfer complete. 28 ftp Example pt 4 ftp> put (local-file) /Users/weiher/grepfile1 (remote-file) grepfile1 local: /Users/weiher/grepfile1 remote: grepfile1 200 PORT command successful. 150 Opening BINARY mode data connection for grepfile1. 226 Transfer complete. 59 bytes sent in 0.261 seconds (226 bytes/s) 29 ftp Example pt 5 ftp> ls grep* 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. -rw-r--r-- 1 weiher 0966 59 Nov 2 18:30 grepfile1 226 Transfer complete. 30 ftp Example pt 6 ftp> quit 221-You have transferred 59 bytes in 1 files. 221-Total traffic for this session was 2357 bytes in 4 transfers. 221-Thank you for using the FTP service on copland.udel.edu. 221 Goodbye. [localhost:~] weiher% 31 Some Hints Remember spaces count! Copy terminal output and paste in text document for printing/saving/study Practice in a special account Backup regularly--just in case Remember touch and cat to quickly create files for practice Be nice; logout of terminal session ^H = backspace; ^D = end of file 32 Regular Expressions . matches any single character [xyz] any one character of x,y,z [^xyz] that is not x, y, or z [x-z] in the range x to z * preceding pattern 0 or more times ? preceding pattern 0 or 1 times + preceding pattern 1 or more times ^ the start of a line $ the end of a line \x or [x] removes any special meaning of x 33 finger Example […:~] weiher% finger [email protected] [udel.edu] X.500 Finger Service... 3 exact matches for "flexman": Edmund.A..Flexman Edmund.Arthur.Flexman Student, Division of Continuing Education, Ruth.M.Flexman Student, Division of Continuing Education, NRQ, Undergraduate, non-degree Coordinator, CE-Prof & Noncredit Programs 34 finger Example pt 2 […] weiher% finger [email protected] [udel.edu] X.500 Finger Service... 1 exact match found for "Ruth.M.Flexman": "Ruth M Flexman, CE-Prof and Noncredit Programs" Also Known As: Ruth M Flexman E-Mail Address: [email protected] Work Phone: +1 302-573-4416 Title: Coordinator, CE-Prof & Noncredit Programs … Uniqname: flexman 35 telnet Example [~] weiher% telnet udel.edu Trying 128.175.13.92... Connected to udel.edu. Escape character is '^]'. SunOS 5.9 login: weiher Password:****** Using project 0966, ALL-EMAIL You have $483.97 remaining in this account. 36 telnet Example pt 2 Last login: Sun Nov 2 21:08:32 from ppp-as37-25.nss Sun Microsystems Inc. SunOS 5.9 copland.udel.edu% quota -v Disk quotas for weiher (uid 14158): Filesystem usage quota limit timeleft /home/usra 17292 24576 24576 copland.udel.edu% logout Connection closed by foreign host. 37 Last Words Version Changes: Apple giveth & taketh away [localhost:~] weiher% Bill Gates OK? kill Gates? /Library/Documentation/Commands /grep/grep_toc.html Also for diffutils, dc, gzip 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    28 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us