├── .gitignore ├── README.md ├── _config.yml ├── _includes └── toc.html ├── _layouts ├── default.html └── default.html~ ├── _quarto.yml ├── _sass ├── fonts.scss ├── jekyll-theme-minimal.scss ├── jekyll-theme-minimal.scss.bak ├── minimal.scss └── rouge-github.scss ├── assets ├── img │ └── logo.svg ├── stat_bear.png └── styles.css ├── cpds.csv ├── exercises.qmd ├── file-management.qmd ├── file.png ├── index.qmd ├── license.qmd ├── ls_format.png ├── managing-processes.qmd ├── regex.qmd ├── shell-programming.qmd ├── testfile.txt └── using-commands.qmd /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Example code in package build process 6 | *-Ex.R 7 | 8 | # RStudio files 9 | .Rproj.user/ 10 | 11 | # produced vignettes 12 | vignettes/*.html 13 | vignettes/*.pdf 14 | 15 | /.quarto/ 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tutorial-using-bash 2 | 3 | Tutorial on using the bash shell. 4 | 5 | This tutorial covers: 6 | 7 | The Interactive Shell 8 | Basic File Management 9 | Regular Expressions 10 | Processes 11 | Shell programming 12 | Working with documents 13 | 14 | To see the tutorial: 15 | 16 | * You can go [here](https://htmlpreview.github.io/?https://github.com/berkeley-scf/tutorial-using-bash/blob/master/bash.html) to view in your browser. 17 | * If you're familiar with Git you can clone the repository and view `bash.html` in a browser. 18 | * If you're not familiar with Git you can download [this zip file](https://github.com/berkeley-scf/tutorial-using-bash/archive/master.zip), unzip it, and view `bash.html`. 19 | 20 | 21 | 22 | You can create the html via Pandoc (see Section 6 of bash.md) or R Markdown processing. The version in this repository was created via 23 | 24 | ``` 25 | Rscript -e "library(knitr); knit2html('bash.Rmd')" 26 | ``` 27 | 28 | Note that processing in that way causes bash.md to be overwritten. 29 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | remote_theme: pages-themes/minimal@v0.2.0 2 | plugins: 3 | - jekyll-remote-theme # add this line to the plugins list if you already have one 4 | title: Bash shell tutorial 5 | description: Training materials for using the bash (and zsh) shell. 6 | show_downloads: false 7 | logo: assets/img/logo.svg -------------------------------------------------------------------------------- /_includes/toc.html: -------------------------------------------------------------------------------- 1 | {% capture tocWorkspace %} 2 | {% comment %} 3 | Copyright (c) 2017 Vladimir "allejo" Jimenez 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | {% endcomment %} 26 | {% comment %} 27 | Version 1.2.0 28 | https://github.com/allejo/jekyll-toc 29 | 30 | "...like all things liquid - where there's a will, and ~36 hours to spare, there's usually a/some way" ~jaybe 31 | 32 | Usage: 33 | {% include toc.html html=content sanitize=true class="inline_toc" id="my_toc" h_min=2 h_max=3 %} 34 | 35 | Parameters: 36 | * html (string) - the HTML of compiled markdown generated by kramdown in Jekyll 37 | 38 | Optional Parameters: 39 | * sanitize (bool) : false - when set to true, the headers will be stripped of any HTML in the TOC 40 | * class (string) : '' - a CSS class assigned to the TOC 41 | * id (string) : '' - an ID to assigned to the TOC 42 | * h_min (int) : 2 - the minimum TOC header level to use; any header lower than this value will be ignored 43 | * h_max (int) : 6 - the maximum TOC header level to use; any header greater than this value will be ignored 44 | * ordered (bool) : false - when set to true, an ordered list will be outputted instead of an unordered list 45 | * item_class (string) : '' - add custom class(es) for each list item; has support for '%level%' placeholder, which is the current heading level 46 | * submenu_class (string) : '' - add custom class(es) for each child group of headings; has support for '%level%' placeholder which is the current "submenu" heading level 47 | * base_url (string) : '' - add a base url to the TOC links for when your TOC is on another page than the actual content 48 | * anchor_class (string) : '' - add custom class(es) for each anchor element 49 | * skip_no_ids (bool) : false - skip headers that do not have an `id` attribute 50 | 51 | Output: 52 | An ordered or unordered list representing the table of contents of a markdown block. This snippet will only 53 | generate the table of contents and will NOT output the markdown given to it 54 | {% endcomment %} 55 | 56 | {% capture newline %} 57 | {% endcapture %} 58 | {% assign newline = newline | rstrip %} 59 | 60 | {% capture deprecation_warnings %}{% endcapture %} 61 | 62 | {% if include.baseurl %} 63 | {% capture deprecation_warnings %}{{ deprecation_warnings }}{{ newline }}{% endcapture %} 64 | {% endif %} 65 | 66 | {% if include.skipNoIDs %} 67 | {% capture deprecation_warnings %}{{ deprecation_warnings }}{{ newline }}{% endcapture %} 68 | {% endif %} 69 | 70 | {% capture jekyll_toc %}{% endcapture %} 71 | {% assign orderedList = include.ordered | default: false %} 72 | {% assign baseURL = include.base_url | default: include.baseurl | default: '' %} 73 | {% assign skipNoIDs = include.skip_no_ids | default: include.skipNoIDs | default: false %} 74 | {% assign minHeader = include.h_min | default: 2 %} 75 | {% assign maxHeader = include.h_max | default: 6 %} 76 | {% assign nodes = include.html | strip | split: ' maxHeader %} 92 | {% continue %} 93 | {% endif %} 94 | 95 | {% assign _workspace = node | split: '' | first }}>{% endcapture %} 114 | {% assign header = _workspace[0] | replace: _hAttrToStrip, '' %} 115 | 116 | {% if include.item_class and include.item_class != blank %} 117 | {% capture listItemClass %} class="{{ include.item_class | replace: '%level%', currLevel | split: '.' | join: ' ' }}"{% endcapture %} 118 | {% endif %} 119 | 120 | {% if include.submenu_class and include.submenu_class != blank %} 121 | {% assign subMenuLevel = currLevel | minus: 1 %} 122 | {% capture subMenuClass %} class="{{ include.submenu_class | replace: '%level%', subMenuLevel | split: '.' | join: ' ' }}"{% endcapture %} 123 | {% endif %} 124 | 125 | {% capture anchorBody %}{% if include.sanitize %}{{ header | strip_html }}{% else %}{{ header }}{% endif %}{% endcapture %} 126 | 127 | {% if htmlID %} 128 | {% capture anchorAttributes %} href="{% if baseURL %}{{ baseURL }}{% endif %}#{{ htmlID }}"{% endcapture %} 129 | 130 | {% if include.anchor_class %} 131 | {% capture anchorAttributes %}{{ anchorAttributes }} class="{{ include.anchor_class | split: '.' | join: ' ' }}"{% endcapture %} 132 | {% endif %} 133 | 134 | {% capture listItem %}{{ anchorBody }}{% endcapture %} 135 | {% elsif skipNoIDs == true %} 136 | {% continue %} 137 | {% else %} 138 | {% capture listItem %}{{ anchorBody }}{% endcapture %} 139 | {% endif %} 140 | 141 | {% if currLevel > lastLevel %} 142 | {% capture jekyll_toc %}{{ jekyll_toc }}<{{ listModifier }}{{ subMenuClass }}>{% endcapture %} 143 | {% elsif currLevel < lastLevel %} 144 | {% assign repeatCount = lastLevel | minus: currLevel %} 145 | 146 | {% for i in (1..repeatCount) %} 147 | {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} 148 | {% endfor %} 149 | 150 | {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} 151 | {% else %} 152 | {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} 153 | {% endif %} 154 | 155 | {% capture jekyll_toc %}{{ jekyll_toc }}{{ listItem }}{% endcapture %} 156 | 157 | {% assign lastLevel = currLevel %} 158 | {% assign firstHeader = false %} 159 | {% endfor %} 160 | 161 | {% assign repeatCount = minHeader | minus: 1 %} 162 | {% assign repeatCount = lastLevel | minus: repeatCount %} 163 | {% for i in (1..repeatCount) %} 164 | {% capture jekyll_toc %}{{ jekyll_toc }}{% endcapture %} 165 | {% endfor %} 166 | 167 | {% if jekyll_toc != '' %} 168 | {% assign rootAttributes = '' %} 169 | {% if include.class and include.class != blank %} 170 | {% capture rootAttributes %} class="{{ include.class | split: '.' | join: ' ' }}"{% endcapture %} 171 | {% endif %} 172 | 173 | {% if include.id and include.id != blank %} 174 | {% capture rootAttributes %}{{ rootAttributes }} id="{{ include.id }}"{% endcapture %} 175 | {% endif %} 176 | 177 | {% if rootAttributes %} 178 | {% assign nodes = jekyll_toc | split: '>' %} 179 | {% capture jekyll_toc %}<{{ listModifier }}{{ rootAttributes }}>{{ nodes | shift | join: '>' }}>{% endcapture %} 180 | {% endif %} 181 | {% endif %} 182 | {% endcapture %}{% assign tocWorkspace = '' %}{{ deprecation_warnings }}{{ jekyll_toc -}} 183 | -------------------------------------------------------------------------------- /_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {% seo %} 9 | 10 | 13 | {% include head-custom.html %} 14 | 15 | 16 |
17 |
18 | {% if site.logo %} 19 | 20 | Berkeley Statistics Logo 21 | 22 | {% endif %} 23 | 24 |

{{ site.title | default: site.github.repository_name }}

25 | 26 |

{{ site.description | default: site.github.project_tagline }}

27 | 28 | {% include toc.html html=content h_max=3 class="docs_toc"%} 29 | 30 | 31 | {% if site.github.is_project_page %} 32 |

View the Project on GitHub {{ site.github.repository_nwo }}

33 | {% endif %} 34 | 35 | {% if site.github.is_user_page %} 36 |

View My GitHub Profile

37 | {% endif %} 38 | 39 | 40 | {% if site.show_downloads %} 41 | 46 | {% endif %} 47 | 48 | {% if site.github.is_project_page %} 49 |

This project is maintained by {{ site.github.owner_name }}, the UC Berkeley Statistical Computing Facility.

50 | {% endif %} 51 | 52 |

Hosted on GitHub Pages — Theme by orderedlist

53 | 54 | 55 |
56 |
57 | 68 |
69 | {{ content }} 70 |
71 | 72 |
73 |
74 |
75 |
76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /_layouts/default.html~: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {% seo %} 9 | 10 | 13 | {% include head-custom.html %} 14 | 15 | 16 |
17 |
18 | {% if site.logo %} 19 | 20 | Berkeley Statistics Logo 21 | 22 | {% endif %} 23 | 24 |

{{ site.title | default: site.github.repository_name }}

25 | 26 |

{{ site.description | default: site.github.project_tagline }}

27 | 28 | {% include toc.html html=content h_max=2 class="docs_toc"%} 29 | 30 | 31 | {% if site.github.is_project_page %} 32 |

View the Project on GitHub {{ site.github.repository_nwo }}

33 | {% endif %} 34 | 35 | {% if site.github.is_user_page %} 36 |

View My GitHub Profile

37 | {% endif %} 38 | 39 | 40 | {% if site.show_downloads %} 41 | 46 | {% endif %} 47 | 48 | {% if site.github.is_project_page %} 49 |

This project is maintained by {{ site.github.owner_name }}, the UC Berkeley Statistical Computing Facility.

50 | {% endif %} 51 | 52 |

Hosted on GitHub Pages — Theme by orderedlist

53 | 54 |
55 |
56 |

