Notes for Computer Information Technology 160
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

oct1.md 1.5KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # October 1
  2. - `#!`
  3. - `chmod [augo]+x -f`
  4. - Control Flow
  5. - If
  6. - While (until)
  7. - For ()
  8. - For () in ()
  9. ## Files and Commands
  10. ```
  11. $ bash ./f # run file "f" in a subshell
  12. $ bash -c <command> # run <command> in a subshell
  13. $ ./f # execute file "f"
  14. $ which <command> # where is <command> in path on filesystem
  15. $ locate <string> # find all instances of <string> on filesystem
  16. ```
  17. ## Find Commands
  18. ```
  19. $ find <location> -type d # find a directory
  20. $ find <location> -name <regular expression> # find by name
  21. $ find / -name lab3.txt # find file named "lab3.txt" in /
  22. ```
  23. You can search with [regular expressions](https://en.wikipedia.org/wiki/Regular_expression)
  24. ## File Command
  25. ```
  26. $ file <file> # get file type, examples:
  27. $ file ch1.lisp
  28. ch1.lisp: Lisp/Scheme program, ASCII text
  29. $ file ch5.py
  30. ch5.py: Python script, ASCII text executable
  31. ```
  32. ## Date Command
  33. ```
  34. $ date
  35. Mon Oct 1 13:22:55 PDT 2018
  36. $ date +<format> # date in <format>
  37. $ date +%A
  38. Monday
  39. $ DAY_OF_WEEK = $(date +%A)
  40. $ echo $DAY_OF_WEEK
  41. Monday
  42. ```
  43. ## If Statement
  44. ```
  45. #!/bin/bash
  46. if [[ boolean ]]; then
  47. echo "true"
  48. else
  49. echo "false"
  50. fi #end if
  51. ```
  52. ## If Statement with Date Command
  53. ```
  54. #!/bin/bash # ShaBang for Bash Script
  55. DAY_OF_WEEK=$(date +%A) # set var to output of date command eg "Monday"
  56. if [[ "$DAY_OF_WEEK" == "Monday" ]];
  57. then
  58. echo "It is Monday my dudes."
  59. echo "Today you have CIT160!"
  60. else
  61. echo "It is not Monday my dudes."
  62. echo "Better do your CIT labs!"
  63. fi
  64. ```