1 / 47

Big Review

CSI 135. Big Review. Why Review?. Some students in this class are still struggling with basic issues and with understanding the context in which we are working So we need to review what we’ve done so far in class and how it all fits together. Basic Unix Commands. $ ls $ pwd $ cd

macon
Download Presentation

Big Review

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. CSI 135 Big Review

  2. Why Review? • Some students in this class are still struggling with basic issues and with understanding the context in which we are working • So we need to review what we’ve done so far in class and how it all fits together

  3. Basic Unix Commands $ ls $ pwd $ cd $ touch $ mkdir $ rmdir $ rm $ who $ cp $ mv $ date $ cal $ echo $ history $ env $ sort

  4. Basic Unix Commands $ ls $ pwd $ cd $ touch $ mkdir $ rmdir $ rm $ who List files Show current directory Change directory Create file or update timestamp Make directory Remove directory (if emtpy) Remove Show who is logged in

  5. Basic Unix Commands $ cp $ mv $ date $ cal $ echo $ history $ env $ sort Copy Move (or rename) Show date & time Show calendar Repeat typed text Show previous commands Show user environment Sort lines of characters

  6. Basic Unix Commands $ cat $ more $ head $ tail $ wc $ ps Display contents of a file Show file screen at a time Show top of file Show bottom of file Count characters, words and lines Show the running processes

  7. Basic Unix Commands $ ls –l -rw------- 1 shsstaff 8876 May 30 2008 my.txt drwx------ 2 shsstaff 512 Mar 13 2006 mydir

  8. Basic Unix Commands $ ls -l /usr/bin | egrep 'date|who' -r-xr-xr-x 1 root bin 8552 Jan 5 2000 date -r-xr-xr-x 1 root bin 6240 Jan 5 2000 rdate -r-xr-xr-x 1 root bin 6280 Jan 5 2000 rwho -r-xr-xr-x 1 root bin 13088 Apr 3 2001 who

  9. Basic Unix Commands $ ls -ld local lrwxrwxrwx 1 shs staff 14 Nov 3 16:25 local -> /usr/local/bin

  10. Basic Unix Commands $ ls –ld .

  11. Basic Unix Commands $ ls –ld . drwx------ 61 shsstaff 3584 Nov 3 16:25 .

  12. Basic Syntax $ command [options] [arguments] Examples: $ ls–l myfile $ cd/tmp $ cal 10 2011 $ sort –n nums Notice that options are prefaced with hyphens Also, options are optional (thus, their name!)

  13. Getting Help $ man <command> $ apropos <word> Examples: $ man ls $ apropos logout

  14. Regular Expressions ? Stands for a single character in commands such as ls * Stands for zero or more characters Examples: $ ls ? List all one-character filenames $ ls a* List all files that start with “a”

  15. Regular Expressions [abc] stands for any single letter in the list shown (in this case, a, b or c) [a-z] stands for any single lowercase letter [A-Z] stands for any single uppercase letter [a-zA-Z] stands for any single letter

  16. Variables $ myvar=11 $ echo $myvar 11 $ favcolor= ”green” $ echo $favcolor green

  17. Environment • The env command will show you a list of variables used to create your working environment and their values • For example: USER=csi135b11 HOME=/u/students/csi135/b11

  18. Your “dot files” • Files such as the .bashrc_profile and .bashrc files in your home directory on vader are read when you log in and set up your user environment. • Before your dot files are read, however, a system file, /etc/profile, is read first. This file is read by the shell when any user logs in.

  19. Your dot files /etc/profile .bash_profile .bashrc

  20. The Unix Filesystem jdoe etc msmith bin home / local The Unix filesystem has one root (base) called / usr bin var

  21. The Unix Filesystem /home might be a separate file system jdoe etc msmith bin home / local The Unix filesystem may be comprised of multiple file systems mounted into one tree-like structure usr bin var

  22. The Unix Filesystem jdoe etc msmith bin home / local /usr/local/bin usr bin Absolute pathname var

  23. The Unix Filesystem jdoe etc msmith bin home / local /home/msmith usr bin var Absolute pathname

  24. The Unix Filesystem jdoe etc msmith bin home / local local/bin usr bin Relative pathname var

  25. The Unix Filesystem jdoe etc msmith bin home / local ../msmith usr bin var Absolute pathname

  26. More Advanced Commands • grep match content • awk select fields • cut select characters or fields

  27. More Advanced Commands • grepgrep word textfile • awkawk ’{print $2}’ textfile • cut cut –c1-3 textfile

  28. Pipes • Using a | to send the output of one command to be the input of another command $ tail myfile | sort $ head myfile | wc –w $ ls | tail -3

  29. Redirection • Sending the output of commands to files or to the bit bucket $ tail myfile > newfile $ head myfile >> logfile $ cat dumfile 2> /dev/null

  30. Quotes $ echo ”hello, $USER” hello, csi135b11 $ echo ’hello, $USER’ hello, $USER

  31. Backticks • Putting text within backticks makes the shell try to interpret the text as a Unix command and execute it $ echo Today is `date`

  32. Scripts • Putting Unix commands in a file and making the file executable makes it a script $ echo date > showdate $ chmod 755 showdate

  33. Scripts #!/bin/bash echo Hello, $USER echo Today is `date +%A`

  34. Arguments $0 name of script $1 first argument $2 second argument $3 third argument $* list of arguments

  35. More Advanced Scripts • if/then/else statements • for loops • while loops

  36. if/then if test condition then commands fi if [ condition ]; then commands fi

  37. if/then/else if test condition then commands else commands fi

  38. if/then/else if [ condition ]; then commands else commands fi

  39. For loops for number in 1 2 3 do echo $number is a number done

  40. While loops while true do commands sleep 5 done

  41. Case statements case month in Jan) tail -5 jan.log;; Feb) tail -5 feb.log;; *) echo ”No log available for $month”;; esac

  42. File Systems partitions

  43. File Systems partitions data blocks

  44. File Systems partitions data blocks meta-data (owner, permissions, etc.)

  45. File Systems partitions data blocks meta-data (owner, permissions, etc.)

  46. File Systems partitions log kjones msmith jdoe var home /

  47. File systems • The df command displays a list of the file systems on a Unix system, including how full they are and where they are mounted (i.e., attached to the Unix file system tree) • As a Unix user, you might want to know this if you can’t save a file (no space left on device) • As a Unix systems administrator, you would need to clean up the file system so users can work

More Related