57 | 58 | {{ content }} 59 | 60 |
61 |
62 |
63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /_quarto.yml: -------------------------------------------------------------------------------- 1 | project: 2 | type: website 3 | 4 | website: 5 | site-url: https://computing.stat.berkeley.edu/tutorial-using-bash 6 | sidebar: 7 | style: docked 8 | title: "SCF Bash Shell Tutorial" 9 | logo: assets/img/logo.svg 10 | logo-href: https://statistics.berkeley.edu 11 | logo-alt: "UC Berkeley Statistics logo" 12 | tools: 13 | - icon: github 14 | href: https://github.com/berkeley-scf/tutorial-using-bash 15 | aria-label: GitHub 16 | contents: 17 | - href: index.qmd 18 | text: Overview 19 | - href: file-management.qmd 20 | text: File Management 21 | - href: using-commands.qmd 22 | text: Using Commands 23 | - href: shell-programming.qmd 24 | text: Shell Programming 25 | - href: managing-processes.qmd 26 | text: Managing Processes 27 | - href: regex.qmd 28 | text: Regular Expressions 29 | - href: exercises.qmd 30 | text: Exercises 31 | - href: license.qmd 32 | text: License 33 | 34 | format: 35 | html: 36 | theme: cosmo 37 | css: assets/styles.css 38 | toc: true 39 | -------------------------------------------------------------------------------- /_sass/fonts.scss: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'Noto Sans'; 3 | font-weight: 400; 4 | font-style: normal; 5 | src: url('../fonts/Noto-Sans-regular/Noto-Sans-regular.eot'); 6 | src: url('../fonts/Noto-Sans-regular/Noto-Sans-regular.eot?#iefix') format('embedded-opentype'), 7 | local('Noto Sans'), 8 | local('Noto-Sans-regular'), 9 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.woff2') format('woff2'), 10 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.woff') format('woff'), 11 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.ttf') format('truetype'), 12 | url('../fonts/Noto-Sans-regular/Noto-Sans-regular.svg#NotoSans') format('svg'); 13 | } 14 | 15 | @font-face { 16 | font-family: 'Noto Sans'; 17 | font-weight: 700; 18 | font-style: normal; 19 | src: url('../fonts/Noto-Sans-700/Noto-Sans-700.eot'); 20 | src: url('../fonts/Noto-Sans-700/Noto-Sans-700.eot?#iefix') format('embedded-opentype'), 21 | local('Noto Sans Bold'), 22 | local('Noto-Sans-700'), 23 | url('../fonts/Noto-Sans-700/Noto-Sans-700.woff2') format('woff2'), 24 | url('../fonts/Noto-Sans-700/Noto-Sans-700.woff') format('woff'), 25 | url('../fonts/Noto-Sans-700/Noto-Sans-700.ttf') format('truetype'), 26 | url('../fonts/Noto-Sans-700/Noto-Sans-700.svg#NotoSans') format('svg'); 27 | } 28 | 29 | @font-face { 30 | font-family: 'Noto Sans'; 31 | font-weight: 400; 32 | font-style: italic; 33 | src: url('../fonts/Noto-Sans-italic/Noto-Sans-italic.eot'); 34 | src: url('../fonts/Noto-Sans-italic/Noto-Sans-italic.eot?#iefix') format('embedded-opentype'), 35 | local('Noto Sans Italic'), 36 | local('Noto-Sans-italic'), 37 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.woff2') format('woff2'), 38 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.woff') format('woff'), 39 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.ttf') format('truetype'), 40 | url('../fonts/Noto-Sans-italic/Noto-Sans-italic.svg#NotoSans') format('svg'); 41 | } 42 | 43 | @font-face { 44 | font-family: 'Noto Sans'; 45 | font-weight: 700; 46 | font-style: italic; 47 | src: url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot'); 48 | src: url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot?#iefix') format('embedded-opentype'), 49 | local('Noto Sans Bold Italic'), 50 | local('Noto-Sans-700italic'), 51 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2') format('woff2'), 52 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff') format('woff'), 53 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf') format('truetype'), 54 | url('../fonts/Noto-Sans-700italic/Noto-Sans-700italic.svg#NotoSans') format('svg'); 55 | } 56 | -------------------------------------------------------------------------------- /_sass/jekyll-theme-minimal.scss: -------------------------------------------------------------------------------- 1 | @import "fonts"; 2 | @import "rouge-github"; 3 | 4 | body { 5 | background-color: #fff; 6 | padding:20px; 7 | font: 14px/1.5 "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 8 | color:#727272; 9 | font-weight:400; 10 | } 11 | 12 | h1, h2, h3, h4, h5, h6 { 13 | color:#222; 14 | margin:0 0 20px; 15 | } 16 | 17 | p, ul, ol, table, pre, dl { 18 | margin:0 0 20px; 19 | } 20 | 21 | h1, h2, h3 { 22 | line-height:1.1; 23 | } 24 | 25 | h1 { 26 | font-size:28px; 27 | } 28 | 29 | h2 { 30 | color:#393939; 31 | } 32 | 33 | h3, h4, h5, h6 { 34 | color:#494949; 35 | } 36 | 37 | a { 38 | color:#267CB9; 39 | text-decoration:underline; 40 | } 41 | 42 | a:hover, a:focus { 43 | color:#069; 44 | font-weight: bold; 45 | } 46 | 47 | a small { 48 | font-size:11px; 49 | color:#777; 50 | margin-top:-0.3em; 51 | display:block; 52 | } 53 | 54 | a:hover small { 55 | color:#777; 56 | } 57 | 58 | .wrapper { 59 | width:1100px; 60 | margin:0 auto; 61 | } 62 | 63 | blockquote { 64 | border-left:1px solid #e5e5e5; 65 | margin:0; 66 | padding:0 0 0 20px; 67 | font-style:italic; 68 | } 69 | 70 | code, pre { 71 | font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal, Consolas, Liberation Mono, DejaVu Sans Mono, Courier New, monospace; 72 | color:#333; 73 | } 74 | 75 | pre { 76 | padding:8px 15px; 77 | background: #f8f8f8; 78 | border-radius:5px; 79 | border:1px solid #e5e5e5; 80 | overflow-x: auto; 81 | } 82 | 83 | table { 84 | width:100%; 85 | border-collapse:collapse; 86 | } 87 | 88 | th, td { 89 | text-align:left; 90 | padding:5px 10px; 91 | border-bottom:1px solid #e5e5e5; 92 | } 93 | 94 | dt { 95 | color:#444; 96 | font-weight:700; 97 | } 98 | 99 | th { 100 | color:#444; 101 | } 102 | 103 | img { 104 | max-width:100%; 105 | } 106 | 107 | kbd { 108 | background-color: #fafbfc; 109 | border: 1px solid #c6cbd1; 110 | border-bottom-color: #959da5; 111 | border-radius: 3px; 112 | box-shadow: inset 0 -1px 0 #959da5; 113 | color: #444d56; 114 | display: inline-block; 115 | font-size: 11px; 116 | line-height: 10px; 117 | padding: 3px 5px; 118 | vertical-align: middle; 119 | } 120 | 121 | header { 122 | width:300px; 123 | float:left; 124 | position:fixed; 125 | overflow-y: scroll; 126 | top: 20px; 127 | bottom: 0; 128 | -webkit-font-smoothing:subpixel-antialiased; 129 | } 130 | 131 | //.docs_toc { 132 | // text-align:left; 133 | //} 134 | 135 | ul.downloads { 136 | list-style:none; 137 | height:40px; 138 | padding:0; 139 | background: #f4f4f4; 140 | border-radius:5px; 141 | border:1px solid #e0e0e0; 142 | width:270px; 143 | } 144 | 145 | .downloads li { 146 | width:89px; 147 | float:left; 148 | border-right:1px solid #e0e0e0; 149 | height:40px; 150 | } 151 | 152 | .downloads li:first-child a { 153 | border-radius:5px 0 0 5px; 154 | } 155 | 156 | .downloads li:last-child a { 157 | border-radius:0 5px 5px 0; 158 | } 159 | 160 | .downloads a { 161 | line-height:1; 162 | font-size:11px; 163 | color:#676767; 164 | display:block; 165 | text-align:center; 166 | padding-top:6px; 167 | height:34px; 168 | } 169 | 170 | .downloads a:hover, .downloads a:focus { 171 | color:#675C5C; 172 | font-weight:bold; 173 | } 174 | 175 | .downloads ul a:active { 176 | background-color:#f0f0f0; 177 | } 178 | 179 | strong { 180 | color:#222; 181 | font-weight:700; 182 | } 183 | 184 | .downloads li + li + li { 185 | border-right:none; 186 | width:89px; 187 | } 188 | 189 | .downloads a strong { 190 | font-size:14px; 191 | display:block; 192 | color:#222; 193 | } 194 | 195 | section { 196 | width:780px; 197 | float:right; 198 | padding-bottom:50px; 199 | } 200 | 201 | small { 202 | font-size:11px; 203 | } 204 | 205 | hr { 206 | border:0; 207 | background:#e5e5e5; 208 | height:1px; 209 | margin:0 0 20px; 210 | } 211 | 212 | footer { 213 | width:300px; 214 | float:left; 215 | position:fixed; 216 | overflow-y: scroll; 217 | bottom: 0; 218 | -webkit-font-smoothing:subpixel-antialiased; 219 | } 220 | 221 | .menu { 222 | position:fixed; 223 | top:0px; 224 | font-size:20px; 225 | background-color:white; 226 | // Doesn't wrap if leave this in: 227 | //width:100%; 228 | padding-top:20px; 229 | padding-bottom:20px; 230 | } 231 | 232 | .main { 233 | margin-top: 80px; 234 | } 235 | 236 | // Prevent anchor link from disappearing behind top nav. 237 | // https://markus.oberlehner.net/blog/simple-solution-for-anchor-links-behind-sticky-headers/ 238 | html { 239 | @media (min-height: 32em) { 240 | scroll-padding-top: 100px; // 1 241 | } 242 | } 243 | 244 | // This causes weird behavior of toc within header appearing at top of page 245 | // if we have 960, 720 for the two separate @media blocs; 246 | // Instead have both come into effect at same width. 247 | @media print, screen and (max-width: 1150px) { 248 | 249 | div.wrapper { 250 | width:auto; 251 | margin:0; 252 | } 253 | 254 | header, section, footer { 255 | float:none; 256 | position:static; 257 | width:auto; 258 | } 259 | 260 | header { 261 | padding-right:320px; 262 | } 263 | 264 | section { 265 | border:1px solid #e5e5e5; 266 | border-width:1px 0; 267 | padding:20px 0; 268 | margin:0 0 20px; 269 | } 270 | 271 | header a small { 272 | display:inline; 273 | } 274 | 275 | header ul { 276 | position:absolute; 277 | right:50px; 278 | top:52px; 279 | } 280 | } 281 | 282 | @media print, screen and (max-width: 1150px) { 283 | body { 284 | word-wrap:break-word; 285 | } 286 | 287 | header { 288 | padding:0; 289 | } 290 | 291 | header ul, header p.view { 292 | position:static; 293 | } 294 | 295 | pre, code { 296 | word-wrap:normal; 297 | } 298 | } 299 | 300 | @media print, screen and (max-width: 480px) { 301 | body { 302 | padding:15px; 303 | } 304 | 305 | .downloads { 306 | width:99%; 307 | } 308 | 309 | .downloads li, .downloads li + li + li { 310 | width:33%; 311 | } 312 | } 313 | 314 | @media print { 315 | body { 316 | padding:0.4in; 317 | font-size:12pt; 318 | color:#444; 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /_sass/jekyll-theme-minimal.scss.bak: -------------------------------------------------------------------------------- 1 | @import "fonts"; 2 | @import "rouge-github"; 3 | 4 | body { 5 | background-color: #fff; 6 | padding:20px; 7 | font: 14px/1.5 "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; 8 | color:#727272; 9 | font-weight:400; 10 | } 11 | 12 | h1, h2, h3, h4, h5, h6 { 13 | color:#222; 14 | margin:0 0 20px; 15 | } 16 | 17 | p, ul, ol, table, pre, dl { 18 | margin:0 0 20px; 19 | } 20 | 21 | h1, h2, h3 { 22 | line-height:1.1; 23 | } 24 | 25 | h1 { 26 | font-size:28px; 27 | } 28 | 29 | h2 { 30 | color:#393939; 31 | } 32 | 33 | h3, h4, h5, h6 { 34 | color:#494949; 35 | } 36 | 37 | a { 38 | color:#267CB9; 39 | text-decoration:none; 40 | } 41 | 42 | a:hover, a:focus { 43 | color:#069; 44 | font-weight: bold; 45 | } 46 | 47 | a small { 48 | font-size:11px; 49 | color:#777; 50 | margin-top:-0.3em; 51 | display:block; 52 | } 53 | 54 | a:hover small { 55 | color:#777; 56 | } 57 | 58 | .wrapper { 59 | width:1160px; 60 | margin:0 auto; 61 | } 62 | 63 | blockquote { 64 | border-left:1px solid #e5e5e5; 65 | margin:0; 66 | padding:0 0 0 20px; 67 | font-style:italic; 68 | } 69 | 70 | code, pre { 71 | font-family:Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal, Consolas, Liberation Mono, DejaVu Sans Mono, Courier New, monospace; 72 | color:#333; 73 | } 74 | 75 | pre { 76 | padding:8px 15px; 77 | background: #f8f8f8; 78 | border-radius:5px; 79 | border:1px solid #e5e5e5; 80 | overflow-x: auto; 81 | } 82 | 83 | table { 84 | width:100%; 85 | border-collapse:collapse; 86 | } 87 | 88 | th, td { 89 | text-align:left; 90 | padding:5px 10px; 91 | border-bottom:1px solid #e5e5e5; 92 | } 93 | 94 | dt { 95 | color:#444; 96 | font-weight:700; 97 | } 98 | 99 | th { 100 | color:#444; 101 | } 102 | 103 | img { 104 | max-width:100%; 105 | } 106 | 107 | kbd { 108 | background-color: #fafbfc; 109 | border: 1px solid #c6cbd1; 110 | border-bottom-color: #959da5; 111 | border-radius: 3px; 112 | box-shadow: inset 0 -1px 0 #959da5; 113 | color: #444d56; 114 | display: inline-block; 115 | font-size: 11px; 116 | line-height: 10px; 117 | padding: 3px 5px; 118 | vertical-align: middle; 119 | } 120 | 121 | header { 122 | width:300px; 123 | float:left; 124 | position:fixed; 125 | overflow-y: scroll; 126 | top: 20px; 127 | bottom: 0; 128 | -webkit-font-smoothing:subpixel-antialiased; 129 | } 130 | 131 | ul.downloads { 132 | list-style:none; 133 | height:40px; 134 | padding:0; 135 | background: #f4f4f4; 136 | border-radius:5px; 137 | border:1px solid #e0e0e0; 138 | width:270px; 139 | } 140 | 141 | .downloads li { 142 | width:89px; 143 | float:left; 144 | border-right:1px solid #e0e0e0; 145 | height:40px; 146 | } 147 | 148 | .downloads li:first-child a { 149 | border-radius:5px 0 0 5px; 150 | } 151 | 152 | .downloads li:last-child a { 153 | border-radius:0 5px 5px 0; 154 | } 155 | 156 | .downloads a { 157 | line-height:1; 158 | font-size:11px; 159 | color:#676767; 160 | display:block; 161 | text-align:center; 162 | padding-top:6px; 163 | height:34px; 164 | } 165 | 166 | .downloads a:hover, .downloads a:focus { 167 | color:#675C5C; 168 | font-weight:bold; 169 | } 170 | 171 | .downloads ul a:active { 172 | background-color:#f0f0f0; 173 | } 174 | 175 | strong { 176 | color:#222; 177 | font-weight:700; 178 | } 179 | 180 | .downloads li + li + li { 181 | border-right:none; 182 | width:89px; 183 | } 184 | 185 | .downloads a strong { 186 | font-size:14px; 187 | display:block; 188 | color:#222; 189 | } 190 | 191 | section { 192 | width:800px; 193 | float:right; 194 | padding-bottom:50px; 195 | } 196 | 197 | small { 198 | font-size:11px; 199 | } 200 | 201 | hr { 202 | border:0; 203 | background:#e5e5e5; 204 | height:1px; 205 | margin:0 0 20px; 206 | } 207 | 208 | footer { 209 | width:300px; 210 | float:left; 211 | position:fixed; 212 | overflow-y: scroll; 213 | bottom: 0; 214 | -webkit-font-smoothing:subpixel-antialiased; 215 | } 216 | 217 | @media print, screen and (max-width: 960px) { 218 | 219 | div.wrapper { 220 | width:auto; 221 | margin:0; 222 | } 223 | 224 | header, section, footer { 225 | float:none; 226 | position:static; 227 | width:auto; 228 | } 229 | 230 | header { 231 | padding-right:320px; 232 | } 233 | 234 | section { 235 | border:1px solid #e5e5e5; 236 | border-width:1px 0; 237 | padding:20px 0; 238 | margin:0 0 20px; 239 | } 240 | 241 | header a small { 242 | display:inline; 243 | } 244 | 245 | header ul { 246 | position:absolute; 247 | right:50px; 248 | top:52px; 249 | } 250 | } 251 | 252 | @media print, screen and (max-width: 720px) { 253 | body { 254 | word-wrap:break-word; 255 | } 256 | 257 | header { 258 | padding:0; 259 | } 260 | 261 | header ul, header p.view { 262 | position:static; 263 | } 264 | 265 | pre, code { 266 | word-wrap:normal; 267 | } 268 | } 269 | 270 | @media print, screen and (max-width: 480px) { 271 | body { 272 | padding:15px; 273 | } 274 | 275 | .downloads { 276 | width:99%; 277 | } 278 | 279 | .downloads li, .downloads li + li + li { 280 | width:33%; 281 | } 282 | } 283 | 284 | @media print { 285 | body { 286 | padding:0.4in; 287 | font-size:12pt; 288 | color:#444; 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /_sass/minimal.scss: -------------------------------------------------------------------------------- 1 | // Placeholder file. If your site uses 2 | // @import "{{ site.theme }}"; 3 | // Then using this theme with jekyll-remote-theme will work fine. 4 | @import "jekyll-theme-minimal"; 5 | -------------------------------------------------------------------------------- /_sass/rouge-github.scss: -------------------------------------------------------------------------------- 1 | .highlight table td { padding: 5px; } 2 | .highlight table pre { margin: 0; } 3 | .highlight .cm { 4 | #color: #999988; 5 | color: #737362; 6 | font-style: italic; 7 | } 8 | .highlight .cp { 9 | #color: #999999; 10 | color: #727272; 11 | font-weight: bold; 12 | } 13 | .highlight .c1 { 14 | #color: #999988; 15 | color: #737362; 16 | font-style: italic; 17 | } 18 | .highlight .cs { 19 | color: #999999; 20 | font-weight: bold; 21 | font-style: italic; 22 | } 23 | .highlight .c, .highlight .cd { 24 | #color: #999988; 25 | color: #737362; 26 | font-style: italic; 27 | } 28 | .highlight .err { 29 | color: #a61717; 30 | background-color: #e3d2d2; 31 | } 32 | .highlight .gd { 33 | color: #000000; 34 | background-color: #ffdddd; 35 | } 36 | .highlight .ge { 37 | color: #000000; 38 | font-style: italic; 39 | } 40 | .highlight .gr { 41 | color: #aa0000; 42 | } 43 | .highlight .gh { 44 | color: #999999; 45 | } 46 | .highlight .gi { 47 | color: #000000; 48 | background-color: #ddffdd; 49 | } 50 | .highlight .go { 51 | color: #888888; 52 | } 53 | .highlight .gp { 54 | color: #555555; 55 | } 56 | .highlight .gs { 57 | font-weight: bold; 58 | } 59 | .highlight .gu { 60 | color: #aaaaaa; 61 | } 62 | .highlight .gt { 63 | color: #aa0000; 64 | } 65 | .highlight .kc { 66 | color: #000000; 67 | font-weight: bold; 68 | } 69 | .highlight .kd { 70 | color: #000000; 71 | font-weight: bold; 72 | } 73 | .highlight .kn { 74 | color: #000000; 75 | font-weight: bold; 76 | } 77 | .highlight .kp { 78 | color: #000000; 79 | font-weight: bold; 80 | } 81 | .highlight .kr { 82 | color: #000000; 83 | font-weight: bold; 84 | } 85 | .highlight .kt { 86 | color: #445588; 87 | font-weight: bold; 88 | } 89 | .highlight .k, .highlight .kv { 90 | color: #000000; 91 | font-weight: bold; 92 | } 93 | .highlight .mf { 94 | #color: #009999; 95 | color: #007f7f; 96 | } 97 | .highlight .mh { 98 | color: #009999; 99 | } 100 | .highlight .il { 101 | color: #009999; 102 | } 103 | .highlight .mi { 104 | #color: #009999; 105 | color:007f7f; 106 | } 107 | .highlight .mo { 108 | color: #009999; 109 | } 110 | .highlight .m, .highlight .mb, .highlight .mx { 111 | #color: #009999; 112 | color: #007f7f; 113 | } 114 | .highlight .sb { 115 | color: #d14; 116 | } 117 | .highlight .sc { 118 | color: #d14; 119 | } 120 | .highlight .sd { 121 | color: #d14; 122 | } 123 | .highlight .s2 { 124 | color: #d14; 125 | } 126 | .highlight .se { 127 | color: #d14; 128 | } 129 | .highlight .sh { 130 | color: #d14; 131 | } 132 | .highlight .si { 133 | color: #d14; 134 | } 135 | .highlight .sx { 136 | color: #d14; 137 | } 138 | .highlight .sr { 139 | color: #009926; 140 | } 141 | .highlight .s1 { 142 | color: #d14; 143 | } 144 | .highlight .ss { 145 | color: #990073; 146 | } 147 | .highlight .s { 148 | color: #d14; 149 | } 150 | .highlight .na { 151 | color: #008080; 152 | } 153 | .highlight .bp { 154 | #color: #999999; 155 | color: #727272; 156 | } 157 | .highlight .nb { 158 | # color: #0086B3; 159 | color: #007ba5; 160 | } 161 | .highlight .nc { 162 | color: #445588; 163 | font-weight: bold; 164 | } 165 | .highlight .no { 166 | color: #008080; 167 | } 168 | .highlight .nd { 169 | color: #3c5d5d; 170 | font-weight: bold; 171 | } 172 | .highlight .ni { 173 | color: #800080; 174 | } 175 | .highlight .ne { 176 | color: #990000; 177 | font-weight: bold; 178 | } 179 | .highlight .nf { 180 | color: #990000; 181 | font-weight: bold; 182 | } 183 | .highlight .nl { 184 | color: #990000; 185 | font-weight: bold; 186 | } 187 | .highlight .nn { 188 | color: #555555; 189 | } 190 | .highlight .nt { 191 | color: #000080; 192 | } 193 | .highlight .vc { 194 | color: #008080; 195 | } 196 | .highlight .vg { 197 | color: #008080; 198 | } 199 | .highlight .vi { 200 | color: #008080; 201 | } 202 | .highlight .nv { 203 | color: #008080; 204 | } 205 | .highlight .ow { 206 | color: #000000; 207 | font-weight: bold; 208 | } 209 | .highlight .o { 210 | color: #000000; 211 | font-weight: bold; 212 | } 213 | .highlight .w { 214 | color: #bbbbbb; 215 | } 216 | .highlight { 217 | background-color: #f8f8f8; 218 | } 219 | -------------------------------------------------------------------------------- /assets/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | image/svg+xml -------------------------------------------------------------------------------- /assets/stat_bear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-using-bash/b818e852ced6e0c5b620abef4352c56103c0a859/assets/stat_bear.png -------------------------------------------------------------------------------- /assets/styles.css: -------------------------------------------------------------------------------- 1 | .cell-output { 2 | background-color: #F0F0F0; 3 | border-radius: 4px; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /cpds.csv: -------------------------------------------------------------------------------- 1 | "year","country","vturn","outlays","realgdpgr","unemp" 2 | 1960,"Australia",95.5,NA,NA,1.42 3 | 1961,"Australia",95.3,NA,-0.07,2.79 4 | 1962,"Australia",95.3,23.17,5.71,2.63 5 | 1963,"Australia",95.7,23.01,6.1,2.12 6 | 1964,"Australia",95.7,22.88,6.28,1.15 7 | 1965,"Australia",95.7,24.9,4.97,1.15 8 | 1966,"Australia",95.1,26.06,2.9,1.6 9 | 1967,"Australia",95.1,26.35,7.25,1.88 10 | 1968,"Australia",95.1,26.52,5.3,1.82 11 | 1969,"Australia",95,25.05,6.29,1.82 12 | 1970,"Australia",95,25.23,6.96,1.65 13 | 1971,"Australia",95,25.55,3.85,1.91 14 | 1972,"Australia",95.4,27.34,2.32,2.61 15 | 1973,"Australia",95.4,26.03,4.39,2.31 16 | 1974,"Australia",95.4,28.99,1.58,2.67 17 | 1975,"Australia",95.4,31.64,2.35,4.9 18 | 1976,"Australia",95.4,33.81,3.92,4.77 19 | 1977,"Australia",95,34.86,1.45,5.63 20 | 1978,"Australia",95,34.59,2.03,6.43 21 | 1979,"Australia",95,32.97,4.65,6.26 22 | 1980,"Australia",94.4,32.94,2.84,6.11 23 | 1981,"Australia",94.4,33.11,4.07,5.78 24 | 1982,"Australia",94.4,35.79,-0.39,7.16 25 | 1983,"Australia",94.6,37.31,-0.17,9.96 26 | 1984,"Australia",94.2,38.81,6.55,8.99 27 | 1985,"Australia",94.2,39.72,5.22,8.26 28 | 1986,"Australia",94.2,39.43,2.24,8.08 29 | 1987,"Australia",93.8,37.22,5.17,8.11 30 | 1988,"Australia",93.8,34.07,4.42,7.23 31 | 1989,"Australia",93.8,32.56,4.26,6.17 32 | 1990,"Australia",95.3,33.38,1.52,6.93 33 | 1991,"Australia",95.3,35.89,-1.18,9.59 34 | 1992,"Australia",95.3,37.01,2.96,10.8 35 | 1993,"Australia",95.8,36.3,4.08,10.9 36 | 1994,"Australia",95.8,36.15,4.76,9.75 37 | 1995,"Australia",95.8,35.83,3.58,8.49 38 | 1996,"Australia",95.8,35.17,3.9,8.55 39 | 1997,"Australia",95.8,34.37,3.9,8.45 40 | 1998,"Australia",95,33.73,5.19,7.72 41 | 1999,"Australia",95,33.53,4.07,6.93 42 | 2000,"Australia",95,33.94,3.14,6.28 43 | 2001,"Australia",94.9,34.47,2.76,6.75 44 | 2002,"Australia",94.9,33.83,3.78,6.36 45 | 2003,"Australia",94.9,33.31,3.35,5.94 46 | 2004,"Australia",94.3,33.77,3.76,5.4 47 | 2005,"Australia",94.3,33.29,3.28,5.04 48 | 2006,"Australia",94.3,32.98,2.6,4.79 49 | 2007,"Australia",94.8,32.96,4.89,4.38 50 | 2008,"Australia",94.8,33.9,2.28,4.25 51 | 2009,"Australia",94.8,36.58,1.45,5.59 52 | 2010,"Australia",93.2,36.26,2.43,5.23 53 | 1960,"Austria",94.2,36.29,NA,2.41 54 | 1961,"Austria",94.2,35.71,5.55,1.86 55 | 1962,"Austria",93.8,37.56,2.62,1.9 56 | 1963,"Austria",93.8,38.64,4.15,2.09 57 | 1964,"Austria",93.8,38.67,6.18,1.94 58 | 1965,"Austria",93.8,38.35,3.01,1.92 59 | 1966,"Austria",93.8,38.75,5.14,1.75 60 | 1967,"Austria",93.8,40.73,2.84,1.85 61 | 1968,"Austria",93.8,40.89,4.11,1.57 62 | 1969,"Austria",93.8,40.69,5.46,2.04 63 | 1970,"Austria",91.8,39.54,6.43,1.39 64 | 1971,"Austria",92.4,40.03,5.11,1.26 65 | 1972,"Austria",92.4,40.07,6.21,1.16 66 | 1973,"Austria",92.4,41.5,4.89,1.08 67 | 1974,"Austria",92.4,42.03,3.94,1.34 68 | 1975,"Austria",92.9,46.09,-0.36,1.77 69 | 1976,"Austria",92.9,46.94,4.58,1.8 70 | 1977,"Austria",92.9,46.57,4.68,1.61 71 | 1978,"Austria",92.9,49.66,-0.36,2.08 72 | 1979,"Austria",92.2,48.98,5.45,2.09 73 | 1980,"Austria",92.2,49.24,2.31,1.85 74 | 1981,"Austria",92.2,50.74,-0.1,2.52 75 | 1982,"Austria",92.2,51.35,1.91,3.51 76 | 1983,"Austria",92.6,51.76,2.8,4.1 77 | 1984,"Austria",92.6,51.87,0.33,3.81 78 | 1985,"Austria",92.6,52.88,2.24,3.61 79 | 1986,"Austria",90.5,53.76,2.34,3.13 80 | 1987,"Austria",90.5,53.98,1.68,3.79 81 | 1988,"Austria",90.5,53.06,3.17,3.55 82 | 1989,"Austria",90.5,51.51,3.84,3.13 83 | 1990,"Austria",83.7,51.48,3.96,3.23 84 | 1991,"Austria",83.7,52.57,3.11,3.47 85 | 1992,"Austria",83.7,53.41,1.57,3.62 86 | 1993,"Austria",83.7,56.28,0.12,4.26 87 | 1994,"Austria",81.9,56.1,1.7,3.59 88 | 1995,"Austria",86,56.26,2.57,3.72 89 | 1996,"Austria",86,56.11,2.33,4.17 90 | 1997,"Austria",86,53.32,2.51,4.29 91 | 1998,"Austria",86,53.58,3.79,4.28 92 | 1999,"Austria",80.4,53.37,3.43,3.79 93 | 2000,"Austria",80.4,51.78,3.79,3.58 94 | 2001,"Austria",80.4,51.17,1,3.66 95 | 2002,"Austria",84.3,50.71,1.28,4.03 96 | 2003,"Austria",84.3,51.33,0.83,4.3 97 | 2004,"Austria",84.3,53.94,2.29,4.97 98 | 2005,"Austria",84.3,50.02,2.73,5.17 99 | 2006,"Austria",78.5,49.17,3.66,4.75 100 | 2007,"Austria",78.5,48.68,3.67,4.42 101 | 2008,"Austria",78.8,49.6,1.06,3.83 102 | 2009,"Austria",78.8,52.98,-3.55,4.79 103 | 2010,"Austria",78.8,52.58,2.47,4.4 104 | 1960,"Belgium",93.6,NA,NA,3.28 105 | 1961,"Belgium",92.3,NA,4.97,2.49 106 | 1962,"Belgium",92.3,NA,5.18,2.08 107 | 1963,"Belgium",92.3,NA,4.4,1.71 108 | 1964,"Belgium",92.3,NA,6.95,1.5 109 | 1965,"Belgium",91.6,NA,3.59,1.71 110 | 1966,"Belgium",91.6,NA,3.11,1.81 111 | 1967,"Belgium",91.6,NA,3.87,2.48 112 | 1968,"Belgium",90,NA,4.17,2.95 113 | 1969,"Belgium",90,NA,6.62,2.33 114 | 1970,"Belgium",90,42.66,6.19,1.93 115 | 1971,"Belgium",91.5,43.87,3.75,1.87 116 | 1972,"Belgium",91.5,45.03,5.26,2.37 117 | 1973,"Belgium",91.5,44.98,6.12,2.45 118 | 1974,"Belgium",90.3,44.52,4.2,2.54 119 | 1975,"Belgium",90.3,50.19,-1.33,4.56 120 | 1976,"Belgium",90.3,50.42,5.65,6.02 121 | 1977,"Belgium",95.1,52.17,0.63,6.83 122 | 1978,"Belgium",94.8,53.67,2.84,7.4 123 | 1979,"Belgium",94.8,55.88,2.34,7.67 124 | 1980,"Belgium",94.8,55.91,4.48,8.09 125 | 1981,"Belgium",94.6,62.23,-0.28,10.4 126 | 1982,"Belgium",94.6,59.95,0.59,12.17 127 | 1983,"Belgium",94.6,62.32,0.31,13.47 128 | 1984,"Belgium",94.6,58.42,2.47,13.51 129 | 1985,"Belgium",93.6,58.34,1.65,12.58 130 | 1986,"Belgium",93.6,57.55,1.82,11.89 131 | 1987,"Belgium",93.4,55.73,2.31,11.58 132 | 1988,"Belgium",93.4,53.82,4.72,10.54 133 | 1989,"Belgium",93.4,52.28,3.47,9.47 134 | 1990,"Belgium",93.4,52.27,3.14,8.92 135 | 1991,"Belgium",92.7,53.48,1.83,9.47 136 | 1992,"Belgium",92.7,53.76,1.53,10.48 137 | 1993,"Belgium",92.7,54.86,-0.96,12.15 138 | 1994,"Belgium",92.7,52.55,3.23,13.06 139 | 1995,"Belgium",91.1,52.07,2.38,13 140 | 1996,"Belgium",91.1,52.48,1.23,12.72 141 | 1997,"Belgium",91.1,51.15,3.85,12.56 142 | 1998,"Belgium",91.1,50.36,1.94,11.71 143 | 1999,"Belgium",90.6,50.14,3.51,8.56 144 | 2000,"Belgium",90.6,49.1,3.78,7.01 145 | 2001,"Belgium",90.6,49.11,0.71,6.61 146 | 2002,"Belgium",90.6,49.79,1.39,7.54 147 | 2003,"Belgium",91.6,51.05,0.79,8.21 148 | 2004,"Belgium",91.6,49.21,3.2,8.41 149 | 2005,"Belgium",91.6,51.86,1.88,8.44 150 | 2006,"Belgium",91.6,48.46,2.72,8.25 151 | 2007,"Belgium",91.1,48.26,2.84,7.46 152 | 2008,"Belgium",91.1,49.84,0.85,6.98 153 | 2009,"Belgium",91.1,53.72,-2.66,7.91 154 | 2010,"Belgium",89.2,52.78,2.22,8.29 155 | 1960,"Canada",80.6,NA,NA,6.96 156 | 1961,"Canada",80.6,NA,3.06,7.15 157 | 1962,"Canada",80.1,NA,6.99,5.9 158 | 1963,"Canada",80.3,NA,5.31,5.54 159 | 1964,"Canada",80.3,NA,6.47,4.67 160 | 1965,"Canada",75.9,NA,6.37,3.92 161 | 1966,"Canada",75.9,NA,6.65,3.35 162 | 1967,"Canada",75.9,NA,2.92,3.82 163 | 1968,"Canada",75.7,NA,4.88,4.5 164 | 1969,"Canada",75.7,NA,5.03,4.42 165 | 1970,"Canada",75.7,35.92,3.03,5.67 166 | 1971,"Canada",75.7,37.17,4.12,6.19 167 | 1972,"Canada",77.2,37.45,5.45,6.22 168 | 1973,"Canada",77.2,36.09,6.96,5.55 169 | 1974,"Canada",71,37.44,3.69,5.33 170 | 1975,"Canada",71,40.89,1.82,6.92 171 | 1976,"Canada",71,40.12,5.2,7.09 172 | 1977,"Canada",71,41.15,3.46,8.05 173 | 1978,"Canada",71,41.54,3.95,8.38 174 | 1979,"Canada",75.7,39.95,3.8,7.53 175 | 1980,"Canada",69.3,41.48,2.16,7.54 176 | 1981,"Canada",69.3,42.39,3.5,7.61 177 | 1982,"Canada",69.3,47.18,-2.86,11.04 178 | 1983,"Canada",69.3,47.81,2.72,12.02 179 | 1984,"Canada",75.7,47.51,5.81,11.34 180 | 1985,"Canada",75.7,48.13,4.78,10.64 181 | 1986,"Canada",75.7,47.5,2.42,9.69 182 | 1987,"Canada",75.7,46.01,4.25,8.82 183 | 1988,"Canada",75.5,45.34,4.97,7.76 184 | 1989,"Canada",75.5,45.77,2.62,7.55 185 | 1990,"Canada",75.5,48.74,0.19,8.13 186 | 1991,"Canada",75.5,52.14,-2.09,10.32 187 | 1992,"Canada",75.5,53.24,0.88,11.2 188 | 1993,"Canada",69.6,52.21,2.34,11.38 189 | 1994,"Canada",69.6,49.79,4.8,10.4 190 | 1995,"Canada",69.6,48.45,2.81,9.49 191 | 1996,"Canada",69.6,46.73,1.62,9.62 192 | 1997,"Canada",67,44.25,4.23,9.1 193 | 1998,"Canada",67,44.78,4.1,8.28 194 | 1999,"Canada",67,42.98,5.53,7.58 195 | 2000,"Canada",60.5,41.09,5.23,6.83 196 | 2001,"Canada",60.5,41.97,1.78,7.23 197 | 2002,"Canada",60.5,41.23,2.92,7.67 198 | 2003,"Canada",60.5,41.18,1.88,7.58 199 | 2004,"Canada",60.9,39.86,3.12,7.18 200 | 2005,"Canada",60.9,39.3,3.02,6.76 201 | 2006,"Canada",64.7,39.45,2.82,6.32 202 | 2007,"Canada",64.7,39.35,2.2,6.03 203 | 2008,"Canada",58.8,40.03,0.69,6.13 204 | 2009,"Canada",58.8,44.37,-2.77,8.27 205 | 2010,"Canada",58.8,44.08,3.21,8.01 206 | 1960,"Denmark",85.8,NA,NA,1.96 207 | 1961,"Denmark",85.8,NA,5.6,1.93 208 | 1962,"Denmark",85.8,NA,5.55,1.85 209 | 1963,"Denmark",85.8,NA,-1.12,2.06 210 | 1964,"Denmark",85.5,NA,11.04,1.47 211 | 1965,"Denmark",85.5,NA,4.47,1.18 212 | 1966,"Denmark",88.6,NA,7.54,1.38 213 | 1967,"Denmark",88.6,NA,5.64,1.22 214 | 1968,"Denmark",89.3,NA,5.67,1.22 215 | 1969,"Denmark",89.3,NA,6.48,1.13 216 | 1970,"Denmark",89.3,NA,1.5,0.73 217 | 1971,"Denmark",87.2,42.74,3,1.14 218 | 1972,"Denmark",87.2,42.12,4.17,0.97 219 | 1973,"Denmark",88.7,40.17,3.76,0.87 220 | 1974,"Denmark",88.7,44.89,-0.82,3.6 221 | 1975,"Denmark",88.2,46.49,-1.22,4.93 222 | 1976,"Denmark",88.2,46.49,6.09,6.41 223 | 1977,"Denmark",88,46.86,1.98,7.42 224 | 1978,"Denmark",88,47.83,2.27,8.38 225 | 1979,"Denmark",85.6,49.93,3.95,6.05 226 | 1980,"Denmark",85.6,53.42,-0.49,6.93 227 | 1981,"Denmark",83.2,57.81,-0.89,10.43 228 | 1982,"Denmark",83.2,59.61,3.71,11.09 229 | 1983,"Denmark",83.2,59.21,2.65,11.55 230 | 1984,"Denmark",88.4,56.13,4.17,8.59 231 | 1985,"Denmark",88.4,55.13,4.02,7.35 232 | 1986,"Denmark",88.4,51.09,4.95,5.53 233 | 1987,"Denmark",86.7,52.51,0.29,5.47 234 | 1988,"Denmark",85.7,55.13,-0.14,6.54 235 | 1989,"Denmark",85.7,55.48,0.57,8.23 236 | 1990,"Denmark",81.4,55.41,1.61,8.41 237 | 1991,"Denmark",81.4,56.07,1.3,9.21 238 | 1992,"Denmark",81.4,57.12,1.98,9.1 239 | 1993,"Denmark",81.4,60.21,-0.09,10.81 240 | 1994,"Denmark",84.3,60.19,5.53,8.13 241 | 1995,"Denmark",84.3,59.28,3.07,7.13 242 | 1996,"Denmark",84.3,58.91,2.83,6.99 243 | 1997,"Denmark",84.3,56.68,3.2,6.16 244 | 1998,"Denmark",86,56.33,2.16,5.51 245 | 1999,"Denmark",86,55.5,2.56,5.58 246 | 2000,"Denmark",86,53.67,3.53,4.64 247 | 2001,"Denmark",87.1,54.19,0.7,4.83 248 | 2002,"Denmark",87.1,54.58,0.47,4.75 249 | 2003,"Denmark",87.1,55.07,0.38,5.6 250 | 2004,"Denmark",87.1,54.55,2.3,5.72 251 | 2005,"Denmark",84.5,52.79,2.45,5.02 252 | 2006,"Denmark",84.5,51.59,3.39,4.1 253 | 2007,"Denmark",86.6,50.81,1.58,4.01 254 | 2008,"Denmark",86.6,51.52,-0.78,3.38 255 | 2009,"Denmark",86.6,57.96,-5.83,6.11 256 | 2010,"Denmark",86.6,57.82,1.3,7.58 257 | 1960,"Finland",75,26.41,NA,1.46 258 | 1961,"Finland",75,25.57,7.61,1.22 259 | 1962,"Finland",85.1,27.58,2.98,1.3 260 | 1963,"Finland",85.1,28.9,3.28,1.49 261 | 1964,"Finland",85.1,30.38,5.24,1.52 262 | 1965,"Finland",85.1,30.84,5.3,1.38 263 | 1966,"Finland",84.9,32.3,2.37,1.51 264 | 1967,"Finland",84.9,33.37,2.17,2.91 265 | 1968,"Finland",84.9,33.34,2.3,3.96 266 | 1969,"Finland",84.9,31.92,9.59,2.84 267 | 1970,"Finland",82.2,31.02,7.47,1.9 268 | 1971,"Finland",82.2,32.65,2.06,2.27 269 | 1972,"Finland",81.4,33.09,7.6,2.54 270 | 1973,"Finland",81.4,32.05,6.6,2.31 271 | 1974,"Finland",81.4,32.3,3.07,1.73 272 | 1975,"Finland",73.8,38.68,1.07,2.25 273 | 1976,"Finland",73.8,40.09,0.17,3.9 274 | 1977,"Finland",73.8,41.69,0.6,5.93 275 | 1978,"Finland",73.8,41.35,2.5,7.28 276 | 1979,"Finland",75.3,40.45,6.72,5.99 277 | 1980,"Finland",75.3,40.35,5.09,4.69 278 | 1981,"Finland",75.3,41.38,1.27,4.91 279 | 1982,"Finland",75.3,43.07,3.1,5.4 280 | 1983,"Finland",75.7,44.7,3.07,5.48 281 | 1984,"Finland",75.7,44.75,2.99,5.24 282 | 1985,"Finland",75.7,46.7,3.23,5.05 283 | 1986,"Finland",75.7,47.36,2.75,5.39 284 | 1987,"Finland",72.1,47.84,3.62,5.11 285 | 1988,"Finland",72.1,46.38,5.15,4.57 286 | 1989,"Finland",72.1,44.5,5.42,3.11 287 | 1990,"Finland",72.1,48.25,0.14,3.19 288 | 1991,"Finland",72.1,57.19,-6,6.67 289 | 1992,"Finland",72.1,62.48,-3.48,11.73 290 | 1993,"Finland",72.1,64.89,-0.81,16.42 291 | 1994,"Finland",72.1,63.63,3.65,16.63 292 | 1995,"Finland",71.7,61.56,3.96,15.45 293 | 1996,"Finland",71.7,60.2,3.57,14.63 294 | 1997,"Finland",71.7,56.68,6.21,12.68 295 | 1998,"Finland",71.7,53.04,5.03,11.4 296 | 1999,"Finland",68.3,51.82,3.91,10.24 297 | 2000,"Finland",68.3,48.45,5.32,9.81 298 | 2001,"Finland",68.3,48.03,2.28,9.14 299 | 2002,"Finland",68.3,49.07,1.83,9.12 300 | 2003,"Finland",69.7,50.36,2.01,9.06 301 | 2004,"Finland",69.7,50.27,4.13,8.85 302 | 2005,"Finland",69.7,50.42,2.92,8.42 303 | 2006,"Finland",69.7,49.27,4.41,7.73 304 | 2007,"Finland",65,47.47,5.34,6.86 305 | 2008,"Finland",65,49.35,0.29,6.38 306 | 2009,"Finland",65,56.14,-8.35,8.28 307 | 2010,"Finland",65,55.59,3.73,8.42 308 | 1960,"France",77.2,NA,NA,1.29 309 | 1961,"France",77.2,NA,4.95,1.13 310 | 1962,"France",68.7,NA,6.72,1.28 311 | 1963,"France",68.7,61.56,6.28,1.41 312 | 1964,"France",68.7,56.59,6.35,1.13 313 | 1965,"France",68.7,52.91,4.81,1.4 314 | 1966,"France",68.7,52.22,5.28,1.44 315 | 1967,"France",81.1,50.79,4.91,1.91 316 | 1968,"France",80,48.34,4.41,2.41 317 | 1969,"France",80,43.29,7.15,2.08 318 | 1970,"France",80,39.23,6.15,2.23 319 | 1971,"France",80,38.83,5.31,2.44 320 | 1972,"France",80,39.05,4.64,2.54 321 | 1973,"France",81.3,39.01,6.56,2.43 322 | 1974,"France",81.3,39.64,4.7,2.56 323 | 1975,"France",81.3,43.01,-1.14,3.7 324 | 1976,"France",81.3,43.36,4.34,4.11 325 | 1977,"France",81.3,43.49,3.62,4.61 326 | 1978,"France",83.2,44.72,3.91,4.79 327 | 1979,"France",83.2,44.92,3.41,5.41 328 | 1980,"France",83.2,46,1.69,5.79 329 | 1981,"France",70.9,48.56,1.02,6.81 330 | 1982,"France",70.9,49.91,2.39,7.39 331 | 1983,"France",70.9,50.28,1.23,7.69 332 | 1984,"France",70.9,51.21,1.6,8.98 333 | 1985,"France",70.9,51.83,1.69,9.54 334 | 1986,"France",78.5,51.28,2.16,9.58 335 | 1987,"France",78.5,50.7,2.39,9.7 336 | 1988,"France",66.2,50.12,4.52,9.32 337 | 1989,"France",66.2,48.9,4.39,8.65 338 | 1990,"France",66.2,49.57,2.58,8 339 | 1991,"France",66.2,50.64,1.09,8.15 340 | 1992,"France",66.2,52.03,1.32,9.06 341 | 1993,"France",69.3,55.09,-0.66,10.14 342 | 1994,"France",69.3,54.11,2.21,10.71 343 | 1995,"France",69.3,54.37,2.17,10.12 344 | 1996,"France",69.3,54.49,1.04,10.67 345 | 1997,"France",68,54.19,2.17,10.73 346 | 1998,"France",68,52.75,3.41,10.22 347 | 1999,"France",68,52.65,3.18,9.81 348 | 2000,"France",68,51.64,3.87,8.37 349 | 2001,"France",68,51.63,1.79,7.56 350 | 2002,"France",64.4,52.84,0.94,7.71 351 | 2003,"France",64.4,53.37,0.89,8.33 352 | 2004,"France",64.4,53.34,2.35,8.71 353 | 2005,"France",64.4,53.63,1.87,8.73 354 | 2006,"France",64.4,52.93,2.66,8.66 355 | 2007,"France",60.4,52.6,2.23,7.87 356 | 2008,"France",60.4,53.33,-0.2,7.32 357 | 2009,"France",60.4,56.85,-2.97,9.09 358 | 2010,"France",60.4,56.81,1.59,9.32 359 | 1960,"Germany",87.8,32.71,NA,1.03 360 | 1961,"Germany",87.7,34.06,4.72,0.69 361 | 1962,"Germany",87.7,35.81,4.71,0.59 362 | 1963,"Germany",87.7,36.59,2.93,0.7 363 | 1964,"Germany",87.7,36.38,6.42,0.64 364 | 1965,"Germany",86.8,37.1,5.26,0.55 365 | 1966,"Germany",86.8,37.14,2.89,0.61 366 | 1967,"Germany",86.8,39,-0.25,1.77 367 | 1968,"Germany",86.8,39.26,5.54,1.25 368 | 1969,"Germany",86.7,38.66,7.46,0.69 369 | 1970,"Germany",86.7,38.43,5.04,0.57 370 | 1971,"Germany",86.7,39.91,3.01,0.7 371 | 1972,"Germany",91.1,41.06,4.27,0.93 372 | 1973,"Germany",91.1,41.57,4.97,1.01 373 | 1974,"Germany",91.1,44.7,1.01,2.16 374 | 1975,"Germany",91.1,48.7,-0.89,4.03 375 | 1976,"Germany",90.7,48.4,4.45,4 376 | 1977,"Germany",90.7,47.99,3.5,3.89 377 | 1978,"Germany",90.7,46.99,3.11,3.72 378 | 1979,"Germany",90.7,46.45,4.29,3.24 379 | 1980,"Germany",88.6,46.89,1.3,3.24 380 | 1981,"Germany",88.6,47.46,0.65,4.58 381 | 1982,"Germany",88.6,47.51,-0.51,6.54 382 | 1983,"Germany",88.4,46.58,1.47,8.05 383 | 1984,"Germany",88.4,45.82,2.91,7.21 384 | 1985,"Germany",88.4,45.08,2.6,7.3 385 | 1986,"Germany",88.4,44.4,2.27,6.57 386 | 1987,"Germany",84.3,45,1.28,6.31 387 | 1988,"Germany",84.3,44.65,3.44,6.29 388 | 1989,"Germany",84.3,43.11,4.05,5.62 389 | 1990,"Germany",77.8,43.55,5.47,4.78 390 | 1991,"Germany",77.8,46.1,5.2,5.64 391 | 1992,"Germany",77.8,47.19,1.5,6.7 392 | 1993,"Germany",77.8,48.2,-1.01,7.96 393 | 1994,"Germany",79,48.05,2.53,8.49 394 | 1995,"Germany",79,54.84,1.77,8.21 395 | 1996,"Germany",79,49.02,0.83,8.95 396 | 1997,"Germany",79,48.17,1.78,9.91 397 | 1998,"Germany",82.2,48.04,1.65,9.29 398 | 1999,"Germany",82.2,48.32,1.75,8.46 399 | 2000,"Germany",82.2,45.09,3.3,7.8 400 | 2001,"Germany",82.2,47.54,1.64,7.88 401 | 2002,"Germany",79.1,47.87,0.03,8.62 402 | 2003,"Germany",79.1,48.39,-0.38,9.32 403 | 2004,"Germany",79.1,47.22,0.7,10.34 404 | 2005,"Germany",77.7,46.98,0.83,11.24 405 | 2006,"Germany",77.7,45.33,3.89,10.33 406 | 2007,"Germany",77.7,43.45,3.39,8.71 407 | 2008,"Germany",77.7,44.1,0.81,7.56 408 | 2009,"Germany",70.8,48.13,-5.08,7.78 409 | 2010,"Germany",70.8,47.97,3.56,7.1 410 | 1960,"Greece",75.5,23.05,NA,6.1 411 | 1961,"Greece",81.9,22.72,13.2,5.91 412 | 1962,"Greece",81.9,23.8,0.36,5.07 413 | 1963,"Greece",83,22.25,11.84,4.98 414 | 1964,"Greece",81.7,22.9,9.41,4.65 415 | 1965,"Greece",81.7,22.44,10.77,4.82 416 | 1966,"Greece",81.7,23.62,6.49,5.01 417 | 1967,"Greece",NA,25.2,5.67,5.4 418 | 1968,"Greece",NA,25.75,7.2,5.58 419 | 1969,"Greece",NA,24.85,11.56,5.25 420 | 1970,"Greece",NA,24.22,8.93,4.16 421 | 1971,"Greece",NA,24.32,7.84,3.14 422 | 1972,"Greece",NA,24.38,10.16,2.11 423 | 1973,"Greece",NA,23.12,8.09,1.97 424 | 1974,"Greece",79.5,26.76,-6.44,2.05 425 | 1975,"Greece",79.5,27.57,6.37,2.29 426 | 1976,"Greece",79.5,27.53,6.85,1.91 427 | 1977,"Greece",81.1,28.7,2.94,1.69 428 | 1978,"Greece",81.1,28.63,7.25,1.83 429 | 1979,"Greece",81.1,29.11,3.28,1.9 430 | 1980,"Greece",81.1,29.25,0.68,2.75 431 | 1981,"Greece",81.5,34.07,-1.55,4.05 432 | 1982,"Greece",81.5,35.28,-1.13,5.78 433 | 1983,"Greece",81.5,37.22,-1.08,7.86 434 | 1984,"Greece",81.5,39.16,2.01,8.14 435 | 1985,"Greece",83.8,41.1,2.51,7.81 436 | 1986,"Greece",83.8,40.41,0.52,7.38 437 | 1987,"Greece",83.8,40.36,-2.26,7.36 438 | 1988,"Greece",83.8,39.31,4.29,7.67 439 | 1989,"Greece",84.3,40.58,3.8,7.46 440 | 1990,"Greece",84.5,44.87,0,7.03 441 | 1991,"Greece",84.5,41.77,3.1,7.65 442 | 1992,"Greece",84.5,44.24,0.7,8.68 443 | 1993,"Greece",78.2,46.54,-1.6,9.66 444 | 1994,"Greece",78.2,44.72,2,9.61 445 | 1995,"Greece",78.2,46.17,2.1,9.99 446 | 1996,"Greece",78.7,44.48,2.36,10.33 447 | 1997,"Greece",78.7,45.28,3.64,10.24 448 | 1998,"Greece",78.7,44.73,3.36,10.84 449 | 1999,"Greece",78.7,44.8,3.42,11.85 450 | 2000,"Greece",78.3,47.12,4.48,11.25 451 | 2001,"Greece",78.3,45.71,4.2,10.44 452 | 2002,"Greece",78.3,45.5,3.44,9.93 453 | 2003,"Greece",78.3,45.15,5.94,9.34 454 | 2004,"Greece",89.1,45.94,4.37,10.22 455 | 2005,"Greece",89.1,44.6,2.28,9.63 456 | 2006,"Greece",89.1,45.19,5.54,8.75 457 | 2007,"Greece",86.5,47.59,3,8.09 458 | 2008,"Greece",86.5,50.65,-0.16,7.23 459 | 2009,"Greece",82.9,53.81,-3.25,8.9 460 | 2010,"Greece",82.9,50.2,-3.52,11.83 461 | 1960,"Iceland",90.4,NA,NA,NA 462 | 1961,"Iceland",90.4,NA,-0.08,1.44 463 | 1962,"Iceland",90.4,NA,8.31,1.42 464 | 1963,"Iceland",91.1,NA,10.28,1.39 465 | 1964,"Iceland",91.1,NA,9.92,0.08 466 | 1965,"Iceland",91.1,NA,7.29,0.19 467 | 1966,"Iceland",91.1,NA,8.74,0.19 468 | 1967,"Iceland",91.4,NA,-1.27,0.38 469 | 1968,"Iceland",91.4,NA,-5.47,1.31 470 | 1969,"Iceland",91.4,NA,2.37,2.45 471 | 1970,"Iceland",91.4,31.1,7.46,1.28 472 | 1971,"Iceland",90.4,33.78,13.06,0.65 473 | 1972,"Iceland",90.4,34.77,6.18,0.5 474 | 1973,"Iceland",90.4,34.63,6.81,0.4 475 | 1974,"Iceland",91.4,37.43,5.71,0.39 476 | 1975,"Iceland",91.4,37.53,0.65,0.48 477 | 1976,"Iceland",91.4,33.06,5.96,0.49 478 | 1977,"Iceland",91.4,32.64,8.82,0.29 479 | 1978,"Iceland",90.3,32.86,6.02,0.33 480 | 1979,"Iceland",89.3,33.43,4.86,0.37 481 | 1980,"Iceland",89.3,32.96,5.75,0.31 482 | 1981,"Iceland",89.3,34.36,4.27,0.36 483 | 1982,"Iceland",89.3,35.02,2.15,0.67 484 | 1983,"Iceland",88.6,36.55,-2.15,1.02 485 | 1984,"Iceland",88.6,33.18,4.13,1.25 486 | 1985,"Iceland",88.6,35.45,3.29,0.91 487 | 1986,"Iceland",88.6,37.8,6.27,0.66 488 | 1987,"Iceland",90.1,34.71,8.55,0.44 489 | 1988,"Iceland",90.1,39.35,-0.09,0.64 490 | 1989,"Iceland",90.1,40.79,0.26,1.66 491 | 1990,"Iceland",90.1,38.87,1.17,1.76 492 | 1991,"Iceland",87.6,40.06,-0.22,2.55 493 | 1992,"Iceland",87.6,40.54,-3.37,4.31 494 | 1993,"Iceland",87.6,40.37,1.31,5.26 495 | 1994,"Iceland",87.6,39.94,3.61,5.33 496 | 1995,"Iceland",87.4,42.7,0.12,4.86 497 | 1996,"Iceland",87.4,42.21,4.79,3.72 498 | 1997,"Iceland",87.4,40.69,4.91,3.88 499 | 1998,"Iceland",87.4,41.3,6.32,2.74 500 | 1999,"Iceland",84.1,42.05,4.09,2.01 501 | 2000,"Iceland",84.1,41.87,4.32,2.31 502 | 2001,"Iceland",84.1,42.6,3.92,2.26 503 | 2002,"Iceland",84.1,44.25,0.14,3.25 504 | 2003,"Iceland",87.7,45.61,2.43,3.35 505 | 2004,"Iceland",87.7,43.99,7.84,3.06 506 | 2005,"Iceland",87.7,42.25,7.23,2.59 507 | 2006,"Iceland",87.7,41.64,4.71,2.88 508 | 2007,"Iceland",83.6,42.27,5.99,2.3 509 | 2008,"Iceland",83.6,57.61,1.27,2.99 510 | 2009,"Iceland",85.1,51.05,-6.81,7.24 511 | 2010,"Iceland",85.1,51.61,-4.02,7.56 512 | 1960,"Ireland",71.3,29.44,NA,5.68 513 | 1961,"Ireland",70.6,31.77,5.02,6.39 514 | 1962,"Ireland",70.6,32.01,3.21,4.88 515 | 1963,"Ireland",70.6,34,4.75,5.03 516 | 1964,"Ireland",70.6,35.21,3.79,4.75 517 | 1965,"Ireland",75.1,36.19,1.93,4.59 518 | 1966,"Ireland",75.1,37.27,0.89,5.92 519 | 1967,"Ireland",75.1,39.71,5.79,5.05 520 | 1968,"Ireland",75.1,40.45,8.24,5.38 521 | 1969,"Ireland",76.9,42.98,5.86,5.03 522 | 1970,"Ireland",76.9,44.59,2.66,5.86 523 | 1971,"Ireland",76.9,45.8,3.47,6.88 524 | 1972,"Ireland",76.9,41.92,6.49,6.21 525 | 1973,"Ireland",76.6,40.72,4.72,5.71 526 | 1974,"Ireland",76.6,44.76,4.26,5.39 527 | 1975,"Ireland",76.6,48.7,5.66,9.33 528 | 1976,"Ireland",76.6,48.32,1.39,9.09 529 | 1977,"Ireland",76.3,45.03,8.21,8.81 530 | 1978,"Ireland",76.3,46.69,7.19,8.29 531 | 1979,"Ireland",76.3,49.17,3.07,6.83 532 | 1980,"Ireland",76.3,54.26,3.08,7.39 533 | 1981,"Ireland",76.2,54.67,3.33,10.5 534 | 1982,"Ireland",72.8,57.28,2.28,11.55 535 | 1983,"Ireland",72.8,56.14,-0.24,14.04 536 | 1984,"Ireland",72.8,53.23,4.35,15.6 537 | 1985,"Ireland",72.8,53.87,3.09,16.74 538 | 1986,"Ireland",72.8,53.57,-0.43,17.15 539 | 1987,"Ireland",73.3,52.01,4.66,16.97 540 | 1988,"Ireland",73.3,48.44,5.22,16.38 541 | 1989,"Ireland",68.5,42.66,5.81,15.19 542 | 1990,"Ireland",68.5,42.38,8.47,13.03 543 | 1991,"Ireland",68.5,43.95,1.93,14.76 544 | 1992,"Ireland",68.5,44.37,3.34,15.17 545 | 1993,"Ireland",68.5,44.17,2.69,15.79 546 | 1994,"Ireland",68.5,43.47,5.76,14.82 547 | 1995,"Ireland",68.5,40.94,9.63,12.24 548 | 1996,"Ireland",68.5,38.95,7.6,11.95 549 | 1997,"Ireland",65.9,36.54,10.92,10.39 550 | 1998,"Ireland",65.9,34.36,7.84,7.86 551 | 1999,"Ireland",65.9,33.92,9.9,5.94 552 | 2000,"Ireland",65.9,31.19,9.29,4.53 553 | 2001,"Ireland",65.9,33.02,4.83,3.86 554 | 2002,"Ireland",62.7,33.35,5.88,4.46 555 | 2003,"Ireland",62.7,33.12,4.16,4.61 556 | 2004,"Ireland",62.7,33.49,4.52,4.54 557 | 2005,"Ireland",62.7,33.76,5.33,4.71 558 | 2006,"Ireland",62.7,34.26,5.33,4.6 559 | 2007,"Ireland",67,36.61,5.17,4.67 560 | 2008,"Ireland",67,42.82,-2.98,5.68 561 | 2009,"Ireland",67,48.83,-7,12.04 562 | 2010,"Ireland",67,66.78,-0.43,13.69 563 | 1960,"Italy",93.7,28.49,NA,5.66 564 | 1961,"Italy",93.7,27.56,8.21,5.16 565 | 1962,"Italy",93.7,28.59,6.2,4.56 566 | 1963,"Italy",92.9,29.21,5.61,3.88 567 | 1964,"Italy",92.9,29.89,2.8,4.34 568 | 1965,"Italy",92.9,32.13,3.27,5.4 569 | 1966,"Italy",92.9,32.05,5.98,5.88 570 | 1967,"Italy",92.9,31.53,7.18,5.42 571 | 1968,"Italy",92.8,32.59,6.54,5.73 572 | 1969,"Italy",92.8,32.03,6.1,5.72 573 | 1970,"Italy",92.8,32.3,5.31,5.47 574 | 1971,"Italy",92.8,34.35,1.93,5.47 575 | 1972,"Italy",93.2,36.33,3.15,6.43 576 | 1973,"Italy",93.2,35.23,6.55,6.42 577 | 1974,"Italy",93.2,34.75,5.28,5.42 578 | 1975,"Italy",93.2,39.08,-2.05,5.92 579 | 1976,"Italy",93.4,38.08,6.53,6.75 580 | 1977,"Italy",93.4,38.46,2.36,7.21 581 | 1978,"Italy",93.4,40.86,3.65,7.28 582 | 1979,"Italy",91.1,40.11,5.53,7.75 583 | 1980,"Italy",91.1,40.55,3.48,7.66 584 | 1981,"Italy",91.1,44.43,0.78,7.99 585 | 1982,"Italy",91.1,46.56,0.33,8.65 586 | 1983,"Italy",89,48.68,1.37,9.52 587 | 1984,"Italy",89,48.89,3.21,10.14 588 | 1985,"Italy",89,49.58,2.84,10.41 589 | 1986,"Italy",89,50.14,2.97,11.24 590 | 1987,"Italy",90.5,49.57,2.96,12.09 591 | 1988,"Italy",90.5,50.13,4.3,12.11 592 | 1989,"Italy",90.5,51.29,3.47,12.1 593 | 1990,"Italy",90.5,52.6,1.95,11.48 594 | 1991,"Italy",90.5,53.67,1.53,11.03 595 | 1992,"Italy",87.3,55.07,0.7,10.65 596 | 1993,"Italy",87.3,56.03,-0.86,10.17 597 | 1994,"Italy",86.1,53.2,2.28,11.16 598 | 1995,"Italy",86.1,52.16,2.96,11.73 599 | 1996,"Italy",82.9,52.18,1,11.74 600 | 1997,"Italy",82.9,49.94,1.91,11.83 601 | 1998,"Italy",82.9,48.95,1.32,11.94 602 | 1999,"Italy",82.9,47.91,1.42,11.52 603 | 2000,"Italy",82.9,45.82,3.89,10.68 604 | 2001,"Italy",81.2,47.71,1.76,9.62 605 | 2002,"Italy",81.2,47.12,0.45,9.1 606 | 2003,"Italy",81.2,48.05,0.03,8.76 607 | 2004,"Italy",81.2,47.58,1.56,8.13 608 | 2005,"Italy",81.2,47.89,1.09,7.81 609 | 2006,"Italy",83.6,48.39,2.27,6.85 610 | 2007,"Italy",83.6,47.64,1.55,6.15 611 | 2008,"Italy",78.1,48.61,-1.16,6.81 612 | 2009,"Italy",78.1,51.89,-5.5,7.87 613 | 2010,"Italy",78.1,50.54,1.76,8.51 614 | 1960,"Japan",73.5,19.18,NA,1.66 615 | 1961,"Japan",73.5,20.01,11.87,1.45 616 | 1962,"Japan",73.5,20.62,8.66,1.28 617 | 1963,"Japan",71.1,20.86,8.73,1.27 618 | 1964,"Japan",71.1,20.83,11.27,1.15 619 | 1965,"Japan",71.1,21.07,5.7,1.19 620 | 1966,"Japan",71.1,21.14,10.33,1.33 621 | 1967,"Japan",74,21.35,11,1.26 622 | 1968,"Japan",74,21.65,11.87,1.17 623 | 1969,"Japan",68.5,21.64,11.91,1.12 624 | 1970,"Japan",68.5,22.46,10.4,1.14 625 | 1971,"Japan",68.5,23.52,4.41,1.23 626 | 1972,"Japan",71.7,23.97,8.31,1.4 627 | 1973,"Japan",71.7,24.56,8.1,1.28 628 | 1974,"Japan",71.7,26.72,-1.16,1.37 629 | 1975,"Japan",71.7,27.05,3.07,1.88 630 | 1976,"Japan",73.4,27.14,3.98,2.01 631 | 1977,"Japan",73.4,28.61,4.4,2.02 632 | 1978,"Japan",73.4,29.7,5.26,2.24 633 | 1979,"Japan",68,31.66,5.43,2.09 634 | 1980,"Japan",74.6,33.02,2.82,2.02 635 | 1981,"Japan",74.6,33.67,4.22,2.21 636 | 1982,"Japan",74.6,33.87,3.39,2.36 637 | 1983,"Japan",67.9,34.13,3.05,2.65 638 | 1984,"Japan",67.9,33.29,4.58,2.72 639 | 1985,"Japan",67.9,32.22,6.21,2.62 640 | 1986,"Japan",71.4,32.3,2.87,2.77 641 | 1987,"Japan",71.4,32.74,4.04,2.84 642 | 1988,"Japan",71.4,31.91,7.26,2.51 643 | 1989,"Japan",71.4,31.07,5.3,2.26 644 | 1990,"Japan",73.3,31.22,5.62,2.1 645 | 1991,"Japan",73.3,31.2,3.32,2.09 646 | 1992,"Japan",73.3,32.29,0.9,2.16 647 | 1993,"Japan",67,34.05,0.11,2.51 648 | 1994,"Japan",67,34.61,0.9,2.89 649 | 1995,"Japan",67,35.56,1.93,3.15 650 | 1996,"Japan",59,36.25,2.66,3.35 651 | 1997,"Japan",59,35.22,1.6,3.39 652 | 1998,"Japan",59,42,-2.11,4.11 653 | 1999,"Japan",59,38.01,-0.08,4.68 654 | 2000,"Japan",62.5,38.54,2.23,4.73 655 | 2001,"Japan",62.5,37.99,0.35,5.04 656 | 2002,"Japan",62.5,38.24,0.28,5.37 657 | 2003,"Japan",59.9,37.77,1.72,5.25 658 | 2004,"Japan",59.9,36.57,2.34,4.71 659 | 2005,"Japan",67.5,36.42,1.29,4.42 660 | 2006,"Japan",67.5,35.95,1.68,4.13 661 | 2007,"Japan",67.5,35.79,2.17,3.85 662 | 2008,"Japan",67.5,36.96,-1.07,3.98 663 | 2009,"Japan",69.3,41.92,-5.53,5.08 664 | 2010,"Japan",69.3,40.79,4.46,5.07 665 | 1960,"Luxembourg",92.3,NA,NA,0.09 666 | 1961,"Luxembourg",92.3,NA,3.83,0.09 667 | 1962,"Luxembourg",92.3,NA,1.36,0.06 668 | 1963,"Luxembourg",92.3,NA,3.44,0.16 669 | 1964,"Luxembourg",90.6,NA,7.87,0.03 670 | 1965,"Luxembourg",90.6,NA,1.93,0.03 671 | 1966,"Luxembourg",90.6,NA,1.11,0.02 672 | 1967,"Luxembourg",90.6,NA,0.22,0.03 673 | 1968,"Luxembourg",88.6,NA,4.18,0.07 674 | 1969,"Luxembourg",88.6,NA,9.97,0.03 675 | 1970,"Luxembourg",88.6,NA,1.7,0.03 676 | 1971,"Luxembourg",88.6,NA,2.67,0.01 677 | 1972,"Luxembourg",88.6,NA,6.6,0.03 678 | 1973,"Luxembourg",88.6,NA,8.31,0.03 679 | 1974,"Luxembourg",90.1,NA,4.21,0.04 680 | 1975,"Luxembourg",90.1,NA,-6.57,0.17 681 | 1976,"Luxembourg",90.1,NA,2.53,0.29 682 | 1977,"Luxembourg",90.1,NA,1.57,0.52 683 | 1978,"Luxembourg",90.1,NA,4.07,0.74 684 | 1979,"Luxembourg",88.9,NA,2.35,0.67 685 | 1980,"Luxembourg",88.9,NA,0.84,0.69 686 | 1981,"Luxembourg",88.9,NA,-0.55,0.98 687 | 1982,"Luxembourg",88.9,NA,1.13,1.28 688 | 1983,"Luxembourg",88.9,NA,2.99,1.55 689 | 1984,"Luxembourg",88.8,NA,6.19,1.68 690 | 1985,"Luxembourg",88.8,NA,2.79,1.59 691 | 1986,"Luxembourg",88.8,NA,9.98,1.38 692 | 1987,"Luxembourg",88.8,NA,3.95,1.55 693 | 1988,"Luxembourg",88.8,NA,8.46,1.41 694 | 1989,"Luxembourg",87.3,NA,9.8,1.25 695 | 1990,"Luxembourg",87.3,37.75,5.32,1.09 696 | 1991,"Luxembourg",87.3,38.4,8.64,1.17 697 | 1992,"Luxembourg",87.3,40.01,1.82,1.35 698 | 1993,"Luxembourg",87.3,39.77,4.2,1.7 699 | 1994,"Luxembourg",88.3,38.95,3.82,2.17 700 | 1995,"Luxembourg",88.3,39.68,1.43,2.33 701 | 1996,"Luxembourg",88.3,41.13,1.52,2.51 702 | 1997,"Luxembourg",88.3,40.65,5.94,2.72 703 | 1998,"Luxembourg",88.3,41.06,6.49,2.28 704 | 1999,"Luxembourg",86.5,39.19,8.42,2.1 705 | 2000,"Luxembourg",86.5,37.59,8.44,1.85 706 | 2001,"Luxembourg",86.5,38.13,2.52,1.74 707 | 2002,"Luxembourg",86.5,41.53,4.1,2 708 | 2003,"Luxembourg",86.5,41.78,1.55,2.54 709 | 2004,"Luxembourg",91.9,42.55,4.4,2.84 710 | 2005,"Luxembourg",91.9,41.52,5.43,3.11 711 | 2006,"Luxembourg",91.9,38.58,4.97,2.88 712 | 2007,"Luxembourg",91.9,36.27,6.64,2.81 713 | 2008,"Luxembourg",91.9,37.12,0.75,2.89 714 | 2009,"Luxembourg",90.9,43,-5.3,3.96 715 | 2010,"Luxembourg",90.9,42.43,2.68,4.25 716 | 1960,"Netherlands",95.6,NA,NA,0.72 717 | 1961,"Netherlands",95.6,NA,3.22,0.52 718 | 1962,"Netherlands",95.6,NA,4.15,0.53 719 | 1963,"Netherlands",95.1,NA,3.71,0.57 720 | 1964,"Netherlands",95.1,NA,7.98,0.49 721 | 1965,"Netherlands",95.1,NA,5.69,0.55 722 | 1966,"Netherlands",95.1,NA,3.02,0.79 723 | 1967,"Netherlands",94.9,NA,5.55,1.64 724 | 1968,"Netherlands",94.9,NA,6.57,1.47 725 | 1969,"Netherlands",94.9,43.6,5.42,1.05 726 | 1970,"Netherlands",94.9,44.82,5.7,0.99 727 | 1971,"Netherlands",79.1,46.35,4.22,1.3 728 | 1972,"Netherlands",83.5,45.59,3.31,2.26 729 | 1973,"Netherlands",83.5,45.35,4.69,2.3 730 | 1974,"Netherlands",83.5,47.3,3.97,2.81 731 | 1975,"Netherlands",83.5,52.06,-0.09,5.31 732 | 1976,"Netherlands",83.5,51.83,5.12,5.64 733 | 1977,"Netherlands",88,50.97,2.32,5.45 734 | 1978,"Netherlands",88,52.72,2.48,5.43 735 | 1979,"Netherlands",88,54.15,1.84,5.49 736 | 1980,"Netherlands",88,55.83,1.68,6.16 737 | 1981,"Netherlands",87,57.47,-0.51,8.65 738 | 1982,"Netherlands",81,59.68,-1.28,11.56 739 | 1983,"Netherlands",81,59.6,1.76,11.86 740 | 1984,"Netherlands",81,58.73,3.12,12.15 741 | 1985,"Netherlands",81,57.49,2.66,10.5 742 | 1986,"Netherlands",85.8,57.12,3.13,10.5 743 | 1987,"Netherlands",85.8,58.5,1.85,9.98 744 | 1988,"Netherlands",85.8,56.35,2.98,9.41 745 | 1989,"Netherlands",80.3,54.39,4.48,8.76 746 | 1990,"Netherlands",80.3,54.85,4.18,7.74 747 | 1991,"Netherlands",80.3,54.87,2.45,7.33 748 | 1992,"Netherlands",80.3,55.68,1.58,5.55 749 | 1993,"Netherlands",80.3,55.72,1.26,6.28 750 | 1994,"Netherlands",78.8,53.5,3.01,7.16 751 | 1995,"Netherlands",78.8,56.33,3.26,7.16 752 | 1996,"Netherlands",78.8,49.4,3.29,6.42 753 | 1997,"Netherlands",78.8,47.48,4.34,5.51 754 | 1998,"Netherlands",73.3,46.63,3.86,4.39 755 | 1999,"Netherlands",73.3,46.01,4.61,3.62 756 | 2000,"Netherlands",73.3,44.13,4.02,2.73 757 | 2001,"Netherlands",73.3,45.3,1.99,2.12 758 | 2002,"Netherlands",79.1,46.15,0.08,2.55 759 | 2003,"Netherlands",80,47.04,0.32,3.59 760 | 2004,"Netherlands",80,46.13,2.04,4.65 761 | 2005,"Netherlands",80,44.77,2.16,4.72 762 | 2006,"Netherlands",80.4,45.5,3.45,3.91 763 | 2007,"Netherlands",80.4,45.23,3.91,3.18 764 | 2008,"Netherlands",80.4,46.21,1.77,2.75 765 | 2009,"Netherlands",80.4,51.53,-3.53,3.41 766 | 2010,"Netherlands",75.4,51.2,1.63,4.45 767 | 1960,"New Zealand",89.7,NA,NA,0.12 768 | 1961,"New Zealand",89.7,NA,4.44,0 769 | 1962,"New Zealand",89.7,NA,2.48,0.11 770 | 1963,"New Zealand",90.2,NA,4.32,0.11 771 | 1964,"New Zealand",90.2,NA,4.2,0.11 772 | 1965,"New Zealand",90.2,NA,6.33,0.1 773 | 1966,"New Zealand",86,NA,8.16,0.1 774 | 1967,"New Zealand",86,NA,-3.29,0.1 775 | 1968,"New Zealand",86,NA,-2.77,0.78 776 | 1969,"New Zealand",88.9,NA,6.68,0.29 777 | 1970,"New Zealand",88.9,NA,3.31,0.09 778 | 1971,"New Zealand",88.9,NA,2.71,0.18 779 | 1972,"New Zealand",89.1,NA,1.61,0.45 780 | 1973,"New Zealand",89.1,NA,9.02,0.17 781 | 1974,"New Zealand",89.1,NA,11.31,0.08 782 | 1975,"New Zealand",82.5,NA,-5.14,0.25 783 | 1976,"New Zealand",82.5,NA,3.25,0.32 784 | 1977,"New Zealand",82.5,NA,-1.34,0.32 785 | 1978,"New Zealand",83.7,NA,-6.37,1.66 786 | 1979,"New Zealand",83.7,NA,1.5,1.94 787 | 1980,"New Zealand",83.7,NA,0.39,2.24 788 | 1981,"New Zealand",89,NA,4.66,3.6 789 | 1982,"New Zealand",89,NA,3.37,3.54 790 | 1983,"New Zealand",89,NA,1.11,5.66 791 | 1984,"New Zealand",91.7,NA,8.52,5.74 792 | 1985,"New Zealand",91.7,NA,1.62,4.18 793 | 1986,"New Zealand",91.7,58.56,0.59,4.12 794 | 1987,"New Zealand",87.2,53.77,0.72,4.13 795 | 1988,"New Zealand",87.2,52.82,2.65,5.63 796 | 1989,"New Zealand",87.2,51.61,0.49,7.13 797 | 1990,"New Zealand",83.2,52.68,0.67,7.97 798 | 1991,"New Zealand",83.2,49.7,-1.9,10.6 799 | 1992,"New Zealand",83.2,48.94,0.88,10.62 800 | 1993,"New Zealand",82.8,45.24,4.7,9.75 801 | 1994,"New Zealand",82.8,42.84,6.21,8.36 802 | 1995,"New Zealand",82.8,41.93,4.36,6.43 803 | 1996,"New Zealand",88.8,40.83,3.39,6.3 804 | 1997,"New Zealand",88.8,41.64,2.88,6.87 805 | 1998,"New Zealand",88.8,40.62,0.56,7.7 806 | 1999,"New Zealand",84.8,40.24,4.71,7.05 807 | 2000,"New Zealand",84.8,38.25,3.74,6.15 808 | 2001,"New Zealand",84.8,37.81,2.48,5.43 809 | 2002,"New Zealand",77,36.94,4.59,5.27 810 | 2003,"New Zealand",77,37.53,4.42,4.77 811 | 2004,"New Zealand",77,37.11,4.07,4.03 812 | 2005,"New Zealand",77,38.25,3.18,3.83 813 | 2006,"New Zealand",77,39.6,2.02,3.83 814 | 2007,"New Zealand",77,39.65,3.39,3.68 815 | 2008,"New Zealand",75.1,41.87,-0.68,4.16 816 | 2009,"New Zealand",75.1,42.85,-0.11,6.16 817 | 2010,"New Zealand",75.1,43.2,2.4,6.52 818 | 1960,"Norway",78.3,NA,NA,1.2 819 | 1961,"Norway",79.1,NA,6.27,0.91 820 | 1962,"Norway",79.1,30.57,2.81,1.05 821 | 1963,"Norway",79.1,31.92,3.79,1.25 822 | 1964,"Norway",79.1,31.95,5.01,1.11 823 | 1965,"Norway",85.4,32.95,5.29,0.9 824 | 1966,"Norway",85.4,33.45,3.79,0.82 825 | 1967,"Norway",85.4,34.9,6.26,0.75 826 | 1968,"Norway",85.4,36.21,2.26,1.15 827 | 1969,"Norway",83.8,38,4.5,1.07 828 | 1970,"Norway",83.8,38.91,2,0.8 829 | 1971,"Norway",83.8,40.74,5.13,0.79 830 | 1972,"Norway",83.8,42.25,5.09,1.68 831 | 1973,"Norway",80.2,42.26,4.41,1.56 832 | 1974,"Norway",80.2,42.2,4.19,1.49 833 | 1975,"Norway",80.2,43.54,5.23,2.3 834 | 1976,"Norway",80.2,45.25,5.86,1.77 835 | 1977,"Norway",82.9,46.53,4.27,1.47 836 | 1978,"Norway",82.9,47.93,3.49,1.81 837 | 1979,"Norway",82.9,47.18,4.36,2 838 | 1980,"Norway",82.9,46.13,4.5,1.68 839 | 1981,"Norway",82,46.08,1.55,2.06 840 | 1982,"Norway",82,46.6,0.13,2.65 841 | 1983,"Norway",82,46.36,3.87,3.49 842 | 1984,"Norway",82,44.46,5.89,3.2 843 | 1985,"Norway",84,44,5.35,2.6 844 | 1986,"Norway",84,48.13,4.04,2 845 | 1987,"Norway",84,50.47,1.78,2.11 846 | 1988,"Norway",84,52.61,-0.17,3.21 847 | 1989,"Norway",83.2,52.16,1,5 848 | 1990,"Norway",83.2,54.01,1.93,5.32 849 | 1991,"Norway",83.2,54.94,3.11,5.55 850 | 1992,"Norway",83.2,56.28,3.52,6.01 851 | 1993,"Norway",75.8,55.13,2.79,6.06 852 | 1994,"Norway",75.8,54.07,5.05,5.47 853 | 1995,"Norway",75.8,50.94,4.19,4.97 854 | 1996,"Norway",75.8,48.5,5.1,4.88 855 | 1997,"Norway",78.3,46.83,5.39,4.07 856 | 1998,"Norway",78.3,49.08,2.68,3.23 857 | 1999,"Norway",78.3,47.69,2.03,3.25 858 | 2000,"Norway",78.3,42.3,3.25,3.48 859 | 2001,"Norway",75.5,44.11,1.99,3.59 860 | 2002,"Norway",75.5,47.06,1.5,3.9 861 | 2003,"Norway",75.5,48.16,0.98,4.54 862 | 2004,"Norway",75.5,45.13,3.96,4.48 863 | 2005,"Norway",77.4,41.8,2.59,4.64 864 | 2006,"Norway",77.4,40.04,2.45,3.46 865 | 2007,"Norway",77.4,40.34,2.65,2.53 866 | 2008,"Norway",77.4,39.77,0.04,2.6 867 | 2009,"Norway",76.4,46.72,-1.67,3.19 868 | 2010,"Norway",76.4,45.5,0.68,3.63 869 | 1960,"Portugal",NA,NA,NA,1.91 870 | 1961,"Portugal",NA,NA,5.47,2.28 871 | 1962,"Portugal",NA,NA,6.65,2.55 872 | 1963,"Portugal",NA,NA,5.92,2.56 873 | 1964,"Portugal",NA,NA,6.57,2.57 874 | 1965,"Portugal",NA,NA,7.48,2.64 875 | 1966,"Portugal",NA,NA,4.08,2.63 876 | 1967,"Portugal",NA,NA,7.54,2.61 877 | 1968,"Portugal",NA,NA,8.88,2.65 878 | 1969,"Portugal",NA,NA,2.12,2.66 879 | 1970,"Portugal",NA,NA,9.11,2.65 880 | 1971,"Portugal",NA,NA,6.63,2.63 881 | 1972,"Portugal",NA,NA,8.02,2.64 882 | 1973,"Portugal",NA,NA,11.2,2.67 883 | 1974,"Portugal",NA,NA,1.14,1.78 884 | 1975,"Portugal",91.7,NA,-4.35,4.56 885 | 1976,"Portugal",83.3,NA,6.9,6.42 886 | 1977,"Portugal",83.3,28.33,5.6,7.55 887 | 1978,"Portugal",83.3,30.82,2.82,8.13 888 | 1979,"Portugal",87.5,30.28,5.64,8.19 889 | 1980,"Portugal",85.4,32.68,4.59,7.84 890 | 1981,"Portugal",85.4,36.16,1.62,7.55 891 | 1982,"Portugal",85.4,35.57,2.14,7.47 892 | 1983,"Portugal",78.6,35.47,-0.17,7.92 893 | 1984,"Portugal",78.6,35.43,-1.88,8.55 894 | 1985,"Portugal",75.4,36.79,2.81,8.67 895 | 1986,"Portugal",75.4,37.86,4.14,8.59 896 | 1987,"Portugal",72.6,37.14,6.38,7.1 897 | 1988,"Portugal",72.6,36.01,7.49,5.77 898 | 1989,"Portugal",72.6,36.08,6.44,5.05 899 | 1990,"Portugal",72.6,38.86,3.95,4.61 900 | 1991,"Portugal",68.2,41.67,4.37,4.32 901 | 1992,"Portugal",68.2,42.72,1.09,4.08 902 | 1993,"Portugal",68.2,44.23,-2.04,5.48 903 | 1994,"Portugal",68.2,42.77,0.96,6.82 904 | 1995,"Portugal",66.3,41.88,4.28,7.15 905 | 1996,"Portugal",66.3,42.4,3.69,7.23 906 | 1997,"Portugal",66.3,41.56,4.41,6.72 907 | 1998,"Portugal",66.3,41.44,5.14,4.98 908 | 1999,"Portugal",61.8,41.48,4.07,4.43 909 | 2000,"Portugal",61.8,41.62,3.92,3.96 910 | 2001,"Portugal",61.8,43.16,1.97,4.04 911 | 2002,"Portugal",61.5,43.06,0.76,5.03 912 | 2003,"Portugal",61.5,44.68,-0.91,6.31 913 | 2004,"Portugal",61.5,45.42,1.56,6.69 914 | 2005,"Portugal",64.3,46.56,0.78,7.66 915 | 2006,"Portugal",64.3,45.22,1.45,7.7 916 | 2007,"Portugal",64.3,44.36,2.37,8.03 917 | 2008,"Portugal",64.3,44.8,-0.01,7.64 918 | 2009,"Portugal",59.7,49.76,-2.91,9.52 919 | 2010,"Portugal",59.7,51.26,1.4,10.85 920 | 1960,"Spain",NA,NA,NA,1.5 921 | 1961,"Spain",NA,NA,12.54,1.48 922 | 1962,"Spain",NA,NA,10.01,1.2 923 | 1963,"Spain",NA,NA,9.45,1.34 924 | 1964,"Spain",NA,20.73,5.27,1.54 925 | 1965,"Spain",NA,21.62,6.25,1.51 926 | 1966,"Spain",NA,21.41,7.25,1.36 927 | 1967,"Spain",NA,22.59,4.34,1.88 928 | 1968,"Spain",NA,22.74,6.6,1.93 929 | 1969,"Spain",NA,22.77,8.91,1.47 930 | 1970,"Spain",NA,23.34,4.25,1.53 931 | 1971,"Spain",NA,25.09,4.65,2.01 932 | 1972,"Spain",NA,24.38,8.15,3.03 933 | 1973,"Spain",NA,24,7.8,2.75 934 | 1974,"Spain",NA,24.46,5.62,3.25 935 | 1975,"Spain",NA,26.07,0.54,4.69 936 | 1976,"Spain",NA,27.3,3.3,4.6 937 | 1977,"Spain",77,28.83,2.84,5.23 938 | 1978,"Spain",77,30.86,1.46,7 939 | 1979,"Spain",68.1,31.81,0.04,8.71 940 | 1980,"Spain",68.1,33.91,1.3,11.51 941 | 1981,"Spain",68.1,36.67,-0.13,14.16 942 | 1982,"Spain",79.8,38.78,1.25,15.99 943 | 1983,"Spain",79.8,39.77,1.77,17.45 944 | 1984,"Spain",79.8,40.06,1.78,20.21 945 | 1985,"Spain",79.8,42.71,2.32,21.6 946 | 1986,"Spain",70.6,42.21,3.25,21.13 947 | 1987,"Spain",70.6,40.57,5.55,20.33 948 | 1988,"Spain",70.6,40.42,5.09,19.34 949 | 1989,"Spain",70,41.7,4.83,17.32 950 | 1990,"Spain",70,42.87,3.78,16.32 951 | 1991,"Spain",70,44.36,2.54,16.4 952 | 1992,"Spain",70,45.42,0.93,18.46 953 | 1993,"Spain",76.4,49.01,-1.03,22.78 954 | 1994,"Spain",76.4,46.75,2.38,24.17 955 | 1995,"Spain",76.4,44.46,2.76,22.96 956 | 1996,"Spain",77.4,43.23,2.42,22.15 957 | 1997,"Spain",77.4,41.65,3.87,20.67 958 | 1998,"Spain",77.4,41.09,4.47,18.67 959 | 1999,"Spain",77.4,39.93,4.75,15.69 960 | 2000,"Spain",68.7,39.19,5.05,13.92 961 | 2001,"Spain",68.7,38.66,3.67,10.6 962 | 2002,"Spain",68.7,38.91,2.71,11.52 963 | 2003,"Spain",68.7,38.41,3.09,11.52 964 | 2004,"Spain",75.7,38.89,3.26,11 965 | 2005,"Spain",75.7,38.44,3.58,9.19 966 | 2006,"Spain",75.7,38.35,4.08,8.54 967 | 2007,"Spain",75.7,39.21,3.48,8.29 968 | 2008,"Spain",73.9,41.46,0.89,11.38 969 | 2009,"Spain",73.9,46.26,-3.74,18.09 970 | 2010,"Spain",73.9,45.62,-0.07,20.15 971 | 1960,"Sweden",85.9,32.61,NA,1.72 972 | 1961,"Sweden",85.9,32.4,5.68,1.49 973 | 1962,"Sweden",85.9,33.46,4.26,1.48 974 | 1963,"Sweden",85.9,35.82,5.33,1.67 975 | 1964,"Sweden",83.9,36.03,6.82,1.56 976 | 1965,"Sweden",83.9,36.75,3.82,1.18 977 | 1966,"Sweden",83.9,38.8,2.09,1.56 978 | 1967,"Sweden",83.9,40.51,3.37,2.12 979 | 1968,"Sweden",89.3,42.73,3.64,2.22 980 | 1969,"Sweden",89.3,42.84,5.01,1.89 981 | 1970,"Sweden",88.3,43.01,6.47,1.51 982 | 1971,"Sweden",88.3,45.71,0.94,2.55 983 | 1972,"Sweden",88.3,46.18,2.29,2.7 984 | 1973,"Sweden",90.8,43.57,3.97,2.46 985 | 1974,"Sweden",90.8,45.86,3.2,1.98 986 | 1975,"Sweden",90.8,46.28,2.55,1.62 987 | 1976,"Sweden",91.8,49.7,1.06,1.71 988 | 1977,"Sweden",91.8,56.62,-1.6,1.96 989 | 1978,"Sweden",91.8,58.48,1.75,2.46 990 | 1979,"Sweden",90.7,59.7,3.84,2.27 991 | 1980,"Sweden",90.7,62.65,1.7,2.22 992 | 1981,"Sweden",90.7,62.85,-0.2,2.77 993 | 1982,"Sweden",91.4,64.97,1.19,3.53 994 | 1983,"Sweden",91.4,64.9,1.81,3.89 995 | 1984,"Sweden",91.4,62.31,4.27,3.49 996 | 1985,"Sweden",89.9,63.18,2.19,3.09 997 | 1986,"Sweden",89.9,60.74,2.86,2.89 998 | 1987,"Sweden",89.9,58.54,3.46,2.31 999 | 1988,"Sweden",86,58.03,2.67,1.88 1000 | 1989,"Sweden",86,59.97,2.78,1.62 1001 | 1990,"Sweden",86,59.77,1.01,1.81 1002 | 1991,"Sweden",86.7,61.14,-1.12,3.26 1003 | 1992,"Sweden",86.7,69.39,-1.2,5.83 1004 | 1993,"Sweden",86.7,70.54,-2.06,9.48 1005 | 1994,"Sweden",86.8,68.34,3.88,9.78 1006 | 1995,"Sweden",86.8,64.95,4.16,9.22 1007 | 1996,"Sweden",86.8,62.92,1.63,9.98 1008 | 1997,"Sweden",86.8,60.66,2.91,10.19 1009 | 1998,"Sweden",81.4,58.78,4.11,8.47 1010 | 1999,"Sweden",81.4,58.11,4.4,7.17 1011 | 2000,"Sweden",81.4,55.09,4.6,5.86 1012 | 2001,"Sweden",81.4,54.52,1.41,5.06 1013 | 2002,"Sweden",80.1,55.6,2.5,5.21 1014 | 2003,"Sweden",80.1,55.67,2.48,5.85 1015 | 2004,"Sweden",80.1,54.18,3.72,6.63 1016 | 2005,"Sweden",80.1,53.85,3.15,7.78 1017 | 2006,"Sweden",82,52.71,4.55,7.07 1018 | 2007,"Sweden",82,50.95,3.43,6.16 1019 | 2008,"Sweden",82,51.74,-0.77,6.23 1020 | 2009,"Sweden",82,54.94,-4.98,8.31 1021 | 2010,"Sweden",84.6,52.48,5.85,8.38 1022 | 1960,"Switzerland",68.5,NA,NA,0.05 1023 | 1961,"Switzerland",68.5,NA,8.35,0.02 1024 | 1962,"Switzerland",68.5,NA,5.02,0.02 1025 | 1963,"Switzerland",64.5,NA,4.96,0.03 1026 | 1964,"Switzerland",64.5,NA,5.1,0.01 1027 | 1965,"Switzerland",64.5,NA,3.06,0.01 1028 | 1966,"Switzerland",64.5,NA,2.41,0.01 1029 | 1967,"Switzerland",63.8,NA,3,0.01 1030 | 1968,"Switzerland",63.8,NA,3.7,0.01 1031 | 1969,"Switzerland",63.8,NA,5.61,0.01 1032 | 1970,"Switzerland",63.8,NA,6.36,0 1033 | 1971,"Switzerland",56.4,NA,4.08,0 1034 | 1972,"Switzerland",56.4,NA,3.2,0 1035 | 1973,"Switzerland",56.4,NA,3.05,0 1036 | 1974,"Switzerland",56.4,NA,1.45,0.01 1037 | 1975,"Switzerland",52.4,NA,-7.28,0.32 1038 | 1976,"Switzerland",52.4,NA,-1.4,0.69 1039 | 1977,"Switzerland",52.4,NA,2.43,0.39 1040 | 1978,"Switzerland",52.4,NA,0.41,0.33 1041 | 1979,"Switzerland",48.1,NA,2.49,0.32 1042 | 1980,"Switzerland",48.1,NA,4.6,0.19 1043 | 1981,"Switzerland",48.1,NA,1.6,0.18 1044 | 1982,"Switzerland",48.1,NA,-1.31,0.4 1045 | 1983,"Switzerland",48.9,NA,0.64,0.85 1046 | 1984,"Switzerland",48.9,NA,3.01,1.05 1047 | 1985,"Switzerland",48.9,NA,3.67,0.89 1048 | 1986,"Switzerland",48.9,NA,1.86,0.75 1049 | 1987,"Switzerland",46.2,NA,1.59,0.71 1050 | 1988,"Switzerland",46.2,NA,3.28,0.61 1051 | 1989,"Switzerland",46.2,NA,4.33,0.46 1052 | 1990,"Switzerland",46.2,30.3,3.67,0.47 1053 | 1991,"Switzerland",46,32.12,-0.95,1.64 1054 | 1992,"Switzerland",46,34.23,0.1,2.7 1055 | 1993,"Switzerland",46,35.12,-0.19,3.64 1056 | 1994,"Switzerland",46,35.19,1.19,3.64 1057 | 1995,"Switzerland",42.2,35,0.35,3.16 1058 | 1996,"Switzerland",42.2,35.29,0.63,3.46 1059 | 1997,"Switzerland",42.2,35.52,2.08,3.93 1060 | 1998,"Switzerland",42.2,35.77,2.64,3.32 1061 | 1999,"Switzerland",43.3,34.3,1.31,2.81 1062 | 2000,"Switzerland",43.3,35.1,3.58,2.54 1063 | 2001,"Switzerland",43.3,34.78,1.15,2.24 1064 | 2002,"Switzerland",43.3,36.16,0.44,2.87 1065 | 2003,"Switzerland",45.2,36.39,-0.2,3.88 1066 | 2004,"Switzerland",45.2,35.95,2.53,4.15 1067 | 2005,"Switzerland",45.2,35.27,2.64,4.16 1068 | 2006,"Switzerland",45.2,33.48,3.63,3.78 1069 | 2007,"Switzerland",48.3,32.32,3.64,3.42 1070 | 2008,"Switzerland",48.3,32.37,2.1,3.19 1071 | 2009,"Switzerland",48.3,34.15,-1.88,4.06 1072 | 2010,"Switzerland",48.3,34.17,2.71,4.24 1073 | 1960,"UK",78.7,NA,NA,1.36 1074 | 1961,"UK",78.7,NA,2.33,1.18 1075 | 1962,"UK",78.7,NA,1.08,1.65 1076 | 1963,"UK",78.7,NA,4.3,2.01 1077 | 1964,"UK",77.2,NA,5.48,1.4 1078 | 1965,"UK",77.2,NA,2.23,1.19 1079 | 1966,"UK",76,NA,1.92,1.11 1080 | 1967,"UK",76,NA,2.47,2.01 1081 | 1968,"UK",76,NA,4.2,2.17 1082 | 1969,"UK",76,NA,2.07,2.07 1083 | 1970,"UK",72.2,40.54,2.24,2.23 1084 | 1971,"UK",72.2,39.97,2.1,2.8 1085 | 1972,"UK",72.2,41.58,3.65,3.12 1086 | 1973,"UK",72.2,42.23,7.2,2.2 1087 | 1974,"UK",72.9,46.33,-1.31,2.08 1088 | 1975,"UK",72.9,47.83,-0.62,3.28 1089 | 1976,"UK",72.9,47.45,2.64,4.91 1090 | 1977,"UK",72.9,44.71,2.37,5.25 1091 | 1978,"UK",72.9,44.34,3.23,5.16 1092 | 1979,"UK",76.3,43.37,2.68,4.69 1093 | 1980,"UK",76.3,45.59,-2.08,5.71 1094 | 1981,"UK",76.3,48.94,-1.32,9.07 1095 | 1982,"UK",76.3,47.87,2.09,10.51 1096 | 1983,"UK",72.8,47.7,3.62,11.35 1097 | 1984,"UK",72.8,47.89,2.67,11.88 1098 | 1985,"UK",72.8,46.47,3.6,11.32 1099 | 1986,"UK",72.8,45.32,4.01,10.78 1100 | 1987,"UK",75.4,43.24,4.56,10.85 1101 | 1988,"UK",75.4,41.11,5.03,8.81 1102 | 1989,"UK",75.4,40.4,2.28,7.25 1103 | 1990,"UK",75.4,41.48,0.78,6.86 1104 | 1991,"UK",75.4,43.24,-1.39,8.4 1105 | 1992,"UK",77.8,45.25,0.15,9.7 1106 | 1993,"UK",77.8,45.27,2.22,10.33 1107 | 1994,"UK",77.8,44.59,4.28,9.61 1108 | 1995,"UK",77.8,44.08,3.05,8.63 1109 | 1996,"UK",77.8,42.18,2.89,8.14 1110 | 1997,"UK",71.6,40.64,3.42,7.05 1111 | 1998,"UK",71.6,39.52,3.84,6.13 1112 | 1999,"UK",71.6,38.83,3.66,5.98 1113 | 2000,"UK",71.6,36.53,4.46,5.5 1114 | 2001,"UK",59.4,39.81,3.15,4.76 1115 | 2002,"UK",59.4,40.85,2.66,5.09 1116 | 2003,"UK",59.4,42.32,3.52,4.86 1117 | 2004,"UK",59.4,43.05,2.96,4.71 1118 | 2005,"UK",61.8,43.98,2.09,4.68 1119 | 2006,"UK",61.8,44.18,2.61,5.42 1120 | 2007,"UK",61.8,43.93,3.47,5.3 1121 | 2008,"UK",61.8,47.87,-1.1,5.31 1122 | 2009,"UK",61.8,51.09,-4.37,7.74 1123 | 2010,"UK",65.8,50.39,2.09,7.8 1124 | 1960,"USA",61,28.29,NA,5.53 1125 | 1961,"USA",61,29.62,2.33,6.69 1126 | 1962,"USA",47.5,29.71,6.06,5.54 1127 | 1963,"USA",47.5,29.52,4.37,5.67 1128 | 1964,"USA",59.7,28.94,5.79,5.18 1129 | 1965,"USA",59.7,28.44,6.42,4.52 1130 | 1966,"USA",46.6,29.41,6.51,3.79 1131 | 1967,"USA",46.6,31.33,2.53,3.85 1132 | 1968,"USA",56.9,31.63,4.84,3.58 1133 | 1969,"USA",56.9,31.27,3.11,3.51 1134 | 1970,"USA",46.1,32.3,0.19,4.94 1135 | 1971,"USA",46.1,32.49,3.36,5.94 1136 | 1972,"USA",53.2,32.29,5.31,5.61 1137 | 1973,"USA",53.2,31.33,5.79,4.88 1138 | 1974,"USA",37.8,32.68,-0.55,5.61 1139 | 1975,"USA",37.8,35.14,-0.21,8.46 1140 | 1976,"USA",51.6,33.97,5.37,7.7 1141 | 1977,"USA",51.6,33.08,4.6,7.06 1142 | 1978,"USA",37,32.3,5.58,6.07 1143 | 1979,"USA",37,32.28,3.12,5.85 1144 | 1980,"USA",50,34.28,-0.27,7.14 1145 | 1981,"USA",50,34.65,2.54,7.61 1146 | 1982,"USA",40.3,36.99,-1.94,9.69 1147 | 1983,"USA",40.3,37.08,4.52,9.61 1148 | 1984,"USA",51.2,36.16,7.19,7.52 1149 | 1985,"USA",51.2,36.92,4.14,7.2 1150 | 1986,"USA",36.2,37.37,3.46,6.99 1151 | 1987,"USA",36.2,37.17,3.2,6.19 1152 | 1988,"USA",48.2,36.28,4.11,5.51 1153 | 1989,"USA",48.2,36.24,3.57,5.27 1154 | 1990,"USA",35,37.2,1.88,5.6 1155 | 1991,"USA",35,37.97,-0.23,6.83 1156 | 1992,"USA",52.5,38.65,3.39,7.5 1157 | 1993,"USA",52.5,38.1,2.85,6.92 1158 | 1994,"USA",38,37.11,4.07,6.1 1159 | 1995,"USA",38,37.08,2.51,5.6 1160 | 1996,"USA",46,36.55,3.74,5.4 1161 | 1997,"USA",46,35.44,4.46,4.94 1162 | 1998,"USA",35.3,34.62,4.36,4.51 1163 | 1999,"USA",35.3,34.2,4.74,4.22 1164 | 2000,"USA",50,33.88,4.14,3.99 1165 | 2001,"USA",50,34.99,1.08,4.73 1166 | 2002,"USA",36.3,35.91,1.81,5.78 1167 | 2003,"USA",36.3,36.31,2.54,5.99 1168 | 2004,"USA",51.2,36.04,3.47,5.53 1169 | 2005,"USA",51.2,36.29,3.07,5.08 1170 | 2006,"USA",35.8,36.07,2.66,4.62 1171 | 2007,"USA",35.8,36.9,1.91,4.62 1172 | 2008,"USA",53.2,39.12,-0.34,5.78 1173 | 2009,"USA",53.2,42.66,-3.49,9.25 1174 | 2010,"USA",39.8,42.45,3.03,9.63 1175 | -------------------------------------------------------------------------------- /exercises.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Exercises 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | 18 | 1. Make a variable, called `mypython` that contains the path to Python 19 | on your machine. You shouldn't need to manually type the path. 20 | 2. Construct a variable that has the value `@` using 21 | existing environment variables and the `hostname` utility. 22 | 3. Figure out how to use the `mkdir` command to create the following 23 | directory structure in one short command: 24 | 25 | 26 | temp 27 | ├── proj1 28 | │   ├── code 29 | │   └── data 30 | ├── proj2 31 | │   ├── code 32 | │   └── data 33 | └── proj3 34 | ├── code 35 | └── data 36 | 37 | 38 | 4. How would you count the number of lines in an input file, say a data 39 | file. 40 | 5. Print the first three lines of a file to the screen. Now print just 41 | the third line to the screen. 42 | 6. Put the third line of a file in a new file. 43 | 7. Now add the fifth line of the file to that same file from the 44 | previous problem. 45 | 8. Extract the Australia data from the `cpds.csv` dataset and put it in 46 | a file called `cpds_australia.csv`. It's OK if you do this in a 47 | straightforward way and it might fail if 'Australia' is present in 48 | an unexpected column. 49 | 9. Find all the lines in a file that do not contain a comma. (You might 50 | use this to look for anomalies in a CSV file.) 51 | 10. Write shell code that creates files `file1.txt`, `file2.txt`, 52 | `file3.txt`, etc., with the word 'blah' as the only line in each 53 | file. 54 | 11. Write shell code that modifies each file from the previous problem 55 | so that the number `1`, `2`, `3`, etc. is prepended to the 56 | appropriate file (i.e., there is a new first line in each file that 57 | simply contains the number corresponding to the file name). 58 | 59 | You may want to write the code to do this operation on a single file 60 | before embedding the code in the loop. 61 | 62 | 12. Create a shell function that will run a Python job in the background 63 | such that I can run the job by typing: 64 | 65 | ```bash 66 | $ bpy file.py file.out 67 | ``` 68 | 69 | You can create a test jobs with: `echo -e 'a=5\nprint(a)' > file.py` 70 | 71 | 13. Modify the function so that you can simply type : 72 | 73 | ```bash 74 | $ bpy file.py 75 | ``` 76 | 77 | and it will use `file.pyout` as the output file. 78 | 79 | 14. Use `ps` to print out all the processes on the machine with 80 | information on memory and CPU use and sort the output of `ps` in 81 | decreasing order of memory use. 82 | 15. Take `$mypython` from the first problem and strip the `python` off 83 | the end---assigning the result to a new variable, `path_to_py`. 84 | 85 | -------------------------------------------------------------------------------- /file-management.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: File management 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | ## 1 Overview 18 | 19 | In Unix, almost "everything is a file". This means that a very wide 20 | variety of input and output resources (e.g., documents, directories, 21 | keyboards, hard drives, network devices) are streams of bytes available 22 | through the filesystem interface. This means that the basic file 23 | management tools are extremely powerful in Unix. Not only can you use 24 | these tools to work with files, but you can also use them to monitor and 25 | control many aspects of your computer. 26 | 27 | A file typically has these attributes: 28 | 29 | - Name 30 | - Type 31 | - Location 32 | - Size 33 | - Protection (i.e., permissions on what can be done with the file) 34 | - Time, date, and user identification 35 | 36 | These attributes are discussed further as part of [our consideration of file permissions](#4-file-permissions). 37 | 38 | ::: {.callout-warning title="Prerequisite"} 39 | 40 | If you're not familiar with moving between directories, listing files, or the structure of the filesystem, please see our [Basics of UNIX tutorial](https://berkeley-scf.github.io/tutorial-unix-basics#3-files-and-directories). 41 | ::: 42 | 43 | ## 2 Finding files and navigating the filesystem 44 | 45 | You can find files by name, modification time, and type: 46 | 47 | ```bash 48 | $ find . -name '*.txt' # find files named *.txt 49 | $ find . -mtime -2 # find files modified less than 2 days ago 50 | $ find . -type l # find links 51 | ``` 52 | 53 | The `.` argument here indicates to find the file(s) in the current working directory and any subdirectories. 54 | 55 | 56 | As usual for UNIX commands, you can get more information about the `find` command with: 57 | 58 | ```bash 59 | $ man find 60 | $ find --help 61 | ``` 62 | 63 | As discussed in our 64 | [Basics of UNIX tutorial](https://berkeley-scf.github.io/tutorial-unix-basics#3-files-and-directories), 65 | one uses `cd` to change directories. In addition to use of `cd -` to go back to the previous working directory, you can use the `pushd`, `popd`, and `dirs` commands if you would like to keep a stack of previous working directories rather than just the last one. 66 | 67 | In each directory there are two special directories, `.` and `..`, which refer to the current directory and the parent of the current directory, respectively. One only sees these with `ls` if we use the `-a` flag to reveal hidden files. 68 | 69 | ```bash 70 | $ ls -al 71 | total 1489 72 | drwxr-sr-x 7 paciorek scfstaff 31 Apr 21 16:39 ./ 73 | drwxr-sr-x 19 paciorek scfstaff 30 Feb 28 15:07 ../ 74 | ``` 75 | 76 | We saw the use of `.` above with `find`. 77 | 78 | ## 3 Filename matching (globbing) 79 | 80 | Shell file globbing will expand certain special characters (called 81 | wildcards) to match patterns of filenames, before passing those 82 | filenames on to a program. Note that the programs themselves don't know 83 | anything about wildcards; it is the shell that does the expansion, so 84 | that programs don't see the wildcards. The following table shows some of 85 | the special characters that the shell uses for expansion. 86 | 87 | **Table. Filename wildcards** 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 |
WildcardFunction
*Match zero or more characters.
?Match exactly one character.
[characters]Match any single character from among characters listed between brackets.
[!characters]Match any single character other than characters listed between brackets.
[a-z]Match any single character from among the range of characters listed between brackets.
[!a-z]Match any single character from among the characters not in the range listed between brackets
{frag1,frag2,...}Brace expansion: create strings frag1, frag2, etc.
127 | 128 | List all files ending with a digit: 129 | 130 | ```bash 131 | $ ls *[0-9] 132 | ``` 133 | 134 | Make a copy of `filename` as `filename.old`: 135 | 136 | ```bash 137 | $ cp filename{,.old} 138 | ``` 139 | 140 | Remove all files beginning with *a* or *z*: 141 | 142 | ```bash 143 | $ rm [az]* 144 | ``` 145 | 146 | List all the R code files with a variety of suffixes: 147 | 148 | ```bash 149 | $ ls *.{r,R} 150 | ``` 151 | 152 | The `echo` command can be used to verify that a wildcard expansion will 153 | do what you think it will: 154 | 155 | ```bash 156 | $ echo cp filename{,.old} 157 | cp filename filename.old 158 | ``` 159 | 160 | If you want to suppress the special meaning of a wildcard in a shell 161 | command, precede it with a backslash (`\`). (Note that this is a general 162 | rule of thumb in many similar situations when a character has a special 163 | meaning but you just want to treat it as a character.) For example to 164 | list files whose name starts with the `*` character: 165 | 166 | ```bash 167 | $ touch \*test # create a file called *test 168 | $ ls \** 169 | *test 170 | ``` 171 | 172 | To read more about standard globbing patterns, see the man page: 173 | 174 | ``` 175 | $ man 7 glob 176 | ``` 177 | 178 | ## 4 File permissions 179 | 180 | UNIX allows you to control who has access to a given file (or directory) and how the user can interact with the file (or directory). We can see what permissions are set using the `-l` flag to `ls`. 181 | 182 | ```bash 183 | $ cd ~/stat243-fall-2020 184 | $ ls -l 185 | ``` 186 | 187 | ``` 188 | total 152 189 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 data 190 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 howtos 191 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 project 192 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 ps 193 | -rw-rw-r-- 1 scflocal scflocal 11825 Dec 28 13:15 README.md 194 | drwxrwxr-x 13 scflocal scflocal 4096 Dec 28 13:15 sections 195 | -rw-rw-r-- 1 scflocal scflocal 37923 Dec 28 13:15 syllabus.lyx 196 | -rw-rw-r-- 1 scflocal scflocal 77105 Dec 28 13:15 syllabus.pdf 197 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:37 units 198 | ``` 199 | 200 | When using the `-l` flag to `ls`, you'll see extensive information about each file (or directory), of which the most important are: 201 | 202 | - (column 1) file permissions (more later) 203 | - (column 3) the owner of the file ('scflocal' here) 204 | - (column 4) the group of users that the file belongs too (also 'scflocal' here) 205 | - (column 5) the size of the file in bytes 206 | - (column 6-8) the last time the file was modified 207 | - (column 9) name of the file 208 | 209 | Here's a graphical summary of the information for a file named 210 | "file.txt", whose owner is "root" and group is "users". (The graphic also indicates that the commands `chmod`, `chown`, and `chgrp` can be used to change aspects of the file permissions and ownership.) 211 | 212 | ![Schematic of file attributes](ls_format.png) 213 | 214 | 215 | Let's look in detail at the information in the first column returned by `ls -l`. 216 | 217 | ```bash 218 | $ ls -l 219 | total 156 220 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 data 221 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 howtos 222 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 project 223 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:15 ps 224 | -rw-rw-r-- 1 scflocal scflocal 11825 Dec 28 13:15 README.md 225 | drwxrwxr-x 13 scflocal scflocal 4096 Dec 28 13:15 sections 226 | -rw-rw-r-- 1 scflocal scflocal 37923 Dec 28 13:15 syllabus.lyx 227 | -rw-rw-r-- 1 scflocal scflocal 77105 Dec 28 13:15 syllabus.pdf 228 | drwxrwxr-x 2 scflocal scflocal 4096 Dec 28 13:37 units 229 | ``` 230 | 231 | The first column actually contains 10 individual single-character columns. Items marked with a `d` as the first character are directories. Here `data` is a directory while `syllabus.pdf` is not. 232 | 233 | Following that first character are three triplets of file permission information. Each triplet contains read ('r'), write ('w') and execute ('x') information. The first `rwx` triplet (the second through fourth characters) indicates if the owner of the file can read, write, and execute a file (or directory). The second `rwx` triplet (the fifth through seventh characters) indicates if anyone in the group that the file belongs to can read, write and execute a file (or directory). The third triplet (the eighth through tenth characters) pertains to any other user. Dashes mean that a given user does not have that kind of access to the given file. 234 | 235 | For example, for the *syllabus.pdf* file, the owner of the file can read it and can modify the file by writing to it (the first triplet is `'rw-'`), as can users in the group the file belongs to. But for other users, they can only read it (the third triplet is `'r--'`). 236 | 237 | We can change the permissions by indicating the type of user and the kind of access we want to add or remove. The type of user is one of: 238 | 239 | - 'u' for the user who owns the file, 240 | - 'g' for users in the group that the file belongs to, and 241 | - 'o' for any other users. 242 | 243 | Thus we specify one of 'u', 'g', or 'o', followed by a '+' to add permission or a '-' to remove permission and finally by the kind of permission: 'r' for read access, 'w' for write access, and 'x' for execution access. 244 | 245 | As a simple example, let's prevent anyone from reading the `tmp.txt` 246 | file (which we'll create first). We then try to print the contents of the file to the screen with the command `cat`, but we are denied. 247 | 248 | First recall the current permissions: 249 | 250 | ```bash 251 | $ echo "first line" > tmp.txt # create a test text file that contains "first line" 252 | $ ls -l tmp.txt 253 | -rw-rw-r-- 1 scflocal scflocal 11 Dec 28 13:39 tmp.txt 254 | ``` 255 | Now we remove the read permissions: 256 | 257 | ```bash 258 | $ chmod u-r tmp.txt # prevent owner from reading 259 | $ chmod g-r tmp.txt # prevent users in the file's group from reading 260 | $ chmod o-r tmp.txt # prevent others from reading 261 | $ ls -l tmp.txt 262 | --w--w---- 1 scflocal scflocal 11 Dec 28 13:39 tmp.txt 263 | ``` 264 | ```bash 265 | $ cat tmp.txt 266 | cat: tmp.txt: Permission denied 267 | ``` 268 | 269 | That can actually be accomplished all at once, like this: 270 | 271 | ```bash 272 | $ chmod ugo-r tmp.txt # prevent all three 273 | $ ls -l tmp.txt 274 | --w--w---- 1 scflocal scflocal 11 Dec 28 13:39 tmp.txt 275 | ``` 276 | 277 | 278 | Or if we wanted to remove read and write permission, we can do this: 279 | 280 | ```bash 281 | $ chmod ugo-rw tmp.txt # prevent all three 282 | ``` 283 | 284 | Now if we try to add a line to the file, using the `>>` 285 | [redirection operator](using-commands#32-overview-of-redirection), we are denied: 286 | 287 | ```bash 288 | $ echo "added line" >> tmp.txt 289 | -bash: tmp.txt: Permission denied 290 | ``` 291 | 292 | Now let's restore read and write permission to the owner: 293 | 294 | ```bash 295 | $ chmod u+rw tmp.txt 296 | $ echo "added line" >> tmp.txt 297 | $ cat tmp.txt 298 | first line 299 | added line 300 | ``` 301 | 302 | There's lots more details that are important when making files accessible to other users, including: 303 | 304 | - [how to make files in a particular directory available to other users on the system](https://docs-research-it.berkeley.edu/services/high-performance-computing/user-guide/data/transferring-data/making-files-accessible/#making-files-accessible-to-all-other-savio-users), 305 | - [how to set up a directory for use by a UNIX group](https://docs-research-it.berkeley.edu/services/high-performance-computing/user-guide/data/transferring-data/making-files-accessible/#making-files-accessible-to-your-group-members), using the so-called "sticky bit" so that files created in the directory in the future belong to the group so that group members will readily have access to them by default, and 306 | - [how to use *access control lists*](https://www.redhat.com/en/blog/linux-access-control-lists) to have more control over access. 307 | 308 | ## 5 Use simple text files when possible 309 | 310 | UNIX commands are designed as powerful tools to manipulate text files. This means that it's helpful to store information in information in text files when possible (of course there are very good reasons to store large datasets in binary files as well, in particular speed of access to portions of the data and efficient storage formats). 311 | 312 | Furthermore, the basic UNIX commands that operate on files operate on a line by line basis (e.g., `grep`, `sed`, `cut`, etc.). So using formats where each line contains a distinct set of information (such as CSVs) is advantageous even compared to other text formats where related information is stored on multiple lines (such as XML and JSON). 313 | 314 | ## 6 Document formats and conversion 315 | 316 | There are many plain text file formats (e.g., Markdown, 317 | reStructuredText, LaTeX). Pandoc is a widely used document converter. To 318 | convert a file written in markdown (`report.md`) to a PDF 319 | (`report.pdf`), you would do something like: 320 | 321 | $ pandoc -o report.pdf report.md 322 | 323 | For a quick introduction to LaTeX, please see our [Introduction to 324 | LaTeX tutorial and screencast](https://github.com/berkeley-scf/tutorial-latex-intro). 325 | -------------------------------------------------------------------------------- /file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-using-bash/b818e852ced6e0c5b620abef4352c56103c0a859/file.png -------------------------------------------------------------------------------- /index.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Using the bash (and zsh) shell 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | ## 1 This tutorial 18 | 19 | ::: {.callout-warning title="Prerequisite"} 20 | Before reading this, if you're not already comfortable with basic commands for working with files (e.g. `cd`, `ls`, `cp` and the structure of the filesystem on a UNIX-like machine), you will want to be familiar with the introductory material in our [Basics of UNIX tutorial](https://computing.stat.berkeley.edu/tutorial-unix-basics). 21 | ::: 22 | 23 | 24 | ### 1.1 Other resources 25 | 26 | Software Carpentry has a very nice introductory lesson on the [basics of the shell](https://swcarpentry.github.io/shell-novice/). It also has an accompanying [YouTube video](https://www.youtube.com/watch?v=8c1BL5b47kg) that covers some, but not all, of the topics of this tutorial. 27 | 28 | The book Research Software Engineering with Python has [several good in-depth chapters on the shell](https://third-bit.com/py-rse/bash-basics.html). 29 | 30 | ## 2 The interactive shell 31 | 32 | The shell is the UNIX program that provides an interactive computer programming environment. You use the shell when in a terminal window to interact with a UNIX-style operating system (e.g., Linux or MacOS). The shell sits between you and the operating system and provides useful commands and functionality. Basically, the shell is a program that serves to run other commands for you and show you the results. 33 | 34 | The shell is a read-evaluate-print loop (REPL) environment. R and 35 | Python also provide REPL environments. A REPL reads a single 36 | *expression* or input, parses and *evaluates* it, *prints* the results, 37 | and then *loops* (i.e., returns control to you to continue your work). 38 | 39 | ::: {.callout-note title="The shell prompt"} 40 | 41 | I will use a `$` prompt for bash. By convention, a regular 42 | user's prompt in bash is `$`, while the root (or administrative) 43 | user's prompt is `#`. However, it is common practice to never log on 44 | as the root user, even if you have root access. If you need to run a command with root privileges, 45 | you should use the `sudo` command. 46 | 47 | `$ echo "The current user is $USER."` 48 | 49 | `The current user is paciorek.` 50 | ::: 51 | 52 | When you are working in a terminal window (i.e., a window with the 53 | command line interface), you're interacting with a shell. 54 | There are actually different shells that you can use, of which `bash` is very common and is the default on many systems. In recent versions of MacOS, `zsh` is the default shell. There are others as well (e.g., *sh*, *csh*, *tcsh*, *fish*). I've generated this document based on using the bash shell on a computer running the Ubuntu Linux version 20.04 operating system, and this tutorial assumes you are using *bash* or *zsh*. That said, the basic ideas and the use of various commands are applicable to any UNIX shell, and you should be able to replicate most of the steps in this tutorial in other UNIX command line environments, with various substitutions of shell syntax specific to the shell you are using, 55 | 56 | The shell is an amazingly powerful programming environment. From it you 57 | can interactively monitor and control almost any aspect of the OS and 58 | more importantly you can automate it. As you will see, *bash* has a 59 | very extensive set of capabilities intended to make both interactive as 60 | well as automated control simple, effective, and customizable. 61 | 62 | ::: {.callout-warning} 63 | 64 | It can be difficult to distinguish what is shell-specific and what is 65 | just part of UNIX. Some of the material in this tutorial is not bash-specific but is 66 | general to UNIX. 67 | 68 | Reference: Newham and Rosenblatt, Learning the bash Shell, 2nd ed. 69 | ::: 70 | 71 | ::: {.callout-warning title="The shell on a Mac"} 72 | 73 | Unfortunately, the behavior of shell commands on a Mac can be 74 | [somewhat different](https://ponderthebits.com/2017/01/know-your-tools-linux-gnu-vs-mac-bsd-command-line-utilities-grep-strings-sed-and-find) 75 | than on Linux (e.g., on a Mac, one can't do `tail -n +5`) because MacOS is based on 76 | BSD, which is not a Linux distribution. The behavior of the commands is distinct from the shell you are using. 77 | ::: 78 | 79 | 80 | ## 3 Accessing the shell 81 | 82 | This tutorial assumes you already have access to a basic bash shell on a computer 83 | with network access (e.g., the Terminal on a Mac, the Ubuntu subsystem on Windows, or a terminal window on a Linux machine), as discussed in our [Basics of UNIX tutorial](https://berkeley-scf.github.io/tutorial-unix-basics#1.3-accessing-a-unix-command-line-interface). 84 | 85 | Here's how you can see your default shell and change it if you like. 86 | 87 | 1. What is my default shell? 88 | 89 | ```bash 90 | $ echo $SHELL 91 | /bin/bash 92 | ``` 93 | 94 | 2. To change to bash on a one-time basis: 95 | 96 | ```bash 97 | $ bash 98 | ``` 99 | 100 | 3. To make it your default: 101 | 102 | ```bash 103 | $ chsh /bin/bash 104 | ``` 105 | 106 | In the last example, `/bin/bash` should be whatever the path to the bash 107 | shell is, which you can figure out using: 108 | 109 | ```bash 110 | $ type bash 111 | bash is /usr/bin/bash 112 | ``` 113 | 114 | 115 | 116 | ## 4 Variables 117 | 118 | ### 4.1 Using variables 119 | 120 | Just like programming languages, you can use variables in the shell. 121 | Variables are names that have values assigned to them. 122 | 123 | To access the value currently assigned to a variable, you can prepend the name with 124 | the dollar sign (\$). To print the value you can use the `echo` command. 125 | 126 | For example, I can find the username of the current user in the `USER` variable: 127 | 128 | ```bash 129 | $ echo $USER 130 | paciorek 131 | ``` 132 | 133 | To declare a variable, just assign a value to the name, without using `$`. For 134 | example, if you want to make a new variable with the name `counter` with 135 | the value `1`: 136 | 137 | ```bash 138 | $ counter=1 139 | ``` 140 | 141 | Since bash uses spaces to parse the expression you give it as input, it 142 | is important to note the lack of spaces around the equal sign. Try 143 | typing the command with and without spaces and note what happens. 144 | 145 | You can also enclose the variable name in curly brackets, which comes in 146 | handy when you're embedding a variable within a line of code, to make 147 | sure the shell knows where the variable name ends: 148 | 149 | ```bash 150 | $ base=/home/jarrod/ 151 | $ echo ${base}src 152 | $ echo $basesrc 153 | ``` 154 | 155 | Make sure you understand the difference in behavior in the last two 156 | lines. 157 | 158 | ### 4.2 Environment variables 159 | 160 | There are also special shell variables called environment variables that 161 | help to control the shell's behavior. These are generally named in all 162 | caps. Type `printenv` to see them. You can create your own environment 163 | variable as follows: 164 | 165 | ```bash 166 | $ export base=/home/jarrod/ 167 | ``` 168 | 169 | The `export` command ensures that other shells created by the current 170 | shell (for example, to run a program) will inherit the variable. Without 171 | the export command, any shell variables that are set will only be 172 | modified within the current shell. More generally, if you want a 173 | variable to always be accessible, you should include the definition of 174 | the variable with an `export` command in your `.bashrc` file. 175 | 176 | You can control the appearance of the bash prompt using the `PS1` 177 | variable: 178 | 179 | ```bash 180 | $ echo $PS1 181 | ``` 182 | 183 | To modify it so that it puts the username, hostname, and current working 184 | directory in the prompt: 185 | 186 | ```bash 187 | $ export PS1='[\u@\h \W]\$ ' 188 | [user1@local1 ~]$ 189 | ``` 190 | 191 | ## 5 Introduction to commands 192 | 193 | ### 5.1 Elements of a command 194 | 195 | While each command has its own syntax, there are some rules usually 196 | followed. Generally, a command line consists of 4 things: a command, 197 | command options, arguments, and line acceptance. Consider the following 198 | example: 199 | 200 | ```bash 201 | $ ls -l file.txt 202 | ``` 203 | In the above example, `ls` is the command, `-l` is a command option 204 | specifying to use the long format, `file.txt` is the argument, and the 205 | line acceptance is indicated by hitting the `Enter` key at the end of 206 | the line. 207 | 208 | After you type a command at the bash prompt and indicate line acceptance 209 | with the `Enter` key, bash parses the command and then attempts to 210 | execute the command. To determine what to do, bash first checks whether 211 | the command is a shell function (we will discuss functions below). If 212 | not, it checks to see whether it is a builtin. Finally, if the command 213 | is not a shell function nor a builtin, bash uses the `PATH` variable. 214 | The `PATH` variable is a list of directories: 215 | 216 | ```bash 217 | $ echo $PATH 218 | /home/jarrod/usr/bin:/usr/local/bin:/bin:/usr/bin: 219 | ``` 220 | 221 | For example, consider the following command: 222 | 223 | ```bash 224 | $ grep pdf file.txt 225 | ``` 226 | 227 | We will discuss `grep` later. For now, let's ignore what `grep` actually 228 | does and focus on what bash would do when you press enter after typing 229 | the above command. First bash checks whether `grep` a shell function or 230 | a builtin. Once it determines that `grep` is neither a shell function 231 | nor a builtin, it will look for an executable file named `grep` first in 232 | `/home/jarrod/usr/bin`, then in `/usr/local/bin`, and so on until it 233 | finds a match or runs out of places to look. You can use `type` to find 234 | out where bash would find it: 235 | 236 | ```bash 237 | $ type grep 238 | grep is hashed (/usr/bin/grep) 239 | ``` 240 | 241 | Also note that the shell substitutes in the values of variables and 242 | does other manipulations before calling the command. For example in the following 243 | example, 244 | 245 | ```bash 246 | $ myfile=file.txt 247 | $ grep pdf $myfile 248 | ``` 249 | 250 | the value of `$myfile` is substituted in before `grep` is called, so the command 251 | that is executed is `grep pdf myfile.txt`. 252 | 253 | ### 5.2 Getting help with commands 254 | 255 | Most bash commands have electronic manual pages, which are accessible 256 | directly from the commandline. You will be more efficient and 257 | effective if you become accustomed to using these `man` pages. To view 258 | the `man` page for the command `sudo`, for instance, you would type: 259 | 260 | ```bash 261 | $ man ls 262 | ``` 263 | 264 | Alternatively, for many commands you can use the `--help` flag: 265 | 266 | ```bash 267 | $ ls --help 268 | ``` 269 | 270 | ::: {.callout-tip title="Exercise"} 271 | 272 | Consider the following examples using the `ls` command: 273 | 274 | ```bash 275 | $ ls --all -l 276 | $ ls -a -l 277 | $ ls -al 278 | ``` 279 | 280 | Use `man ls` to see what the command options do. Is there any difference 281 | in what the three versions of the command invocation above return as the 282 | result? What happens if you add a filename to the end of the command? 283 | ::: 284 | 285 | ## 6 Operating efficiently at the command line 286 | 287 | ### 6.1 Tab completion 288 | 289 | When working in the shell, it is often unnecessary to type out an entire 290 | command or file name, because of a feature known as tab completion. When 291 | you are entering a command or filename in the shell, you can, at any 292 | time, hit the tab key, and the shell will try to figure out how to 293 | complete the name of the command or filename you are typing. If there is 294 | only one such command found in the search path and you're using tab completion with 295 | the first token of a line, then the shell will display its value and the 296 | cursor will be one space past the completed name. If there are multiple 297 | commands that match the partial name, the shell will display as much as 298 | it can. In this case, hitting tab twice will display a list of choices, 299 | and redisplay the partial command line for further editing. Similar 300 | behavior with regard to filenames occurs when tab completion is used on 301 | anything other than the first token of a command. 302 | 303 | ::: {.callout-tip title="Tab completion in Python and R"} 304 | 305 | R and Python also provide tab completions for objects (including functions) and 306 | (in some cases) filenames. 307 | ::: 308 | 309 | ### 6.2 Keyboard shortcuts 310 | 311 | 312 | Note that you can use emacs-like control sequences (`Ctrl-a`, `Ctrl-e`, 313 | `Ctrl-k`) to navigate and delete characters. 314 | 315 | **Table. Keyboard Shortcuts** 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 |
Key StrokesDescriptions
Ctrl-aBeginning of line
Ctrl-eEnd of line
Ctrl-kDelete line from cursor forward
Ctrl-wDelete word before cursor
Ctrl-ypastes in whatever was deleted previously with Ctrl-k or Ctrl-w
ESC-FForward one word
ESC-BBackwards one word
Ctrl-dEOF; exit
Ctrl-cInterrupt current command
Ctrl-zSuspend current command
Ctrl-lClear screen
Ctrl-rEnables an interactive search history
375 | 376 | ### 6.3 Command History and Editing 377 | 378 | By using the up and down arrows, you can scroll through commands that 379 | you have entered previously. So if you want to rerun the same command, 380 | or fix a typo in a command you entered, just scroll up to it and hit 381 | enter to run it or edit the line and then hit enter. 382 | 383 | To list the history of the commands you entered, use the `history` 384 | command: 385 | 386 | ```bash 387 | $ history 388 | ``` 389 | ``` 390 | 1 echo $PS1 391 | 2 PS1=$ 392 | 3 bash 393 | 4 export PS1=$ 394 | 5 bash 395 | 6 echo $PATH 396 | 7 which echo 397 | 8 ls --all -l 398 | 9 ls -a -l 399 | 10 ls -al 400 | 11 ls -al manual.xml 401 | ``` 402 | 403 | The behavior of the `history` command is controlled by a shell 404 | variables: 405 | 406 | ```bash 407 | $ echo $HISTFILE 408 | $ echo $HISTSIZE 409 | ``` 410 | You can also rerun previous commands as follows: 411 | 412 | ```bash 413 | $ !-n 414 | $ !gi 415 | ``` 416 | 417 | The first example runs the nth previous command and the second one runs 418 | the last command that started with 'gi'. 419 | 420 | **Table. Command History Expansion** 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 |
DesignatorDescription
!!Last command
!nCommand numbered n in the history
!-nCommand n previous
!stringLast command starting with string
!?stringLast command containing string
^string1^string2Execute the previous command with string2 substituted for string1
456 | 457 | If you're not sure what command you're going to recall, you can append 458 | `:p` at the end of the text you type to do the recall, and the result 459 | will be printed, but not executed. For example: 460 | 461 | ```bash 462 | $ !gi:p 463 | ``` 464 | 465 | You can then use the up arrow key to bring back that statement for 466 | editing or execution. 467 | 468 | You can also search for commands by doing `Ctrl-r` and typing a string 469 | of characters to search for in the search history. You can hit return to 470 | submit, `Ctrl-c` to get out, or `ESC` to put the result on the regular 471 | command line for editing. 472 | 473 | ## 7 Accessing remote machines 474 | 475 | You likely already have `ssh` installed. SSH provides an 476 | encrypted mechanism to connect to a remote Unix-based (i.e., Linux or Mac) terminal. You can [learn more 477 | about using ssh on various operating systems](https://statistics.berkeley.edu/computing/ssh). 478 | 479 | To ssh to another machine, you need to know its (host)name. For example, 480 | to ssh to `arwen.berkeley.edu`, one of the SCF machines, you would: 481 | 482 | ```bash 483 | $ ssh arwen.berkeley.edu 484 | Password: 485 | ``` 486 | 487 | At this point you have to type your password. Alternatively, you can [set 488 | up ssh so that you can use it without typing your password](https://statistics.berkeley.edu/computing/ssh-keys). 489 | 490 | If you have a different username on the remote machine than on the machine you are on, you will need to 491 | specify it as well. For example, to specify the username `jarrod`, you 492 | would: 493 | 494 | ```bash 495 | $ ssh jarrod@arwen.berkeley.edu 496 | ``` 497 | 498 | If you want to view graphical applications on your local computer that 499 | are running on the remote computer you need to use the `-X` option: 500 | 501 | ```bash 502 | $ ssh -X jarrod@arwen.berkeley.edu 503 | ``` 504 | 505 | Alternatively, if you want to copy a file (`file1.txt`) from your local 506 | computer to `arwen.berkeley.edu`, you can use the `scp` command, 507 | which securely copies files between machines: 508 | 509 | ```bash 510 | $ scp file1.txt jarrod@arwen.berkeley.edu:. 511 | ``` 512 | The above command will copy `file1.txt` from my current working 513 | directory on my local machine to `jarrod`'s home directory on 514 | `arwen.berkeley.edu`. The `.` following the `:` indicates that I want 515 | to copy the file to jarrod's home directory on the remote machine, 516 | keeping the file name as it is. I could 517 | also replace `.` with any relative path from jarrod's home directory on the 518 | remote machine or I could use an absolute path. 519 | 520 | To copy a file (`file2.txt`) from `arwen.berkeley.edu` to my local 521 | machine: 522 | 523 | ```bash 524 | $ scp jarrod@arwen.berkeley.edu:file2.txt . 525 | ``` 526 | 527 | I can even copy a file (`file3.txt`) owned by one user (`jarrod`) on one 528 | remote machine `arwen.berkeley.edu` to the account of another user 529 | (`jmillman`) on another remote machine `scf-ug02.berkeley.edu`: 530 | 531 | ```bash 532 | $ scp jarrod@arwen.berkeley.edu:file3.txt jmillman@arwen.berkeley.edu:. 533 | ``` 534 | If instead of copying a single file, I wanted to copy an entire 535 | directory (`src`) from one machine to another, I would use the `-r` 536 | option: 537 | 538 | ```bash 539 | $ scp -r src jmillman@arwen.berkeley.edu:. 540 | ``` 541 | 542 | Regardless of whether you are working on a local computer or a remote 543 | one, it is occasionally useful to operate as a different user. For 544 | instance, you may need root (or administrative) access to change file 545 | permissions or install software. (Note this will only be possible 546 | on machines that you own or have special privileges on. The Ubuntu 547 | Subsystem on Windows is one way to have a virtual Linux machine 548 | for which you have root access.) 549 | 550 | For example on an Ubuntu Linux machine (including the Ubuntu Subsystem on Windows), 551 | here's how you can act as the 'root' user to update or add software 552 | on machines where you have administrative access: 553 | 554 | To upgrade all the software on the machine: 555 | 556 | ```bash 557 | $ sudo apt-get upgrade 558 | ``` 559 | 560 | To install the text editor vim on the machine: 561 | 562 | ```bash 563 | $ sudo apt-get install vim 564 | ``` 565 | -------------------------------------------------------------------------------- /license.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: License 3 | --- 4 | 5 | Creative Commons License
This work (by Christopher Paciorek and Jarrod Millman) is licensed under a Creative Commons Attribution 4.0 International License. 6 | 7 | -------------------------------------------------------------------------------- /ls_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-using-bash/b818e852ced6e0c5b620abef4352c56103c0a859/ls_format.png -------------------------------------------------------------------------------- /managing-processes.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Managing processes 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | A process is a program that is being executed. Processes have the 18 | following attributes: 19 | 20 | - A lifetime. 21 | - A process ID (PID). 22 | - A user ID (UID). 23 | - A group ID (GID). 24 | - A parent process with its own ID (PPID). 25 | - An environment. 26 | - A current working directory. 27 | 28 | Anytime you do something on the computer, one or more processes will 29 | start up to carry out the activity. 30 | 31 | ## 1 Monitoring 32 | 33 | ### 1.1 Monitoring processes 34 | 35 | #### Using `ps` 36 | 37 | Examining subprocesses of your shell with `ps`: 38 | 39 | ```bash 40 | $ ps 41 | PID TTY TIME CMD 42 | 19370 pts/3 00:00:00 bash 43 | 22846 pts/3 00:00:00 ps 44 | ``` 45 | 46 | Examining in more detail subprocesses of your shell with `ps`: 47 | 48 | ```bash 49 | $ ps -f 50 | UID PID PPID C STIME TTY TIME CMD 51 | jarrod 19370 19368 0 10:51 pts/3 00:00:00 bash 52 | jarrod 22850 19370 0 14:57 pts/3 00:00:00 ps -f 53 | ``` 54 | 55 | Examining in more detail all processes on your computer: 56 | 57 | ```bash 58 | $ ps -ef 59 | UID PID PPID C STIME TTY TIME CMD 60 | root 1 0 0 Aug21 ? 00:00:05 /usr/lib/systemd 61 | root 2 0 0 Aug21 ? 00:00:00 [kthreadd] 62 | root 3 2 0 Aug21 ? 00:00:07 [ksoftirqd/0] 63 | root 5 2 0 Aug21 ? 00:00:00 [kworker/0:0H] 64 | 65 | root 16210 1 0 07:19 ? 00:00:00 login -- jarrod 66 | jarrod 16219 16210 0 07:19 tty1 00:00:00 -bash 67 | jarrod 16361 16219 0 07:19 tty1 00:00:00 /bin/sh /bin/startx 68 | 69 | ``` 70 | 71 | You can use the `-u` option to see percent CPU and percent memory used 72 | by each process. You can use the `-o` option to provide your own 73 | user-defined format; for example, : 74 | 75 | 76 | ```bash 77 | $ ps -o pid,ni,pcpu,pmem,user,comm 78 | PID NI %CPU %MEM USER COMMAND 79 | 18124 0 0.0 0.0 jarrod bash 80 | 22963 0 0.0 0.0 jarrod ps 81 | ``` 82 | 83 | To see the hierarchical process structure (i.e., which processes started which other processes), you can use the `pstree` 84 | command. 85 | 86 | #### Using `top` 87 | 88 | Examining processes with `top`: 89 | 90 | ```bash 91 | $ top 92 | top - 13:49:07 up 1:49, 3 users, load average: 0.10, 0.15, 0.18 93 | Tasks: 160 total, 1 running, 158 sleeping, 1 stopped, 0 zombie 94 | %Cpu(s): 2.5 us, 0.5 sy, 0.0 ni, 96.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st 95 | KiB Mem : 7893644 total, 5951552 free, 1085584 used, 856508 buff/cache 96 | KiB Swap: 7897084 total, 7897084 free, 0 used. 6561548 avail Mem 97 | 98 | PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 99 | 1607 jarrod 20 0 2333568 974888 212944 S 12.5 12.4 11:10.67 firefox 100 | 3366 jarrod 20 0 159828 4312 3624 R 6.2 0.1 0:00.01 top 101 | 1 root 20 0 193892 8484 5636 S 0.0 0.1 0:01.78 systemd 102 | 103 | ``` 104 | 105 | The first few lines show general information about the machine, while 106 | the remaining lines show information for each process. 107 | 108 | - The `RES` column indicates the amount of memory that a process is 109 | using (in bytes, if not otherwise indicated). 110 | - The `%MEM` shows that memory use relative to the physical memory available on the 111 | computer. 112 | - The `%CPU` column shows the proportion of a CPU core that 113 | the process is using (which can exceed 100% if a process is 114 | threaded). 115 | - The `TIME+` column shows the amount of time the process has 116 | been running. 117 | 118 | To quit `top`, type `q`. 119 | 120 | You can also kill jobs (see below for further details on 121 | killing jobs) from within top: just type `r` or `k`, 122 | respectively, and proceed from there. 123 | 124 | ### 1.2 Monitoring memory use 125 | 126 | One of the main things to watch out for is a job that is using close to 127 | 100% of memory and much less than 100% of CPU. What is generally 128 | happening is that your program has run out of memory and is using 129 | virtual memory on disk, spending most of its time writing to/from disk, 130 | sometimes called *paging* or *swapping*. If this happens, it can be a 131 | very long time, if ever, before your job finishes. 132 | 133 | Note that the per-process memory use reported by `top` and `ps` may "double count" 134 | memory that is being used simultaneously by multiple processes. To see the total 135 | amount of memory actually available on a machine: 136 | 137 | ```bash 138 | $ free -h 139 | total used free shared buff/cache available 140 | Mem: 251G 998M 221G 2.6G 29G 247G 141 | Swap: 7.6G 210M 7.4G 142 | ``` 143 | 144 | You'll generally be interested in the `Memory` row and in the `total`, `used` and `available` columns. 145 | The `free` column can be confusing and [does not actually indicate how much memory is still available 146 | to be used](https://berkeley-scf.github.io/tutorial-databases/db-management#52-memory), 147 | so you'll want to focus on the `available` column. 148 | 149 | 150 | ## 2 Job Control 151 | 152 | ### 2.1 Foreground and background jobs 153 | 154 | When you run a command in a shell by simply typing its name, you are 155 | said to be running in the foreground. When a job is running in the 156 | foreground, you can't type additional commands into that shell session, 157 | but there are two signals that can be sent to the running job through 158 | the keyboard. To interrupt a program running in the foreground, use 159 | `Ctrl-c`; to quit a program, use `Ctrl-\`. While modern windowed systems 160 | have lessened the inconvenience of tying up a shell with foreground 161 | processes, there are some situations where running in the foreground is 162 | not adequate. 163 | 164 | The primary need for an alternative to foreground processing arises when 165 | you wish to have jobs continue to run after you log off the computer. In 166 | cases like this you can run a program in the background by simply 167 | terminating the command with an ampersand (`&`). However, before putting 168 | a job in the background, you should consider how you will access its 169 | results, since *stdout* is not preserved when you log off from the 170 | computer. Thus, redirection (including redirection of *stderr*) is 171 | essential when running jobs in the background. As a simple example, 172 | suppose that you wish to run a Python script, and you don't want it to 173 | terminate when you log off. 174 | 175 | ```bash 176 | $ python code.py > code.pyout 2>&1 & 177 | ``` 178 | 179 | What does the inscrutable `2>&1` do? Recall from [earlier](using-commands.html#overview-of-redirection) that it says to send *stderr* to the same 180 | place as *stdout*, which in this case has been redirected to `code.pyout`. 181 | 182 | If you forget to put a job in the background when you first execute it, 183 | you can do it while it's running in the foreground in two steps. First, 184 | suspend the job using the `Ctrl-z` signal. After receiving the signal, 185 | the program will interrupt execution, but it will still have access to all 186 | files and other resources. Next, issue the `bg` command, which will 187 | start the stopped job running in the background. 188 | 189 | ### 2.2 Listing and killing jobs 190 | 191 | Since only foreground jobs will accept signals through the keyboard, if 192 | you want to terminate a background job you must first determine the 193 | unique process id (PID) for the process you wish to terminate through 194 | either `ps` or `top`. Here we'll illustrate use of `ps` again. 195 | 196 | To see all processes owned by a specific user (e.g., `jarrod`), I can 197 | use the `-U jarrod` option: 198 | 199 | ```bash 200 | $ ps -U jarrod 201 | ``` 202 | 203 | If I want to get more information (e.g., `%CPU` and `%MEM`), I can use 204 | add the `-u` option: 205 | 206 | ```bash 207 | $ ps -U jarrod -u 208 | USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 209 | jarrod 16116 12.0 6.0 118804 5080 tty1 Ss 16:25 133:01 python 210 | ``` 211 | 212 | In this example, the `ps` output tells us that this python job has a PID 213 | of `16116`, that it has been running for 133 minutes, is using 12% of 214 | CPU and 6% of memory, and that it started at 16:25. You could then issue 215 | the command: 216 | 217 | ```bash 218 | $ kill 16116 219 | ``` 220 | 221 | or, if that doesn't work: 222 | 223 | ```bash 224 | $ kill -9 16116 225 | ``` 226 | 227 | to terminate the job. Another useful command in this regard is 228 | `killall`, which accepts a program name instead of a process id, and 229 | will kill all instances of the named program (in this case, R): 230 | 231 | ```bash 232 | $ killall R 233 | ``` 234 | 235 | Of course, it will only kill the jobs that belong to you, so it will not 236 | affect the jobs of other users. Note that the `ps` and `kill` commands 237 | only apply to the particular computer on which they are executed, not to 238 | the entire computer network. Thus, if you start a job on one machine, 239 | you must log back into that same machine in order to manage your job. 240 | 241 | Finally, let's see how to build up a command to kill firefox using some of the 242 | tools we've seen. First let's pipe the output of `ps -e` to `grep` to 243 | select the line corresponding to `firefox`: 244 | 245 | ```bash 246 | $ ps -e | grep firefox 247 | 16517 ? 00:10:03 firefox 248 | ``` 249 | 250 | We can now use `awk` to select the first column, which contains the 251 | process ID corresponding to `firefox`: 252 | 253 | ```bash 254 | $ ps -e | grep firefox | awk '{ print $1 }' 255 | 16517 256 | ``` 257 | 258 | Finally, we can pipe this to the `kill` command using `xargs` or 259 | command substitution: 260 | 261 | ```bash 262 | $ ps -e | grep firefox | awk '{ print $1 }' | xargs kill 263 | $ kill $(ps -e | grep firefox | awk '{ print $1 }') 264 | ``` 265 | 266 | As mentioned before, we can't pipe the PID directly to `kill` because 267 | `kill` takes the PID(s) as argument(s) rather than reading them from stdin. 268 | 269 | 270 | ## 3 Screen 271 | 272 | Screen allows you to create *virtual terminals*, which are not connected 273 | to your actual terminal or shell. This allows you to run multiple 274 | programs from the command line and leave them all in the foreground in 275 | their own virtual terminal. Screen provides facilities for managing 276 | several virtual terminals including: 277 | 278 | - listing them, 279 | - switching between them, and 280 | - disconnecting from one machine and then reconnecting to an existing virtual terminal from another. 281 | 282 | While we will only discuss its basic operation, we will cover enough to 283 | be of regular use. 284 | 285 | `tmux` is an alternative to `screen`. 286 | 287 | Calling screen: 288 | 289 | ```bash 290 | $ screen 291 | ``` 292 | 293 | will open a single window and you will see a new bash prompt. You just 294 | work at this prompt as you normally would. The difference is that you 295 | can disconnect from this window by typing `Ctrl-a d` and you will see 296 | something like this : 297 | 298 | ```bash 299 | $ screen 300 | [detached from 23974.pts-2.t430u] 301 | ``` 302 | 303 | ::: {.callout-tip title="Screen commands"} 304 | 305 | All the screen key commands begin with the control key combination 306 | `Ctrl-a` followed by another key. For instance, when you are in a 307 | screen session and type `Ctrl-a ?`, screen will display a help screen 308 | with a list of its keybindings. 309 | 310 | ::: 311 | 312 | You can now list your screen sessions : 313 | 314 | ```bash 315 | $ screen -ls 316 | There is a screen on: 317 | 23974.pts-2.t430u (Detached) 318 | ``` 319 | 320 | To reconnect : 321 | 322 | ```bash 323 | $ screen -r 324 | ``` 325 | 326 | You can start multiple screen sessions. This is what it might look like 327 | if you have 3 screen sessions: 328 | 329 | ```bash 330 | $ screen -ls 331 | There are screens on: 332 | 24274.pts-2.t430u (Attached) 333 | 24216.pts-2.t430u (Detached) 334 | 24158.pts-2.t430u (Detached) 335 | ``` 336 | 337 | with the first session active on a machine. 338 | 339 | To specify that you want to reattach to session `24158.pts-2.t430u`, 340 | type: 341 | 342 | ```bash 343 | $ screen -r 24158.pts-2.t430u 344 | ``` 345 | 346 | If you have several screen sessions, you will want to name your screen 347 | session something more informative than `24158.pts-2.t430u`. To name a 348 | screen session `gene-analysis` you can use the `-S` option when calling 349 | screen: 350 | 351 | ```bash 352 | $ screen -S gene-analysis 353 | ``` 354 | 355 | While there are many more features and keybindings available for screen, 356 | you've already seen enough screen to be useful. For example, imagine you 357 | ssh to a remote machine from your laptop to run an analysis. The first 358 | thing you do at the bash prompt on the remote machine is: 359 | 360 | ```bash 361 | $ screen -S dbox-study 362 | ``` 363 | 364 | Then you start your analysis script `dbox-analysis.py` running: 365 | 366 | ```bash 367 | $ dbox-analysis.py 368 | Starting statistical analysis ... 369 | Processing subject 1 ... 370 | Processing subject 2 ... 371 | ``` 372 | 373 | If your study has 50 subjects and processing each subject takes 20 374 | minutes, you will not want to sit there watching your monitor. So you 375 | use `Ctrl-a d` to detach the session and you will then see: 376 | 377 | ```bash 378 | $ screen -S dbox-study 379 | [detached from 2799.dbox-study] 380 | $ 381 | ``` 382 | 383 | Now you can log off your laptop and go home. Sometime after dinner, you 384 | decide to check on your job. So you ssh from your home computer to the 385 | remote machine again and type the following at the bash prompt: 386 | 387 | ```bash 388 | $ screen -r dbox-study 389 | ``` 390 | 391 | You should then be able to see the progress of your analysis script, 392 | as if you had kept a terminal open the whole time. 393 | -------------------------------------------------------------------------------- /regex.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Regular expressions 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | Regular expressions (regex) are a domain-specific language for finding 18 | patterns and are one of the key functionalities in scripting languages 19 | such as Python, as well as the UNIX utilities `sed`, `awk`, and 20 | `grep`. We'll just cover the basic use of regular 21 | expressions in bash, but once you know that, it would be easy to use 22 | them elsewhere (Python, R, etc.). At the level we'll consider them, the 23 | syntax is quite similar. 24 | 25 | ::: {.callout-important title="Different types of regular expressions"} 26 | 27 | POSIX.2 regular expressions come in two flavors: extended regular 28 | expressions and basic (or obsolete) regular expressions. The extended 29 | syntax has metacharacters `()` and `{}`, while the basic syntax 30 | requires the metacharacters to be designated `\(\)` and `\{\}`. 31 | In addition to the POSIX standard, Perl regular expressions are also 32 | widely used. While we won't go into detail, we will see some examples 33 | of each syntax. In the examples that follow we'll generally use the 34 | extended syntax by using the `-E` flag to `grep`. 35 | ::: 36 | 37 | ## 1 Overview and core syntax 38 | 39 | The basic idea of regular expressions is that they allow us to find 40 | matches of strings or patterns in strings, as well as do substitution. 41 | Regular expressions are good for tasks such as: 42 | 43 | - extracting pieces of text - for example finding all the phone 44 | numbers in a document; 45 | - creating variables from information found in text; 46 | - cleaning and transforming text into a uniform format; 47 | - mining text by treating documents as data; and 48 | - scraping the web for data. 49 | 50 | Regular expressions are constructed from three things: 51 | 52 | 1. *Literal characters* are matched only by the characters themselves, 53 | 2. *Character classes* are matched by any single member in the class, 54 | and 55 | 3. *Modifiers* operate on either of the above or combinations of them. 56 | 57 | Note that the syntax is very concise, so it's helpful to break down 58 | individual regular expressions into the component parts to understand 59 | them. Since regex are their own language, it's a good idea to build up a 60 | regex in pieces as a way of avoiding errors just as we would with any 61 | computer code. You'll also want to test your regex on examples, for which 62 | this [online testing tool](https://regex101.com) is helpful. 63 | 64 | It is also helpful to search for common regex online 65 | before trying to craft your own. For instance, if you wanted to use a 66 | regex that matches valid email addresses, you would need to match 67 | anything that complies with the [RFC 68 | 822](http://www.ietf.org/rfc/rfc0822.txt?number=822) grammar. If you 69 | look over that document, you will quickly realize that implementing a 70 | correct regular expression to validate email addresses is extremely 71 | complex. So if you are writing a website that validates email addresses, 72 | it is best to look for a bug-vetted implementation rather than creating 73 | your own. 74 | 75 | The special characters (meta-characters) used for defining regular 76 | expressions are: 77 | 78 | * . ^ $ + ? ( ) [ ] { } | \ 79 | 80 | To use these characters literally as characters, we have to 'escape' 81 | them. In bash, you escape these characters by placing a single backslash 82 | before the character you want to escape. In R, we have to use two 83 | backslashes instead of a single backslash because R uses a single 84 | backslash to symbolize certain control characters, such as `\n` for 85 | newline. 86 | 87 | To learn more about regular expressions, you can type: 88 | 89 | ```bash 90 | $ man 7 regex 91 | ``` 92 | 93 | ## 2 Character sets and character classes 94 | 95 | We can use character sets to match any of the characters in a set. 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 |
OperatorsDescription
[abc]Match any single character from from the listed characters
[a-z]Match any single character from the range of characters
[^abc]Match any single character not among listed characters
[^a-z]Match any single character not among listed range of characters
.Match any single character except a newline
\Turn off (escape) the special meaning of a metacharacter
131 | 132 | If we want to search for any one of a set of characters, we use a 133 | character set, such as `[13579]` or `[abcd]` or `[0-9]` (where the dash 134 | indicates a sequence) or `[0-9a-z]`. To indicate any character not in a 135 | set, we place a `^` just inside the first bracket: `[^abcd]`. 136 | 137 | Here's an example of using regex with `grep` to find all lines in `test.txt` that 138 | contain at least one numeric digit. 139 | 140 | ```bash 141 | $ grep -E [0-9] test.txt 142 | ``` 143 | 144 | or with the `-o` flag to find and return only the actual digits 145 | 146 | ```bash 147 | $ grep -E -o [0-9] test.txt 148 | ``` 149 | 150 | There are a bunch of named character classes so that we don't have write 151 | out common sets of characters. The syntax is `[:CLASS:]` where `CLASS` 152 | is one of the following values: 153 | 154 | "alnum", "alpha", "ascii", "blank", "cntrl", "digit", "graph", 155 | "lower", "print", "punct", "space", "upper", "word" or "xdigit". 156 | 157 | So to find any line that contains a punctuation symbol: 158 | 159 | ```bash 160 | $ grep -E [[:punct:]] test.txt 161 | ``` 162 | 163 | Note that to make a character set with a character class you need two square 164 | brackets, e.g., with the digit class: `[[:digit:]]`. Or we can make a combined 165 | character set such as `[[:alnum:]_]` (to find any alphabetic or 166 | numeric characters or an underscore). 167 | Or here, any line with a digit, a period, or a comma. 168 | 169 | ```bash 170 | $ grep -E [[:digit:].,] test.txt 171 | ``` 172 | 173 | Interestingly, we don't need to escape the period or comma inside the 174 | character set, despite both of them being meta-characters. 175 | 176 | 177 | ## 3 Location-specific matches 178 | 179 | We can use position anchors to make location-specific matches. 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 |
OperatorsDescription
^Match the beginning of a line.
$Match the end of a line.
199 | 200 | To find a pattern at the beginning of the string, we use `^` (note this 201 | was also used for negation, but in that case occurs only inside square 202 | brackets) and to find it at the end we use `$`. 203 | 204 | Here we'll search for lines that start with a digit and for lines that 205 | end with a digit. 206 | 207 | ```bash 208 | $ grep -E ^[0-9] test.txt 209 | $ grep -E [0-9]$ test.txt 210 | ``` 211 | 212 | ## 4 Repetitions, Grouping, and References 213 | 214 | Now suppose I wanted to be able to detect phone numbers, email 215 | addresses, etc. I often need to be able to deal with repetitions of 216 | characters or character sets. 217 | 218 | **Modifiers** 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 245 | 246 | 247 | 248 | 249 | 250 | 251 |
OperatorsDescription
*Match zero or more instances of the preceding character or regex.
?Match zero or one instance of the preceding character or regex.
+Match one or more instances of the preceding character or regex.
{n,m}Match a range of occurrences (at least n, no more 243 | than m) of preceding character 244 | of regex.
|Match the character or expression to the left or right of the vertical bar.
252 | 253 | Here are some examples of repetitions: 254 | 255 | - `[[:digit:]]*` : any number of digits (zero or more) 256 | - `[[:digit:]]+` : at least one digit 257 | - `[[:digit:]]?` : zero or one digits 258 | - `[[:digit:]]{1,3}` : at least one and no more than three digits 259 | - `[[:digit:]]{2,}` : two or more digits 260 | 261 | Another example is that `\[.*\]` is the pattern of closed square brackets 262 | with any number of characters (`.*`) inside: 263 | 264 | ```bash 265 | $ grep -E "\[.*\]" test.txt 266 | ``` 267 | 268 | Note that the quotations ensured that the backslashes are passed into 269 | grep and not simply interpreted by the shell, while the `\` is needed 270 | so that `[` and `]` are treated as simple characters since they are 271 | meta-characters in the regex syntax. 272 | 273 | As shown above, we can use `|` to mean "or". For example, to match one or 274 | more occurrences of "http" or "ftp": 275 | 276 | 277 | ```bash 278 | $ grep -E -o "(http|ftp)" test.txt 279 | ``` 280 | 281 | Parentheses are also used with a pipe (`|`) when working with 282 | multi-character sequences, such as `(http|ftp)`. Also, here we need double 283 | quotes or the shell tries to interpret the `(` as part of the regular 284 | expression and not shell syntax. 285 | 286 | Next let's see the use of repitition to look for more complicated multi-character patterns. For 287 | example, if you wanted to match phone numbers whether they start with 288 | `1-` or not you could use the following: 289 | 290 | (1-)?[[:digit:]]{3}-[[:digit:]]{3}-[[:digit:]]{4} 291 | 292 | The first part of the pattern `(1-)?` matches 0 or 1 occurrences of 293 | `1-`. Then the pattern `[[:digit:]]{3}` matches any 3 digits. Similarly, 294 | the pattern `[[:digit:]]{4}` matches any 4 digits. So the whole pattern 295 | matches any three digits followed by `-`, then another three digits, and then followed by four 296 | digits when it is preceded by 0 or 1 occurrences of `1-`. 297 | 298 | Now let's consider a file named `file2.txt` with the following content: 299 | 300 | ``` 301 | Here is my number: 919-543-3300. 302 | hi John, good to meet you 303 | They bought 731 bananas 304 | Please call 1.919.554.3800 305 | I think he said it was 337.4355 306 | ``` 307 | 308 | Let's use a regular expression pattern to print all lines 309 | containing phone numbers: 310 | 311 | ```bash 312 | $ grep '(1-)?[[:digit:]]{3}-[[:digit:]]{4}' file2.txt 313 | ``` 314 | 315 | You will notice that this doesn't match any lines. The reason is that 316 | the group syntax `(1-)` and the `{}` notation are not part of the 317 | extended syntax. To have `grep` use the extended syntax, you can either 318 | use the `-E` option (as we've been doing above): 319 | 320 | ```bash 321 | $ grep -E '(1-)?[[:digit:]]{3}-[[:digit:]]{4}' file2.txt 322 | Here is my number: 919-543-3300. 323 | ``` 324 | 325 | or use the `egrep` command: 326 | 327 | ```bash 328 | $ egrep '(1-)?[[:digit:]]{3}-[[:digit:]]{4}' file2.txt 329 | Here is my number: 919-543-3300. 330 | ``` 331 | 332 | If we want to match regardless of whether the phone number is separated 333 | by a minus `-` or a period `.`, we could use the pattern `[-.]`: 334 | 335 | ```bash 336 | $ egrep '(1[-.])?[[:digit:]]{3}[-.][[:digit:]]{4}' file2.txt 337 | Here is my number: 919-543-3300. 338 | Please call 1.919.554.3800 339 | I think he said it was 337.4355 340 | ``` 341 | 342 | ::: {.callout-tip title="Exercise"} 343 | Explain what the following regular expression matches: 344 | 345 | ```bash 346 | $ grep '^[^T]*is.*$' file1.txt 347 | ``` 348 | ::: 349 | 350 | ## 5 Greedy matching 351 | 352 | Regular expression pattern matching is *greedy*---by default, the 353 | longest matching string is chosen. 354 | 355 | Suppose we have the following file: 356 | 357 | ```bash 358 | $ cat file1.txt 359 | Do an internship in place of one course. 360 | ``` 361 | 362 | If we want to match the html tags (e.g., `` and ``, we might be 363 | tempted to use the pattern `<.*>`. Using the `-o` option to grep, we can 364 | have grep print out just the part of the text that the pattern matches: 365 | 366 | ```bash 367 | $ grep -o "<.*>" file1.txt 368 | in place of one 369 | ``` 370 | 371 | To get a non-greedy match, you can use the modifier `?` after the 372 | quantifier. However, this requires that we use the Perl syntax. In order 373 | for grep to use the Perl syntax, we need to use the `-P` option: 374 | 375 | ```bash 376 | $ grep -P -o "<.*?>" file1.txt 377 | 378 | 379 | 380 | 381 | ``` 382 | 383 | However, one can often avoid greedy matching by being more clever. 384 | 385 | ::: {.callout-tip title="Challenge"} 386 | How could we change our regexp to avoid the greedy 387 | matching without using the `?` modifier? Hint: Is there some character 388 | set that we don't want to be inside the angle brackets? 389 | ::: 390 | 391 | ::: {.callout-tip title="globs vs. regex"} 392 | 393 | Be sure you understand the difference between [filename globbing](file-management#3-filename-matching-globbing) 394 | and regular expressions. Filename globbing only works for filenames, while 395 | regular expressions are used to match patterns in text more 396 | generally. While they both use the same set of symbols, they mean 397 | different things (e.g., `*` matches 0 or more characters when 398 | globbing but matches 0 or more repetitions of the character that 399 | precedes it when used in a regular expression). 400 | ::: 401 | -------------------------------------------------------------------------------- /shell-programming.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Shell programming 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | ## 1 Shell scripts 18 | 19 | Shell scripts are files containing shell commands (commonly with the 20 | extension `.sh`) To run a shell script called `file.sh`, you would type 21 | : 22 | 23 | ```bash 24 | $ source ./file.sh 25 | ``` 26 | 27 | or : 28 | 29 | ```bash 30 | $ . ./file.sh 31 | ``` 32 | 33 | Note that if you just typed `file.sh`, the operating system will 34 | generally have two problems: first, it would have trouble finding the script (if `file.sh` is not in a 35 | directory included in the `PATH` environment variable), and second it would have trouble recognizing that it is 36 | executable (if the `-x` flag is not set for `file.sh`). 37 | 38 | To be sure that the operating system knows what shell to use 39 | to interpret the script, the first line of the script should be 40 | `#!/bin/bash` (in the case that you're using the bash shell). 41 | 42 | The best thing to do is to set `file.sh` to be executable (i.e., to have the 'x' flag set), and you can can execute it simply with: 43 | 44 | ```bash 45 | $ ./file.sh 46 | ``` 47 | 48 | ## 2 Functions 49 | 50 | You can define your own utilities by creating a shell function. This 51 | allows you to automate things that are more complicated than you can do 52 | with an 53 | [alias](using-commands#8-aliases-command-shortcuts-and-bashrc). 54 | One nice thing about shell functions is that the shell 55 | automatically takes care of function arguments for you. It places the 56 | arguments given by the user into local variables in the function called 57 | (in order): `$1 $2 $3` etc. It also fills `$#` with the number of 58 | arguments given by the user. Here's an example of using arguments in a 59 | function that saves me some typing when I want to copy a file to the SCF 60 | filesystem: 61 | 62 | ```bash 63 | function putscf() { 64 |    scp $1 jarrod@arwen.berkeley.edu:$2 65 | } 66 | ``` 67 | 68 | To use this function, I just do the following to copy `unit1.pdf` from 69 | the current directory on whatever non-SCF machine I'm on to the 70 | directory `~/teaching/243` on SCF: 71 | 72 | ```bash 73 | $ putscf unit1.pdf teaching/243/. 74 | ``` 75 | 76 | Often you'd want to put such functions in your `.bashrc` file. 77 | 78 | ## 3 If/then/else 79 | 80 | We can use if-then-else type syntax to control the flow of a shell 81 | script. For an example, here is a shell function `niceR()` that can be 82 | used for nicing R jobs: 83 | 84 | ```bash 85 | # niceR shortcut for nicing R jobs 86 | # usage: niceR inputRfile outputRfile 87 | # Author: Brian Caffo 88 | # Date: 10/01/03 89 | 90 | function niceR(){ 91 | # submits nice'd R jobs 92 | if [ $# != "2" ]; then 93 | echo "usage: niceR inputRfile outputfile" 94 | elif [ -e "$2" ]; then 95 | echo "$2 exists, I won't overwrite" 96 | elif [ ! -e "$1" ]; then 97 | echo "inputRfile $1 does not exist" 98 | else 99 | echo "running R on $1" 100 | nice -n 19 R --no-save < $1 &> $2 101 | fi 102 | } 103 | ``` 104 | 105 | If the `then` is on a separate line from the `if`, you won't need the semicolon. 106 | 107 | ## 4 For loops 108 | 109 | For loops in shell scripting are primarily designed for iterating 110 | through a set of files or directories. Here's an example: 111 | 112 | ```bash 113 | $ for FILE in $(ls *.txt); do 114 | >    mv $file ${FILE/.txt/.R} 115 | >   # this syntax replaces .txt with .R in $FILE`` 116 | > done 117 | ``` 118 | 119 | Note that the `>` prompt above occurs when the shell is expecting 120 | further input. 121 | 122 | Another use of `for` loops is automating file downloads: 123 | 124 | ```bash 125 | # example of bash for loop and wget for downloading a collection of files on the web 126 | # usage: ./forloopDownload.sh 127 | # Author: Chris Paciorek 128 | # Date: July 28, 2011 129 | 130 | url='ftp://ftp.ncdc.noaa.gov/pub/data/ghcn/daily/grid/years' 131 | types="tmin tmax" 132 | for ((yr=1950; yr<=2017; yr++)) 133 | do 134 | for type in ${types} 135 | do 136 | wget ${url}/${yr}.${type} 137 | done 138 | done 139 | ``` 140 | 141 | If the `do` is on a separate line from the `for`, you don't need the 142 | semicolon seen in the previous example. 143 | 144 | 145 | *for* loops are very useful for starting a series of jobs: 146 | 147 | ```bash 148 | # example of bash for loop for starting jobs 149 | # usage: ./forloopJobs.sh 150 | # Author: Chris Paciorek 151 | # Date: July 28, 2011 152 | 153 | n=100 154 | for(( it=1; it<=100; it++ )) 155 | do 156 | echo "n=$n; it=$it; source('base.R')" > tmp-$n-$it.R # create customized R file 157 | R CMD BATCH --no-save tmp-$n-$it.R sim-n$n-it$it.Rout 158 | done 159 | # note that base.R should NOT set either 'n' or 'it' 160 | ``` 161 | 162 | That's just an illustration. In reality, in the case above you'd be better off passing arguments into the R code using `commandArgs` or by setting environment variables that are read in the R code. 163 | 164 | Note by default the separator when you're looping through elements of a variable will be a space (as above), but you can set it differently, for example: 165 | 166 | ```bash 167 | $ IFS=: 168 | $ types=tmin:tmax:pmin:pmax 169 | $ for type in $types 170 | > do 171 | > echo $type 172 | > done 173 | tmin 174 | tmax 175 | pmin 176 | pmax 177 | ``` 178 | 179 | 180 | ## 5 How much shell scripting should I learn? 181 | 182 | We've covered most of what you are likely to need to know about the 183 | shell. I tend to only use bash scripts for simple tasks that require 184 | only a few lines of bash commands and limited control flow (i.e., 185 | conditional statements, loops). For more complicated OS tasks, it is 186 | often preferable to use Python. (You can also do a fair amount of what 187 | you need from within R using the `system()` function.) This will enable 188 | you to avoid dealing with a lot of shell programming syntax. But you'll 189 | still need to know how to use standard UNIX commands/utilities, wildcards, and pipes to be 190 | effective. 191 | -------------------------------------------------------------------------------- /testfile.txt: -------------------------------------------------------------------------------- 1 | This is the first line. 2 | Followed by this line. 3 | And then ... 4 | -------------------------------------------------------------------------------- /using-commands.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Using UNIX commands 3 | date: 2025-04-09 4 | format: 5 | html: 6 | theme: cosmo 7 | css: assets/styles.css 8 | toc: true 9 | code-copy: true 10 | code-block-bg: true 11 | code-block-border-left: "#31BAE9" 12 | engine: knitr 13 | ipynb-shell-interactivity: all 14 | code-overflow: wrap 15 | --- 16 | 17 | ## 1 Basic utilities / commands 18 | 19 | [Earlier](index#5-introduction-to-commands) we introduced the basics of entering commands in the shell. 20 | 21 | 22 | Since files are such an essential aspect of Unix and working from the 23 | shell is the primary way to work with Unix, there are a large number of 24 | useful commands and tools to view and manipulate files. 25 | 26 | - cat -- concatenate files and print to standard output 27 | - cp -- copy files and directories 28 | - cut --_remove sections from each line of files 29 | - diff -- find differences between two files 30 | - grep -- print lines matching a pattern 31 | - head -- output the first part of files 32 | - find --  search for files in a directory hierarchy 33 | - less -- opposite of more (and better than more) 34 | - more -- file perusal filter for crt viewing 35 | - mv -- move (rename) files 36 | - nl -- number lines of files 37 | - paste -- merge lines of files 38 | - rm -- remove files or directories 39 | - rmdir -- remove empty directories 40 | - sort -- sort lines of text files. 41 | - split -- split a file into pieces 42 | - tac -- concatenate and print files in reverse 43 | - tail -- output the last part of files 44 | - touch -- change file timestamps 45 | - tr -- translate or delete characters 46 | - uniq -- remove duplicate lines from a sorted file 47 | - wc -- print the number of bytes, words, and lines in files 48 | - wget and curl -- non-interactive internet downloading 49 | 50 | Recall that a command consists of the command, optionally one or more flags, and optionally one or more arguments. When there is an argument, it is often the name of a file that the command should operate on. 51 | 52 | Thus the general syntax for a Unix program/command/utility is: 53 | 54 | ``` 55 | $ command -options argument1 argument2 ... 56 | ``` 57 | 58 | For example, : 59 | 60 | ```bash 61 | $ grep -i graphics file.txt 62 | ``` 63 | 64 | looks for the literal string `graphics` (argument 1) in `file.txt` 65 | (argument2) with the option `-i`, which says to ignore the case of the 66 | letters. A simpler invocation is:While : 67 | 68 | ```bash 69 | $ less file.txt 70 | ``` 71 | 72 | which simply pages through a text file (you can navigate up and down 73 | with the space bar and the up/down arrows) so you 74 | can get a feel for what's in it. To exit `less` type `q`. 75 | 76 | 77 | Unix programs often take flags (options) that are identified with a minus 78 | followed by a letter and then (possibly) followed by the specific option (adding a space 79 | before the specific option is fine). Options may also involve two 80 | dashes, e.g., `R --no-save`. A standard two dash option for many 81 | commands is `--help`. For example, try: 82 | 83 | ```bash 84 | $ tail --help 85 | ``` 86 | 87 | Here are a couple of examples of flags when using the `tail` command 88 | (`-n 10` and `-f`): 89 | 90 | ```bash 91 | $ wget https://raw.githubusercontent.com/berkeley-scf/tutorial-using-bash/master/cpds.csv 92 | $ tail -n 10 cpds.csv # last 10 lines of cpds.csv 93 | $ tail -f cpds.csv # shows end of file, continually refreshing 94 | ``` 95 | 96 | The first line downloads the data from GitHub. The two main tools 97 | for downloading network-accessible data from the commandline are `wget` 98 | and `curl`. I tend to use `wget` as my commandline downloading tool as 99 | it is more convenient, but on a Mac, only `curl` is generally available. 100 | 101 | A few more tidbits about `grep` (we will see more examples of `grep` in 102 | the [section on regular expressions](regex), but it is so useful that it is worth 103 | seeing many times): 104 | 105 | ```bash 106 | $ grep ^2001 cpds.csv # returns lines that start with '2001' 107 | $ grep 0$ cpds.csv # returns lines that end with '0' 108 | $ grep 19.0 cpds.csv # returns lines with '19' separated from '0' by a single character 109 | $ grep 19.*0 cpds.csv # now separated by any number of characters 110 | $ grep -o 19.0 cpds.csv # returns only the content matching the pattern, not entire lines 111 | ``` 112 | 113 | Note that the first argument to grep is the pattern you are looking for. 114 | The syntax is different from that [used for wildcards](file-management#3-filename-globbing) in file names. 115 | Also, you can use regular expressions in the pattern, but we defer 116 | details until [later](regex). 117 | 118 | It is sometimes helpful to put the pattern inside double quotes, e.g., 119 | if you want spaces in your pattern: 120 | 121 | ```bash 122 | $ grep "George .* Bush" cpds.csv 123 | ``` 124 | 125 | More generally in Unix, enclosing a string in quotes is often useful to 126 | indicate that it is a single argument/value. 127 | 128 | If you want to explicitly look for one of the special characters used in 129 | creating patterns (such as double quote (`"`), period (`.`), etc.), you 130 | can "escape" them by preceding with a back-slash. For example to look 131 | for `"Canada"`, including the quotes: 132 | 133 | ```bash 134 | $ grep "\"Canada\"" cpds.csv # look for "Canada" (including quotes) 135 | $ grep "19\.0" cpds.csv # look for 19.0 136 | ``` 137 | 138 | If you have a big data file and need to subset it by line (e.g., with 139 | `grep`) or by field (e.g., with `cut`), then you can do it really fast 140 | from the Unix command line, rather than reading it with R, SAS, Python, 141 | etc. 142 | 143 | Much of the power of these utilities comes in piping between them (see 144 | the next section) and [using wildcards](file-management#3-filename-globbing) to 145 | operate on groups of files. The utilities can also be used in shell 146 | scripts to do more complicated things. 147 | 148 | We'll see further examples of how to use these utilities later. 149 | 150 | ::: {.callout-tip title="Exercise"} 151 | 152 | You've already seen some of the above commands. Use the `--help` 153 | syntax to view the abbreviated man pages for some commands you're not 154 | familiar with and consider how you 155 | might use these commands. 156 | ::: 157 | 158 | ## 3 Streams, pipes, and redirects 159 | 160 | ### 3.1 Streams (stdin/stdout/stderr) 161 | 162 | Unix programs that involve input and/or output often operate by reading 163 | input from a *stream* known as standard input (*stdin*), and writing their 164 | results to a stream known as standard output (*stdout*). In addition, a 165 | third stream known as standard error (*stderr*) receives error messages 166 | and other information that's not part of the program's results. In the 167 | usual interactive session, standard output and standard error default to 168 | your screen, and standard input defaults to your keyboard. 169 | 170 | ### 3.2 Overview of redirection 171 | 172 | You can change the place from which programs read and write through 173 | redirection. The shell provides this service, not the individual 174 | programs, so redirection will work for all programs. The following table 175 | shows some examples of redirection. 176 | 177 | **Table. Common Redirection Operators** 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 |
Redirection SyntaxFunction
$ cmd > fileSend stdout to file
$ cmd 1> fileSame as above
$ cmd 2> fileSend stderr to file
$ cmd > file 2>&1Send both stdout and stderr to file
$ cmd < fileReceive stdin from file
$ cmd >> fileAppend stdout to file
$ cmd 1>> fileSame as above
$ cmd 2>> fileAppend stderr to file
$ cmd >> file 2>&1Append both stdout and stderr to file
$ cmd1 | cmd2Pipe stdout from cmd1 to cmd2
$ cmd1 2>&1 | cmd2Pipe stdout and stderr from cmd1 to cmd2
$ cmd1 | tee file1 | cmd2Pipe stdout from cmd1 to cmd2 while simultaneously writing it to file1
using tee
241 | 242 | Note that `cmd` may include options and arguments as seen in the 243 | previous section. 244 | 245 | 246 | 247 | ### 3.3 Standard redirection (pipes) 248 | 249 | Operations where output from one command is used as input to another 250 | command (via the `|` operator) are known as pipes; they are made 251 | especially useful by the convention that many UNIX commands will accept 252 | their input through the standard input stream when no file name is 253 | provided to them. 254 | 255 | A simple pipe to `wc` to count the number of words in a string: 256 | 257 | ```bash 258 | $ echo "hey there" | wc -w 259 | 2 260 | ``` 261 | 262 | Translating lowercase to UPPERCASE with `tr`: 263 | 264 | ```bash 265 | $ echo 'user1' | tr 'a-z' 'A-Z' 266 | USER1 267 | ``` 268 | 269 | Here's an example of finding out how many unique entries there are in 270 | the 2nd column of a data file whose fields are separated by commas: 271 | 272 | ```bash 273 | $ cut -d',' -f2 cpds.csv | sort | uniq | wc 274 | $ cut -d',' -f2 cpds.csv | sort | uniq > countries.txt 275 | ``` 276 | 277 | Here are the piecies of what is going on in the commands above: 278 | 279 | - We use the `cut` utility to extract the second field (`-f2`) or 280 | column of the file `cpds.csv` where the fields (or columns) are split or 281 | delimited by a comma (`-d','`). 282 | - The standard output of the `cut` command [is then piped (via `|`) to the standard input of the `sort` command. 283 | - Then the output of `sort` is sent to the input of `uniq` to remove 284 | duplicate entries in the sorted list provided by `sort`. (Rather than 285 | using `sort | uniq`, you could also use `sort -u`.) 286 | - Finally, the first of the `cut` commands prints a word count summary using `wc`; while the 287 | second saving the sorted information with duplicates removed in the file 288 | `countries.txt`. 289 | 290 | As another example of checking for anomalies in a set of files, with 291 | the , to see if there are any "S" values in certain fields (based on fixed 292 | width using `-b`) of a 293 | set of files (`USC*dly`), one can do this: 294 | 295 | ```bash 296 | $ cut -b29,37,45,53,61,69,77,85,93,101,109,117,125,133,141,149, \  297 | 157,165,173,181,189,197,205,213,221,229,237,245,253, \ 298 | 261,269 USC*.dly | grep S | less 299 | ``` 300 | 301 | (Note I did that on 22,000 files (5 Gb or so) in about 5 302 | minutes on my desktop; it would have taken much more time to read the 303 | data into a program like R or Python.) 304 | 305 | ### 3.4 The `tee` command 306 | 307 | The `tee` command lets you create two streams from one. For example, 308 | consider the case where you want the results of this command: 309 | 310 | ```bash 311 | $ cut -d',' -f2 cpds.csv | sort | uniq 312 | ``` 313 | 314 | to both be output to the terminal screen you are working in as well as 315 | being saved to a file. You could issue the command twice: 316 | 317 | ```bash 318 | $ cut -d',' -f2 cpds.csv | sort | uniq 319 | $ cut -d',' -f2 cpds.csv | sort | uniq > countries.txt 320 | ``` 321 | 322 | Instead of repeating the command and wasting computing time, you could 323 | use `tee` command: 324 | 325 | ```bash 326 | $ cut -d',' -f2 cpds.csv | sort | uniq | tee countries.txt 327 | ``` 328 | 329 | ## 4 Command substitution and the `xargs` command 330 | 331 | ### 4.1 Command substitution 332 | 333 | A closely related, but subtly different, capability to piping is 334 | command substitution. You may sometimes need to substitute the results of a command for use 335 | by another command. For example, if you wanted to use the directory 336 | listing returned by `ls` as the argument to another command, you would 337 | type `$(ls)` in the location you want the result of `ls` to appear. 338 | 339 | When the shell encounters a command 340 | surrounded by `$()`, it runs the command and replaces the 341 | expression with the output from the command. This allows something 342 | similar to a pipe, but it is appropriate when a command reads its arguments 343 | directly from the command line instead of through standard input. 344 | 345 | For 346 | example, suppose we are interested in searching for the text `pdf` in 347 | the last 4 R code files (those with suffix `.r` or `.R`) that were 348 | modified in the current directory. We can find the names of the four most 349 | recently modified files ending in `.R` or `.r` using: 350 | 351 | ```bash 352 | $ ls -t *.{R,r} | head -4 353 | ``` 354 | 355 | and we can search for the required pattern using `grep` . Putting these 356 | together with command substitution, we can solve the problem using: 357 | 358 | ```bash 359 | $ grep pdf $(ls -t *.{R,r} | head -4) 360 | ``` 361 | 362 | Suppose that the four R code file names produced by the `ls` command above were: 363 | `test.R`, `run.R`, `analysis.R` , and `process.R`. Then the result of the command substitution above is to run the following command: 364 | 365 | ```bash 366 | $ grep pdf test.R run.R analysis.R process.R 367 | ``` 368 | 369 | 370 | ::: {.callout-tip title="Command substitution alternate syntax"} 371 | 372 | An older notation for command substitution is to use backticks (e.g., 373 | `` `ls` `` rather than `$(ls)`). It is generally preferable to use the new 374 | notation, since there are many annoyances with the backtick notation. 375 | For example, backslashes (`\`) inside of backticks behave in a 376 | non-intuitive way, nested quoting is more cumbersome inside backticks, 377 | nested substitution is more difficult inside of backticks, and it is 378 | easy to visually mistake backticks for a single quote. 379 | ::: 380 | 381 | Note that piping the output of the `ls` command into `grep` would not 382 | achieve the desired goal, since `grep` reads its filenames as arguments from the 383 | command line, not standard input. 384 | 385 | ### 4.2 The `xargs` command 386 | 387 | While it doesn't work to directly use pipes to redirect output from one program 388 | as arguments to another program, you can redirect output as the arguments to another program using 389 | the `xargs` utility. Here's an example: 390 | 391 | ```bash 392 | $ ls -t *.{R,r} | head -4 | xargs grep pdf 393 | ``` 394 | 395 | where the result is equivalent to the use of command substitution we saw in the previous section. 396 | 397 | ::: {.callout-tip title="Exercise"} 398 | 399 | Try the following commands: 400 | 401 | ```bash 402 | $ ls -l tr 403 | $ type -p tr 404 | $ ls -l type -p tr 405 | $ ls -l $(type -p tr) 406 | ``` 407 | 408 | Make sure you understand why each command behaves as it does. 409 | ::: 410 | 411 | ## 5 Brace expansion 412 | 413 | We saw brace expansion when discussing file wildcards. For example, we can 414 | rename a file with a long name easily like this: 415 | 416 | ```bash 417 | $ mv my_long_filename.{txt,csv} 418 | $ ls my_long_filename* 419 | my_long_filename.csv 420 | $ mv my_long_filename.csv{,-old} 421 | $ ls my_long_filename* 422 | my_long_filename.csv-old 423 | ``` 424 | 425 | This works because the shell expands the braces before passing the result on to the command. So with the `mv` calls above, the shell expands the braces to produce 426 | 427 | ```bash 428 | mv my_long_filename.txt my_long_filename.csv 429 | mv my_long_filename.csv my_long_filename.csv-old 430 | ``` 431 | 432 | Brace expansion is quite useful and more flexible than I've indicated. 433 | Above we saw how to use brace expansion using a comma-separated 434 | list of items inside the curly braces (e.g., `{txt,csv}`), but they can 435 | also be used with a sequence specification. A sequence is indicated with 436 | a start and end item separated by two periods (`..`). Try typing the 437 | following examples at the command line and try to figure out how they 438 | work: 439 | 440 | ```bash 441 | $ echo {1..15} 442 | $ echo c{c..e} 443 | $ echo {d..a} 444 | $ echo {1..5..2} 445 | $ echo {z..a..-2} 446 | ``` 447 | 448 | This can be used for filename wildcards but also anywhere else it would be useful. For example to kill a bunch of sequentially-numbered processes: 449 | 450 | ```bash 451 | $ kill 1397{62..81} 452 | ``` 453 | ## 6 Quoting 454 | 455 | A note about using single vs. double quotes in shell code. In 456 | general, variables inside double quotes will be evaluated, but variables 457 | not inside double quotes will not be: 458 | 459 | ```bash 460 | $ echo "My home directory is $HOME" 461 | My home directory is /home/jarrod 462 | $ echo 'My home directory is $HOME' 463 | My home directory is $HOME 464 | ``` 465 | 466 | **Table. Quotes** 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 |
Types of QuotingDescription
' 'hard quote - no substitution allowed
" "soft quote - allow substitution
486 | 487 | This can be useful, for example, when you have a directory with a space 488 | in its name (of course, it is better to avoid spaces in file and 489 | directory names). For example, suppose you have a directory named "with space" within the `/home/jarrod` home directory. 490 | Since bash uses spaces to parse the elements of the 491 | command line, you might try escaping any spaces with a backslash: 492 | 493 | ```bash 494 | $ ls $HOME/with\ space 495 | file1.txt 496 | ``` 497 | 498 | However that can be a pain and may not work in all circumstances. A cleaner 499 | approach is to use soft (or double) quotes: 500 | 501 | ```bash 502 | $ ls "$HOME/with space" 503 | file1.txt 504 | ``` 505 | 506 | If you used hard quotes, you will get this error: 507 | 508 | ```bash 509 | $ ls '$HOME/with space' 510 | ls: cannot access $HOME/with space: No such file or directory 511 | ``` 512 | 513 | What if you have double quotes in your file or directory name, such as a directory `"with"quote` (again, it 514 | is better to avoid using double quotes in file and directory names)? In 515 | this case, you will need to escape the quote: 516 | 517 | ```bash 518 | $ ls "$HOME/\"with\"quote" 519 | ``` 520 | 521 | So we'll generally use double quotes. We can always work with a literal 522 | double quote by escaping it as seen above. 523 | 524 | ::: {.callout-warning title="Curly quotes"} 525 | Avoid using curly quotes (e.g., “ or ‘) when coding (in the shell or otherwise), 526 | except as part of an actual string. 527 | ::: 528 | 529 | ## 7 Powerful tools for text manipulation: `grep`, `sed`, and `awk` 530 | 531 | Before the text editor, there was the line editor. Rather than 532 | presenting you with the entire text as a text editor does, a line editor 533 | only displays lines of text when it is requested to. The original Unix 534 | line editor is called `ed`. You will likely never use `ed` directly, but 535 | you will very likely use commands that are its descendants. For example, 536 | the commands `grep`, `sed`, `awk`, and `vim` are all based directly on 537 | `ed` (e.g., `grep` is a `ed` command that is now available as a 538 | standalone command, while `sed` is a streaming version of `ed`) or 539 | inherit much of its syntax (e.g., `awk` and `vim` both heavily borrow 540 | from the `ed` syntax). Since `ed` was written when computing resources 541 | were very constrained compared to today, this means that the syntax of 542 | these commands can be terse. However, it also means that learning the 543 | syntax for one of these tools will be rewarded when you need to learn 544 | the syntax of another of these tools. 545 | 546 | An important benefit of these tools, particularly when working with large files, is that by operating line by line they 547 | don't incur the memory use that would be involved in reading an entire file into memory in a program like Python or R and then operating on the file's contents in memory. 548 | 549 | You may not need to learn much `sed` or `awk`, but it is good to know about 550 | them since you can search the internet for awk or sed one-liners. If you 551 | have some file munging task, it can be helpful to do a quick search 552 | before writing code to perform the task yourself. 553 | 554 | ### 7.1 `grep` 555 | 556 | The simplest of these tools is `grep`. As I mentioned, `ed` only 557 | displays lines of text when requested. One common task was to print all 558 | the lines in a file matching a specific regular expression. The command 559 | in `ed` that does this is `g//p`, which stands for globally match 560 | all lines containing the regular express `` and print them out. 561 | 562 | One often uses `grep` with [regular expressions](regex), covered 563 | later, so we'll just show some basic usage here. 564 | 565 | To start you will need to create a file called `testfile.txt` with the 566 | following content: 567 | 568 | ``` 569 | This is the first line. 570 | Followed by this line. 571 | And then ... 572 | ``` 573 | 574 | To print all the lines containing `is`: 575 | 576 | ```bash 577 | $ grep is testfile.txt 578 | This is the first line. 579 | Followed by this line. 580 | ``` 581 | 582 | To print all the lines **not** containing `is`: 583 | 584 | ```bash 585 | $ grep -v is testfile.txt 586 | And then ... 587 | ``` 588 | 589 | To print only the matches, one can use the `-o` flag, though this 590 | would generally only be interesting when used with a regular 591 | expression pattern since in this case, we know "is" is what will be 592 | returned: 593 | 594 | ```bash 595 | $ grep -o is testfile.txt 596 | is 597 | is 598 | is 599 | ``` 600 | 601 | One could also use `--color` so that the matches are highlighed in color. 602 | 603 | 604 | ### 7.2 `sed` 605 | 606 | Here are some useful things you can do with `sed`. Note that as with 607 | other UNIX tools, `sed` will not generally directly alter a file 608 | (unless you use the `-i` flag); instead it will print the modified 609 | version of the file to stdout. 610 | 611 | Printing lines of text with `sed`: 612 | 613 | ```bash 614 | $ sed -n '1,9p' file.txt # prints out lines 1-9 from file.txt 615 | $ sed -n '/^#/p' file.txt # prints out lines starting with # from file.txt 616 | ``` 617 | 618 | The first command prints out lines 1-9, while the second 619 | one prints out lines starting with `#`. 620 | 621 | Deleting lines of text with `sed`: 622 | 623 | ```bash 624 | $ sed -e '1,9d' file.txt 625 | $ sed -e '/^;/d' -e '/^$/d' file.txt 626 | ``` 627 | 628 | The first line deletes lines 1-9 of `file.txt`, printing the remaining 629 | lines to stdout. What do you think the 630 | second line does? 631 | 632 | Note that the -e flag is only necessary if you want to have more than one expression, so it's not actually needed in the first line. 633 | 634 | Text substitution with `sed`: 635 | 636 | ```bash 637 | $ sed 's/old_pattern/new_pattern/' file.txt > new_file.txt 638 | $ sed 's/old_pattern/new_pattern/g' file.txt > new_file.txt 639 | $ sed -i 's/old_pattern/new_pattern/g' file.txt 640 | ``` 641 | 642 | The first line replaces only the first instance in a line, while the second 643 | line replaces all instances in a line (i.e., globally). The use of the -i 644 | flag in the third line replaces 645 | the pattern **in place** in the file, thereby altering file.txt. Use 646 | the `-i` flag carefully as there is no way to easily restore the original version of the file. 647 | 648 | ### 7.3 `awk` 649 | 650 | Awk is a general purpose programming language typically used in data 651 | extraction tasks and particularly well-suited to one-liners (although it 652 | is possible to write long programs in it, it is rare). For our purposes, 653 | we will just look at a few common one-liners to get a sense of how it 654 | works. Basically, awk will go through a file line by line and perform 655 | some action for each line. 656 | 657 | For example, to select a given column from some text (here getting 658 | the PIDs of some processes, which are in the second (`$2`) column of 659 | the output of `ps -f`: 660 | 661 | ```bash 662 | ps -f | awk '{ print $2 }' 663 | ``` 664 | 665 | To double space a file, you would read each line, print it, 666 | and then print a blank line: 667 | 668 | ```bash 669 | $ awk '{ print } { print "" }' file.txt 670 | ``` 671 | 672 | Print every line of a file that is longer than 80 characters: 673 | 674 | ```bash 675 | $ awk 'length($0) > 80' file.txt 676 | ``` 677 | 678 | Print the home directory of every user defined in the file 679 | `/etc/passwd`: 680 | 681 | ```bash 682 | $ awk -F: '{ print $6 }' /etc/passwd 683 | ``` 684 | 685 | To see what that does, let's look at the first line of `/etc/passwd`: 686 | 687 | ```bash 688 | $ head -n 1 /etc/passwd 689 | root:x:0:0:root:/root:/bin/bash 690 | ``` 691 | 692 | As you can see the entries are separated by colons (`:`) and the sixth 693 | field contains the root user's home directory (`/root`). The option 694 | `-F:` specifies that the colon `:` is the field delimiter (instead of 695 | the default space delmiter) and `print $6` 696 | prints the 6th field of each line. 697 | 698 | Summing columns: 699 | 700 | ```bash 701 | $ awk '{print $1 + $2}' file.txt 702 | ``` 703 | 704 | This will sum columns 1 and 2 of `file.txt`. 705 | 706 | 707 | ## 8 Aliases (command shortcuts) and .bashrc 708 | 709 | Aliases allow you to use an abbreviation for a command, to create new 710 | functionality or to insure that certain options are always used when you 711 | call an existing command. For example, I'm lazy and would rather type 712 | `q` instead of `exit` to terminate a shell window. You could create the 713 | alias as follow: 714 | 715 | ```bash 716 | $ alias q=exit 717 | ``` 718 | 719 | As another example, suppose you find the `-F` option of `ls` (which 720 | displays `/` after directories, `\` after executable files and `@` after 721 | links) to be very useful. The command : 722 | 723 | ```bash 724 | $ alias ls="ls -F" 725 | ``` 726 | 727 | will ensure that the `-F` option will be used whenever you use `ls`. If 728 | you need to use the unaliased version of something for which you've 729 | created an alias, precede the name with a backslash (`\`). For example, 730 | to use the normal version of `ls` after you've created the alias 731 | described above: 732 | 733 | ```bash 734 | $ \ls 735 | ``` 736 | 737 | The real power of aliases is only achieved when they are automatically 738 | set up whenever you log in to the computer or open a new shell window. 739 | To achieve that goal with aliases (or any other bash shell commands), 740 | simply insert the commands in the file `.bashrc` in your home directory. 741 | For example, here is an excerpt from my `.bashrc`: 742 | 743 | ```bash 744 | # .bashrc 745 | 746 | # Source global definitions 747 | if [ -f /etc/bashrc ]; then 748 | . /etc/bashrc 749 | fi 750 | 751 | # User specific aliases and functions 752 | pushdp () { 753 | pushd "$(python -c "import os.path as _, ${1}; \ 754 | print _.dirname(_.realpath(${1}.__file__[:-1]))" 755 | )" 756 | } 757 | 758 | export EDITOR=vim 759 | source /usr/share/git-core/contrib/completion/git-prompt.sh 760 | export PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' 761 | 762 | # history settings 763 | export HISTCONTROL=ignoredups # no duplicate entries 764 | shopt -s histappend # append, don't overwrite 765 | 766 | # R settings 767 | export R_LIBS=$HOME/usr/lib64/R/library 768 | alias R="/usr/bin/R --quiet --no-save" 769 | 770 | # Set path 771 | mybin=$HOME/usr/bin 772 | export PATH=$mybin:$HOME/.local/bin:$HOME/usr/local/bin:$PATH: 773 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/usr/local/lib 774 | 775 | # Additional aliases 776 | alias grep='grep --color=auto' 777 | alias hgrep='history | grep' 778 | alias l.='ls -d .* --color=auto' 779 | alias ll='ls -l --color=auto' 780 | alias ls='ls --color=auto' 781 | alias more=less 782 | alias vi=vim 783 | ``` 784 | 785 | 786 | ::: {.callout-tip title="Exercise"} 787 | 788 | Look over the content of the example `.bashrc` and make sure you 789 | understand what each line does. For instance, use `man grep` to see what 790 | the option `--color=auto` does. Use `man which` to figure out what the 791 | various options passed to it do. 792 | 793 | ::: 794 | --------------------------------------------------------------------------------