├── .gitignore ├── assets ├── css │ └── style.scss ├── styles.css ├── stat_bear.png ├── img │ ├── ls_format.png │ └── logo.svg ├── fonts │ ├── Noto-Sans-700 │ │ ├── Noto-Sans-700.eot │ │ ├── Noto-Sans-700.ttf │ │ ├── Noto-Sans-700.woff │ │ ├── Noto-Sans-700.woff2 │ │ └── Noto-Sans-700.svg │ ├── Noto-Sans-italic │ │ ├── Noto-Sans-italic.eot │ │ ├── Noto-Sans-italic.ttf │ │ ├── Noto-Sans-italic.woff │ │ └── Noto-Sans-italic.woff2 │ ├── Noto-Sans-regular │ │ ├── Noto-Sans-regular.eot │ │ ├── Noto-Sans-regular.ttf │ │ ├── Noto-Sans-regular.woff │ │ └── Noto-Sans-regular.woff2 │ └── Noto-Sans-700italic │ │ ├── Noto-Sans-700italic.eot │ │ ├── Noto-Sans-700italic.ttf │ │ ├── Noto-Sans-700italic.woff │ │ └── Noto-Sans-700italic.woff2 └── js │ └── scale.fix.js ├── example.txt ├── mv_assets.sh ├── _sass ├── minimal.scss ├── fonts.scss ├── rouge-github.scss ├── jekyll-theme-minimal.scss.bak └── jekyll-theme-minimal.scss ├── _config.yml ├── _quarto.yml ├── README.md ├── _layouts └── default.html ├── _includes └── toc.html ├── index.qmd └── _freeze └── index └── execute-results └── html.json /.gitignore: -------------------------------------------------------------------------------- 1 | # emacs backup files 2 | *~ 3 | 4 | 5 | /.quarto/ 6 | -------------------------------------------------------------------------------- /assets/css/style.scss: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | 4 | @import "jekyll-theme-minimal"; 5 | -------------------------------------------------------------------------------- /example.txt: -------------------------------------------------------------------------------- 1 | Hello there. 2 | This is a file 3 | that contains 4 | 4 lines. 5 | -------------------------------------------------------------------------------- /assets/styles.css: -------------------------------------------------------------------------------- 1 | .cell-output { 2 | background-color: #F0F0F0; 3 | border-radius: 4px; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /assets/stat_bear.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/stat_bear.png -------------------------------------------------------------------------------- /assets/img/ls_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/img/ls_format.png -------------------------------------------------------------------------------- /mv_assets.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd 3 | tar -cvzf assets.tgz assets 4 | mv assets.tgz /tmp 5 | cd /tmp 6 | tar -xvzf assets.tgz 7 | -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700/Noto-Sans-700.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700/Noto-Sans-700.eot -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700/Noto-Sans-700.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700/Noto-Sans-700.ttf -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700/Noto-Sans-700.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700/Noto-Sans-700.woff -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700/Noto-Sans-700.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700/Noto-Sans-700.woff2 -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-italic/Noto-Sans-italic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-italic/Noto-Sans-italic.eot -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-italic/Noto-Sans-italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-italic/Noto-Sans-italic.ttf -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff2 -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-regular/Noto-Sans-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-regular/Noto-Sans-regular.eot -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-regular/Noto-Sans-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-regular/Noto-Sans-regular.ttf -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff2 -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/berkeley-scf/tutorial-unix-basics/HEAD/assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2 -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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: UNIX basics tutorial 5 | description: Introductory training materials for working on the UNIX command line. 6 | show_downloads: false 7 | logo: assets/img/logo.svg -------------------------------------------------------------------------------- /_quarto.yml: -------------------------------------------------------------------------------- 1 | project: 2 | type: website 3 | 4 | website: 5 | site-url: https://computing.stat.berkeley.edu/tutorial-unix-basics 6 | sidebar: 7 | style: docked 8 | title: "SCF UNIX Basics 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-unix-basics 15 | aria-label: GitHub 16 | contents: 17 | - href: index.qmd 18 | 19 | format: 20 | html: 21 | theme: cosmo 22 | css: assets/styles.css 23 | toc: true 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tutorial-unix-basics 2 | ===================== 3 | 4 | Tutorial on the basics of the UNIX command line. 5 | 6 | Please see the [tutorial website](https://computing.stat.berkeley.edu/tutorial-unix-basics) to easily view the materials in a browser. 7 | 8 | This tutorial covers: 9 | 10 | * accessing a UNIX command line from various operating systems 11 | * navigating the filesystem 12 | * basic use of UNIX commands 13 | * copying, moving and deleting files 14 | * file permissions 15 | * compressing files and directories 16 | * getting information on the machine 17 | * basic time-saving tools - tab completion, command history 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /assets/js/scale.fix.js: -------------------------------------------------------------------------------- 1 | (function(document) { 2 | var metas = document.getElementsByTagName('meta'), 3 | changeViewportContent = function(content) { 4 | for (var i = 0; i < metas.length; i++) { 5 | if (metas[i].name == "viewport") { 6 | metas[i].content = content; 7 | } 8 | } 9 | }, 10 | initialize = function() { 11 | changeViewportContent("width=device-width, minimum-scale=1.0, maximum-scale=1.0"); 12 | }, 13 | gestureStart = function() { 14 | changeViewportContent("width=device-width, minimum-scale=0.25, maximum-scale=1.6"); 15 | }, 16 | gestureEnd = function() { 17 | initialize(); 18 | }; 19 | 20 | 21 | if (navigator.userAgent.match(/iPhone/i)) { 22 | initialize(); 23 | 24 | document.addEventListener("touchstart", gestureStart, false); 25 | document.addEventListener("touchend", gestureEnd, false); 26 | } 27 | })(document); 28 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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 | 58 | {{ content }} 59 | 60 |
61 | 63 |
64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /_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/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 | width:100%; 227 | padding-top:20px; 228 | padding-bottom:20px; 229 | } 230 | 231 | .main { 232 | margin-top: 50px; 233 | } 234 | 235 | 236 | 237 | // This causes weird behavior of toc within header appearing at top of page 238 | // if we have 960, 720 for the two separate @media blocs; 239 | // Instead have both come into effect at same width. 240 | @media print, screen and (max-width: 1150px) { 241 | 242 | div.wrapper { 243 | width:auto; 244 | margin:0; 245 | } 246 | 247 | header, section, footer { 248 | float:none; 249 | position:static; 250 | width:auto; 251 | } 252 | 253 | header { 254 | padding-right:320px; 255 | } 256 | 257 | section { 258 | border:1px solid #e5e5e5; 259 | border-width:1px 0; 260 | padding:20px 0; 261 | margin:0 0 20px; 262 | } 263 | 264 | header a small { 265 | display:inline; 266 | } 267 | 268 | header ul { 269 | position:absolute; 270 | right:50px; 271 | top:52px; 272 | } 273 | } 274 | 275 | @media print, screen and (max-width: 1150px) { 276 | body { 277 | word-wrap:break-word; 278 | } 279 | 280 | header { 281 | padding:0; 282 | } 283 | 284 | header ul, header p.view { 285 | position:static; 286 | } 287 | 288 | pre, code { 289 | word-wrap:normal; 290 | } 291 | } 292 | 293 | @media print, screen and (max-width: 480px) { 294 | body { 295 | padding:15px; 296 | } 297 | 298 | .downloads { 299 | width:99%; 300 | } 301 | 302 | .downloads li, .downloads li + li + li { 303 | width:33%; 304 | } 305 | } 306 | 307 | @media print { 308 | body { 309 | padding:0.4in; 310 | font-size:12pt; 311 | color:#444; 312 | } 313 | } 314 | -------------------------------------------------------------------------------- /_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 | -------------------------------------------------------------------------------- /assets/img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | image/svg+xml -------------------------------------------------------------------------------- /index.qmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: The basics of working on the UNIX command line 3 | date: 2024-10-31 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 | execute: 13 | freeze: auto 14 | engine: knitr 15 | ipynb-shell-interactivity: all 16 | code-overflow: wrap 17 | --- 18 | 19 | 22 | 23 | # 1 Introduction 24 | 25 | ## 1.1 This Tutorial 26 | 27 | 28 | This tutorial covers the basics of navigating in a UNIX-like (e.g., Linux or MacOs) environment. In particular, it covers using the UNIX command line interface, a powerful way to carry out operations on a computer and to automate tasks. Being familiar with operating on the command line will allow you (with some practice and training) to do things more quickly and in a way that can be reproduced later. That's hard or impossible to do if you are doing point-and-click or drag-and-drop operations in a File Manager or Finder window. 29 | 30 | Materials for this tutorial, including the Quarto Markdown file that was used to create this document are [available on GitHub](https://github.com/berkeley-scf/tutorial-unix-basics). 31 | 32 | 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). Episodes 1-3 (the first 20 minutes) cover the material that is in this tutorial. 33 | 34 | :::{.callout-note title="License"} 35 | This tutorial by Christopher Paciorek is licensed under a Creative Commons Attribution 3.0 Unported License. 36 | ::: 37 | 38 | 39 | ## 1.2 The shell 40 | 41 | Operating on the UNIX command line is also known as "using the terminal" and "using the shell". 42 | 43 | The shell is the UNIX program that you interact with when in a terminal window interacting 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. 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. zsh is an extension of bash, so you should be able to use zsh based on this tutorial. 44 | 45 | I've generated this document based on using the bash shell on a computer running the Ubuntu Linux version 22.04 operating system, but you should be able to replicate most of the steps in this tutorial in other UNIX command line environments, ideally using the bash or zsh shells. 46 | 47 | ## 1.3 Accessing a UNIX command line interface 48 | 49 | Here are some options for accessing a UNIX command line interface: 50 | 51 | - MacOS: If you'd like to work on your own Mac, you'll find the Terminal under 52 | `Applications -> Utilities -> Terminal`. 53 | - Windows: 54 | - If you have a sufficiently new version of Windows 10, you can use the [Windows Subsystem for Linux](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide), which will provide you with an Ubuntu shell running bash on your own machine. 55 | - If you have access to remote machines running Linux, you can login to them using programs such as MobaXTerm and Putty. Once logged in, you'll find yourself in a Terminal window on the remote machine. 56 | - JupyterHub: If you have access to a JupyterHub, you will likely be able to start a Terminal session under "New". 57 | - Cloud-based options: You could also try a cloud service such as Google [Cloud Shell](https://shell.cloud.google.com). 58 | 59 | :::{.callout-warning title="Don't use Git Bash for this tutorial"} 60 | You probably shouldn't use `Git Bash` to follow this tutorial as its functionality is limited. 61 | ::: 62 | 63 | Once you're in a Terminal window, you'll be interacting with the shell and you can enter commands to get information and work with the system. Commands often have optional arguments (flags) that are specified with a minus in front of them, as we'll see. 64 | 65 | ## 1.4 Getting started 66 | 67 | Once we are in a terminal, we'll see the "prompt", which indicates that the shell is waiting for us to enter commands. Sometimes the prompt is just `$`: 68 | 69 | :::{.cell-output} 70 | $ 71 | ::: 72 | 73 | but often it contains information about the username of the current user and the directory on the filesystem that we are in. For example, here a prompt that shows that the current user is 'scflocal', on the machine named 'gandalf' in the 'tutorial-unix-basics' (sub)directory in the user's home directory (indicated by `~`): 74 | 75 | :::{.cell-output} 76 | scflocal@gandalf:~/tutorial-unix-basics> 77 | ::: 78 | 79 | :::{.callout-note title="Tutorial code formatting"} 80 | In the remainder of this tutorial, you won't see the prompt in front of the commands. All commands will appear in a grey background, with the output (if any) following the code. 81 | ::: 82 | 83 | 84 | :::{.callout-note title="When the shell is waiting for more information"} 85 | Note that if you simply see `>` instead of the usual prompt, that means the shell thinks you haven't finished entering your command (usually that you haven't finished entering a string) and is expecting more input from you. If you see a newline but nothing else, the shell probably expects you to enter some text for it to process. 86 | 87 | If you're not sure what to do, type `Ctrl-c` (the control key and 'c' at the same time) to get back to the usual prompt. 88 | ::: 89 | 90 | Let's start by running a command, `whoami`, that prints out the username of the current user: 91 | ```{bash} 92 | whoami 93 | ``` 94 | 95 | 96 | 97 | # 2 Using `git` for version control 98 | 99 | We'll discuss `git` briefly, both because it is an important and useful tool, and because it's the easiest way for us to get a set of files to work with in this tutorial. 100 | 101 | Git is an important tool to become familiar with, at least at the basic level. Git allows you to share files between different computers and different people and for people to collaborate on projects together. In particular, it is a version control tool that allows you to have different versions of your files and to go back to earlier versions of your files. Git stores the files for a project in a *repository*. 102 | 103 | For our purposes here, we'll simply use Git to download materials from GitHub, a website that stores Git repositories in the cloud. 104 | 105 | First we'll download the materials for this tutorial. 106 | 107 | To *clone* (i.e., copy) a repository (in this case from GitHub) we do the following. Note that `berkeley-scf` is the *organization* and `tutorial-unix-basics` is the *repository*. Note that everything below that follows the `#` symbol is a comment and not executed. 108 | 109 | Here we'll first use the `cd` command (for "change directory") to go to our home directory and then use `git clone` to download materials to a subdirectory (which will be called `tutorial-unix-basics`) within our home directory. 110 | 111 | ```{bash} 112 | #| eval: false 113 | cd 114 | git clone https://github.com/berkeley-scf/tutorial-unix-basics 115 | ``` 116 | ::: {.cell-output} 117 | ``` 118 | Cloning into 'tutorial-unix-basics'... 119 | remote: Enumerating objects: 387, done. 120 | remote: Counting objects: 100% (66/66), done. 121 | remote: Compressing objects: 100% (45/45), done. 122 | remote: Total 387 (delta 37), reused 46 (delta 19), pack-reused 321 (from 1) 123 | Receiving objects: 100% (387/387), 779.53 KiB | 5.27 MiB/s, done. 124 | Resolving deltas: 100% (199/199), done. 125 | ``` 126 | ::: 127 | 128 | Now suppose that whoever controls the repository makes some changes to the materials in the repository online and you want an updated copy of the repository on your computer. Simply use `cd` to go into any directory in the repository materials on your computer and run `git pull`. 129 | 130 | ```{bash} 131 | #| eval: false 132 | cd tutorial-unix-basics 133 | ``` 134 | 135 | ```{bash} 136 | git pull 137 | ``` 138 | 139 | In this case, since no changes had been made, git simply reports that things are up-to-date. 140 | 141 | We'll discuss how to use `cd` in more detail in the next section. 142 | 143 | # 3 Files and directories 144 | 145 | ## 3.1 Moving around and listing information 146 | 147 | We'll start by thinking about the filesystem, which organizes our information/data into files on the computer's disk. 148 | 149 | Anytime you are at the UNIX command line, you have a *working directory*, which is your current location in the file system. 150 | 151 | Here's how you can see where you are using the `pwd` ("print working directory") command: 152 | 153 | ```{bash} 154 | pwd 155 | ``` 156 | 157 | and here's how you use `ls` to list the files (and subdirectories) in the working directory... 158 | 159 | ```{bash} 160 | ls 161 | ``` 162 | 163 | Now suppose I want to be in a different directory so I can see what is there or do things to the files in that directory. 164 | 165 | The command you need is `cd` and an important concept you need to become familiar with is the notion of 'relative' versus 'absolute' *path*. A path is the set of nested directories that specify a location of interest on the filesystem. 166 | 167 | First let's go to our home directory, which is generally where our files will be. Simply running `cd` will do that. 168 | 169 | ```{bash} 170 | cd 171 | pwd 172 | ``` 173 | 174 | 175 | Now let's go into a subdirectory. We can use `cd` with the name of the subdirectory. The subdirectory is found 'relative' to our working directory, i.e., found from where we currently are. 176 | 177 | ```{bash} 178 | #| eval: false 179 | cd tutorial-unix-basics 180 | pwd 181 | ``` 182 | 183 | :::{.cell-output} 184 | /home/scflocal/tutorial-unix-basics 185 | ::: 186 | 187 | We could also navigate through nested subdirectories. For example, after going back to our home directory, let's go to the `assets` subdirectory of the `tutorial-unix-basics` subdirectory. The `/` is a separate character that distinguishes the nested subdirectories. 188 | 189 | ```{bash} 190 | cd 191 | cd tutorial-unix-basics/assets 192 | pwd 193 | ``` 194 | 195 | 196 | You can access the parent directory of any directory using `..`: 197 | 198 | ```{bash} 199 | #| eval: false 200 | pwd 201 | cd .. 202 | pwd 203 | ``` 204 | :::{.cell-output} 205 | /home/scflocal/tutorial-unix-basics/assets 206 | /home/scflocal/tutorial-unix-basics 207 | ::: 208 | 209 | 210 | We can get more complicated in our use of `..` with relative paths. Here we'll go up a directory and then down to a different subdirectory. 211 | 212 | ```{bash} 213 | cd assets 214 | cd ../_includes 215 | pwd 216 | ``` 217 | 218 | 219 | And here we'll go up two directories and then down to another subdirectory. 220 | 221 | ```{bash} 222 | #| eval: false 223 | cd ../../Desktop # go up two directories and down 224 | pwd 225 | ``` 226 | 227 | :::{.cell-output} 228 | 229 | /home/scflocal/Desktop 230 | ::: 231 | 232 | All of the above examples used relative paths to navigate based on your working directory at the moment you ran the command. 233 | 234 | We can instead use absolute paths so that it doesn't matter where we are when we run the command. Specifying an absolute path is done by having your path start with `/`, such as `/home/scflocal`. If the path doesn't start with `/` then it is interpreted as being a relative path, relative to your working directory. Here we'll go to the `units` subdirectory again, but this time using an absolute path. 235 | 236 | ```{bash} 237 | cd /home/scflocal/tutorial-unix-basics/assets 238 | pwd 239 | ``` 240 | 241 | :::{.callout-warning title="Absolute paths are not robust"} 242 | Note that using absolute paths in scripts is generally a bad idea because the script wouldn't generally work correctly if run on a different machine (which will generally have a different filesystem structure) or as a different user (who will have a different home directory). 243 | ::: 244 | 245 | ## 3.2 The filesystem 246 | 247 | The filesystem is basically a upside-down tree. 248 | 249 | For example, if we just consider the `tutorial-unix-basics` directory, we can see the tree structure using `tree`: 250 | 251 | ```{bash} 252 | tree 253 | ``` 254 | 255 | The dot (`.`) means "this directory", so the top of the tree here is the `tutorial-unix-basics` directory itself, within which there are subdirectories, `asset`, `_includes`, `_layouts`, etc. Then within each of these are files and further subdirectories (as seen in the case of `assets`, which has subdirectories named `css` and `fonts`.) 256 | 257 | If we consider the entire filesystem, the top, or root of the tree, is the `/` directory. Within `/` there are subdirectories, such as `/home` (which contains users' home directories where all of the files owned by a user are stored) and `/bin` (containing UNIX programs, aka 'binaries'). We'll use `ls` again, this time telling it the directory to operate on: 258 | 259 | ```{bash} 260 | ls / 261 | ``` 262 | 263 | 264 | If there is a user named `scflocal`, everything specific to that user would be stored in the user's *home directory*. Here that is `/home/scflocal`, but the exact location may differ on different systems. The shortcut `~scflocal` refers to the `scflocal` home directory, `/home/scflocal`. If you are the `scflocal` user, you can also refer to your home directory by the shortcut `~`. 265 | 266 | 267 | ```{bash} 268 | ls /home 269 | ``` 270 | 271 | ```{bash} 272 | cd /home/scflocal 273 | pwd 274 | ``` 275 | 276 | Go to the home directory of the current user (which happens to be the `scflocal` user): 277 | 278 | 279 | ```{bash} 280 | cd ~ 281 | pwd 282 | ``` 283 | 284 | 285 | Go to the home directory of the scflocal user explicitly: 286 | 287 | ```{bash} 288 | cd ~scflocal 289 | pwd 290 | ``` 291 | 292 | 293 | Another useful directory is `/tmp`, which is a good place to put temporary files that you only need briefly and don't need to save. These will disappear when a machine is rebooted. 294 | 295 | ```{bash} 296 | cd /tmp 297 | ls 298 | ``` 299 | 300 | 301 | We can return to the most recent directory we were in like this: 302 | 303 | ```{bash} 304 | #| eval: false 305 | cd - 306 | pwd 307 | ``` 308 | 309 | :::{.cell-output} 310 | /home/scflocal 311 | ::: 312 | 313 | # 4 Using commands 314 | 315 | ## 4.1 Overview 316 | 317 | Let's look more at various ways to use commands. We just saw the `ls` command. Here's one way we can modify the behavior of the command by passing a command option. Here the `-F` option (also called a 'flag') shows directories by appending `/` to anything that is a directory (rather than a file) and a `*` to anything that is an executable (i.e., a program). 318 | 319 | ```{bash} 320 | ls -F 321 | ``` 322 | 323 | 324 | Next we'll use multiple options to the `ls` command. `-l` shows extended information about files/directories. `-t` shows files/directories in order of the time at which they were last modified and `-r` shows in reverse order. Before I run `ls`, I'll create an empty file using the `touch` command. Given this, what file do you expect to be displayed last when you do the following? 325 | 326 | ```{bash} 327 | touch myfile 328 | ls -lrt 329 | ``` 330 | 331 | While each command has its own syntax, there are some rules usually 332 | followed. Generally, executing a command consists of four things: 333 | 334 | - the command 335 | - command option(s) 336 | - argument(s) 337 | - line acceptance 338 | 339 | Here's an example: 340 | 341 | ```{bash} 342 | wc -l example.txt 343 | ``` 344 | 345 | In the above example, `wc` is the command, `-l` is a command option 346 | specifying to count the number of lines, `example.txt` is the argument, and the 347 | line acceptance is indicated by hitting the `Enter` key at the end of 348 | the line. 349 | 350 | So that invocation counts the number of lines in the file named `example.txt`. 351 | 352 | The spaces are required and distinguish the different parts of the invocation. For this reason, 353 | it's generally a bad idea to have spaces within file names on a UNIX system. But if you do, you can 354 | use quotation marks to distinguish the file name, e.g., 355 | 356 | ```{bash} 357 | echo "some text" > "filename with spaces.txt" 358 | ls -l "filename with spaces.txt" 359 | ``` 360 | 361 | Also, capitalization matters. For example `-l` and `-L` are different options. 362 | 363 | Note that options, arguments, or both might not be included in some cases. Recall that we've used `ls` 364 | without either options or arguments. 365 | 366 | Arguments are usually one or more files or directories. 367 | 368 | ## 4.2 Options 369 | 370 | Often we can specify an option either in short form (as with `-l` here) 371 | or long form (`--lines` here), as seen in the following equivalent invocations: 372 | 373 | ```{bash} 374 | wc -l example.txt 375 | wc --lines example.txt 376 | ``` 377 | 378 | 379 | We can also ask for the number of characters with the `-m` option, which can 380 | be combined with the `-l` option equivalently in two ways: 381 | 382 | ```{bash} 383 | wc -lm example.txt 384 | wc -l -m example.txt 385 | ``` 386 | 387 | 388 | Options will often take values, e.g., if we want to get the first two lines of the file, 389 | the following invocations are equivalent: 390 | 391 | ```{bash} 392 | head -n 2 example.txt 393 | head --lines=2 example.txt 394 | head --lines 2 example.txt 395 | ``` 396 | 397 | 398 | ## 4.3 Comments 399 | 400 | Anything that follows `#` is a comment and is ignored. 401 | 402 | ```{bash} 403 | # This is ignored 404 | ls # Everything after the # is ignored 405 | ``` 406 | 407 | ## 4.4 Getting help with UNIX commands 408 | 409 | Essentially all UNIX commands have help information (called a man page), accessed using `man`. We won't show the results here as they are rather long. 410 | 411 | ```{bash} 412 | #| eval: false 413 | man ls 414 | ``` 415 | 416 | You should try it yourself to practice viewing man pages. Once you are in the man page, you can navigate by hitting the space bar (to scroll down) and the up and down arrows. You can search by typing `/`, typing the string you want to search for and hitting ``. You can use `n` and `p` for the next and previous search hits and `q` to quit out of the search. 417 | 418 | Unfortunately man pages are often quite long, hard to understand, and without examples. But the information you need is usually there if you take the time to look for it. 419 | 420 | Also, UNIX commands as well as other programs run from the command line often provide help information via the `--help` option: 421 | 422 | ```{bash} 423 | #| eval: false 424 | ls --help 425 | ``` 426 | 427 | Again, we're not showing the output as it is rather long. 428 | 429 | ## 4.5 Seeing if a command or program is available 430 | 431 | You can see if a command or program is installed (and where it is installed) using `type`. 432 | 433 | ```{bash} 434 | type grep 435 | type R 436 | type python 437 | ``` 438 | 439 | # 5 Working with files 440 | 441 | ## 5.1 Copying and removing files 442 | 443 | You'll often want to make a copy of a file, move it between directories, or remove it. 444 | 445 | ```{bash} 446 | cp 447 | cp example.txt example-new.txt 448 | mv example-new.txt /tmp/. 449 | cd /tmp 450 | ls -lrt 451 | ``` 452 | 453 | When we moved the file, the use of `/.` in `/tmp/.` indicates we want to use the same name as the original file. 454 | 455 | 456 | ```{bash} 457 | cd /tmp 458 | rm example-new.txt 459 | ls -lrt 460 | ``` 461 | 462 | :::{.callout-important title="`rm` is forever"} 463 | I used `rm` above to remove the file. Be very careful about removing files - there is no Trash folder in UNIX - once a file is removed, it's gone for good. 464 | ::: 465 | 466 | The `mv` command is also used if you want to rename a file. 467 | 468 | ```{bash} 469 | cd ~/tutorial-unix-basics 470 | mv example.txt silly_example.txt 471 | ls 472 | ``` 473 | 474 | 475 | We can copy and remove entire directories. The `-p` flag preserves the time stamp and other information associated with the files/directories, while the `-r` option copies recursively, such that the directory and all its contents (all child files and directories) are also copied. 476 | 477 | ```{bash} 478 | cp -pr assets /tmp/. # Copy the assets directory into /tmp. 479 | cd /tmp 480 | mkdir test 481 | mv assets test # Move the assets directory into the test directory. 482 | ls -l test/assets 483 | ``` 484 | 485 | ```{bash} 486 | rm -rf /tmp/test/assets # Remove the ps directory and anything contained within it. 487 | ls /tmp/test # This should be empty now. 488 | ``` 489 | 490 | You can use a variant of `cp` named `scp` to copy files between different UNIX-like machines. Suppose I have access to the machine *radagast.berkeley.edu* and that my user name on that machine is *scf1*. I can copy a file to that machine or from that machine as follows. 491 | 492 | (Note that I am not running the code in the process of generating this document.) 493 | 494 | ```{bash} 495 | #| eval: false 496 | cd ~/tutorial-unix-basics 497 | 498 | # FROM the machine you're on TO another machine 499 | # Copy the file to the Desktop subdirectory of the scf1 home directory on the remote machine 500 | scp example.txt username@machinename.berkeley.edu:~/Desktop/. 501 | 502 | # FROM another machine TO the machine you're on 503 | # Copy a file from the /tmp directory of the remote machine to a specific directory on this machine 504 | scp username@machinename.berkeley.edu:/tmp/data.txt ~/Downloads/. 505 | ``` 506 | 507 | 508 | ## 5.2 File names and extensions 509 | 510 | The format a file is in is determined by the **actual content** of the file. You can determine the file format using `file`: 511 | 512 | ```{bash} 513 | file index.qmd 514 | file /usr/local/linux/miniforge-3.12/lib/python3.12/site-packages/numpy/dtypes.py 515 | ``` 516 | 517 | 518 | In many cases, files have extensions such as `.csv` (for comma-separated text files), `.pdf` for PDFs, `.jpg` for JPEG files. The extension is a convention that helps us and programs distinguish different kinds of files and therefore know how to manipulate/interpret the files. 519 | 520 | :::{.callout-tip title="Filename extensions don't determine the file type" collapse="false"} 521 | The extension is just a convention -- changing the file name doesn't change the file format! 522 | 523 | So if make a copy of the `example.txt` file but name it `example.pdf`, we see that it's still just a simple text file even if I give it a name that would suggest it's a PDF. 524 | 525 | ```{bash} 526 | cp silly_example.txt silly_example.pdf 527 | cat silly_example.pdf 528 | ``` 529 | 530 | ```{bash} 531 | file silly_example.pdf 532 | ``` 533 | 534 | However, changing the extension may prevent a program from using the file simply because the program was written to assume that files in a certain format have a certain extension. 535 | 536 | ::: 537 | 538 | # 6 Other useful tools and information 539 | 540 | ## 6.1 Compressing and uncompressing files 541 | 542 | The `zip` utility compresses in a format compatible with zip files for Windows: 543 | 544 | ```{bash} 545 | zip -r assets.zip assets 546 | ``` 547 | 548 | ```{bash} 549 | ls -l assets.zip 550 | ``` 551 | 552 | `gzip` is a standard UNIX compression utility to compress individual files: 553 | 554 | ```{bash} 555 | cp assets/img/ls_format.png test.png 556 | ls -l test.png 557 | ``` 558 | 559 | Here we see that gzip can't compress the png file much, but it can help 560 | a lot with other formats. 561 | 562 | ```{bash} 563 | gzip test.png 564 | ls -l test.png.gz # Not much smaller than the uncompressed file. 565 | ``` 566 | 567 | 568 | 569 | Finally, the `tar` utility will combine multiple files and directories into a single archive. 570 | 571 | ```{bash} 572 | tar -cvf assets.tar assets 573 | ``` 574 | 575 | ```{bash} 576 | ls -l assets.tar 577 | ``` 578 | 579 | Adding the `-z` flag also gzips the result. In that case there was more noticeable compression. 580 | 581 | ```{bash} 582 | tar -cvzf assets.tgz assets 583 | ``` 584 | 585 | 586 | ```{bash} 587 | ls -l assets.tgz 588 | ``` 589 | 590 | Now let's move that *tarball* (as it is called) to a new directory and unzip and expand it using the -x flag. 591 | 592 | ```{bash} 593 | mv assets.tgz /tmp 594 | cd /tmp 595 | tar -xvzf assets.tgz 596 | ``` 597 | 598 | 599 | You can see the whole directory structure of what was archived has been recovered in the new location: 600 | ```{bash} 601 | ls -l /tmp/assets 602 | ``` 603 | 604 | 605 | ## 6.2 Disk usage 606 | 607 | You can can see how much disk space is being used versus available as follows. The 'Mounted on' column will generally identify the parts of the filesystem in a more user-friendly way than the 'Filesystem' column. 608 | 609 | ```{bash} 610 | df -h 611 | ``` 612 | 613 | 614 | In general, you'll want to look at the '/' line under `Mounted on`, and on standard UNIX machines possibly at '/tmp', '/home', and others. 615 | 616 | We can see usage in specific directories like this: 617 | 618 | ```{bash} 619 | cd assets 620 | du -h 621 | ``` 622 | 623 | 624 | Here we see that the total usage is about a bit less than 700 KB, with, for example, about 70 KB of that in the `img` subdirectory. 625 | 626 | If we only want a summary of usage for each top-level subdirectory, rather than showing all nested subdirectories: 627 | 628 | ```{bash} 629 | cd ~/tutorial-unix-basics 630 | du -h -d 1 631 | ``` 632 | 633 | 634 | ## 6.3 Machine information 635 | 636 | Linux machines (but not Macs) have system information provided in a few special files. 637 | 638 | `/proc/cpuinfo` shows information on each processor. 639 | 640 | ```{bash} 641 | head -n 30 /proc/cpuinfo 642 | ``` 643 | 644 | 645 | This indicates there are at least two processors -- numbered 0 and 1 (we'd need to see the whole file to see if there are more). Each is an Intel Core i7. 646 | 647 | 648 | This file has information on the memory available: 649 | 650 | ```{bash} 651 | head -n 10 /proc/meminfo 652 | ``` 653 | 654 | 655 | The key line is the *MemTotal* line, indicating 132 GB of RAM. 656 | 657 | ```{bash} 658 | cat /etc/issue 659 | ``` 660 | 661 | We're running Ubuntu version 22.04. 662 | 663 | We can also use commands to get information: 664 | 665 | ```{bash} 666 | nproc # how many processors? 667 | ``` 668 | 669 | 670 | # 7 The shell 671 | 672 | The shell provides a number of useful shortcuts, of which we highlight a couple here. 673 | 674 | ## 7.1 Tab completion 675 | 676 | The shell will try to auto-complete the names of commands/programs or of files when you type part of the name and then hit ``. This can save quite a bit of typing, particularly for long file names. 677 | 678 | 679 | ## 7.2 Keyboard shortcuts 680 | 681 | You can navigate within a line using the usual arrows but also: 682 | 683 | * `Ctrl-a` moves to the beginning of the line 684 | * `Ctrl-e` moves to the end of the line 685 | * `Ctrl-k` deletes the rest of the line starting at the cursor 686 | * `Ctrl-y` pastes in whatever was deleted previously with `Ctrl-k` 687 | * `Ctrl-r` enables an [interactive history search](http://www.techrepublic.com/article/keyboard-shortcuts-in-bash-and-zsh/) 688 | 689 | ## 7.3 Command history 690 | 691 | The up and down arrow keys will move you through the history of commands you have entered in the terminal. So you can recover something you typed previously and then directly run it again, or edit it and then run the modified version. You run the command by pressing ``, which you can do regardless of where your cursor currently is on the line you are editing. 692 | 693 | There's also lots more functionality along these lines that we won't go into here. 694 | 695 | ## 7.4 Saving your code as a shell script 696 | 697 | Often (particularly as you learn more sophisticated shell functionality) you will want to save your shell syntax in the form of a code file, called a script, that you could run another time. 698 | 699 | For example, suppose you often need to do the following series of steps: 700 | ```{bash} 701 | #| eval: false 702 | cd 703 | tar -cvzf assets.tgz assets 704 | mv assets.tgz /tmp 705 | cd /tmp 706 | tar -xvzf assets.tgz 707 | ``` 708 | 709 | You can put those lines into a file, say, `mv_assets.sh`, which will generally end in .sh. 710 | 711 | Then we can run the code in the file as follows. (Results not shown here.) 712 | 713 | ```{bash} 714 | #| eval: false 715 | chmod ugo+x mv_assets.sh # Make the script executable by everyone. 716 | ./mv_assets.sh # Run it. 717 | ``` 718 | 719 | The initial `./` is needed because UNIX is not expecting there to be an executable file in this particular directory. 720 | 721 | You'll generally want to have the first line of your shell scripts indicate the shell to be used to execute the script, so you'd want to put `#!/bin/bash` as the first line of `mv_assets.sh`. 722 | 723 | # 8 Practice questions 724 | 725 | 1) Try to run the following command `mkdir ~/projects/drought`. It will fail. Look in the help information on `mkdir` to figure out how to make it work without first creating the `projects` directory. 726 | 727 | 2) Figure out how to list out the files in a directory in order of decreasing file size, as a way to see easily what the big files are that are taking up the most space. Modify this command to get the result in the ascending order. 728 | 729 | 3) Use both `zip` and `tar -cvzf` to compress the `tutorial-unix-basics` directory. Is one much smaller than the other? 730 | 731 | 4) Figure out how to print out free disk space in terms of megabytes. 732 | 733 | 5) The `ls` command is itself an executable installed on the system. Where is it located? 734 | 735 | 6) Where is `gzip` installed on the system? What are some other commands/executables that are installed in the same directory? 736 | 737 | 7) Practice with moving/removing/copying. Make a copy of the `tutorial-unix-basics` directory (and all its contents) in `/tmp`. Now use `cd` to go into the copied directory. Remove the `/tmp/tutorial-unix-basics/.git` directory. Now run `git status`. Congratulations, you should discover that you've turned a directory that is a Git repository into a directory that is not considered a git repository. 738 | 739 | ```{bash} 740 | #| include: false 741 | mv silly_example.txt example.txt 742 | rm assets.{tar,zip} silly_example.pdf test.png.gz 743 | ``` 744 | -------------------------------------------------------------------------------- /_freeze/index/execute-results/html.json: -------------------------------------------------------------------------------- 1 | { 2 | "hash": "cb945d04e3af3d2decb8c0826a0e6610", 3 | "result": { 4 | "engine": "knitr", 5 | "markdown": "---\ntitle: The basics of working on the UNIX command line\ndate: 2024-10-31\nformat:\n html:\n theme: cosmo\n css: assets/styles.css\n toc: true\n code-copy: true\n code-block-bg: true\n code-block-border-left: \"#31BAE9\" \nexecute:\n freeze: auto\nengine: knitr\nipynb-shell-interactivity: all\ncode-overflow: wrap\n---\n\n\n\n\n\n\n# 1 Introduction\n\n## 1.1 This Tutorial\n\n\nThis tutorial covers the basics of navigating in a UNIX-like (e.g., Linux or MacOs) environment. In particular, it covers using the UNIX command line interface, a powerful way to carry out operations on a computer and to automate tasks. Being familiar with operating on the command line will allow you (with some practice and training) to do things more quickly and in a way that can be reproduced later. That's hard or impossible to do if you are doing point-and-click or drag-and-drop operations in a File Manager or Finder window.\n\nMaterials for this tutorial, including the Quarto Markdown file that was used to create this document are [available on GitHub](https://github.com/berkeley-scf/tutorial-unix-basics).\n\nSoftware 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). Episodes 1-3 (the first 20 minutes) cover the material that is in this tutorial.\n\n:::{.callout-note title=\"License\"}\nThis tutorial by Christopher Paciorek is licensed under a Creative Commons Attribution 3.0 Unported License.\n:::\n\n\n## 1.2 The shell\n\nOperating on the UNIX command line is also known as \"using the terminal\" and \"using the shell\".\n\nThe shell is the UNIX program that you interact with when in a terminal window interacting 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. 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. zsh is an extension of bash, so you should be able to use zsh based on this tutorial.\n\nI've generated this document based on using the bash shell on a computer running the Ubuntu Linux version 22.04 operating system, but you should be able to replicate most of the steps in this tutorial in other UNIX command line environments, ideally using the bash or zsh shells. \n\n## 1.3 Accessing a UNIX command line interface\n\nHere are some options for accessing a UNIX command line interface:\n\n - MacOS: If you'd like to work on your own Mac, you'll find the Terminal under\n `Applications -> Utilities -> Terminal`.\n - Windows:\n - If you have a sufficiently new version of Windows 10, you can use the [Windows Subsystem for Linux](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide), which will provide you with an Ubuntu shell running bash on your own machine.\n - If you have access to remote machines running Linux, you can login to them using programs such as MobaXTerm and Putty. Once logged in, you'll find yourself in a Terminal window on the remote machine.\n - JupyterHub: If you have access to a JupyterHub, you will likely be able to start a Terminal session under \"New\".\n - Cloud-based options: You could also try a cloud service such as Google [Cloud Shell](https://shell.cloud.google.com).\n\n:::{.callout-warning title=\"Don't use Git Bash for this tutorial\"}\nYou probably shouldn't use `Git Bash` to follow this tutorial as its functionality is limited. \n:::\n\nOnce you're in a Terminal window, you'll be interacting with the shell and you can enter commands to get information and work with the system. Commands often have optional arguments (flags) that are specified with a minus in front of them, as we'll see. \n\n## 1.4 Getting started\n\nOnce we are in a terminal, we'll see the \"prompt\", which indicates that the shell is waiting for us to enter commands. Sometimes the prompt is just `$`:\n\n:::{.cell-output}\n$\n:::\n\nbut often it contains information about the username of the current user and the directory on the filesystem that we are in. For example, here a prompt that shows that the current user is 'scflocal', on the machine named 'gandalf' in the 'tutorial-unix-basics' (sub)directory in the user's home directory (indicated by `~`):\n\n:::{.cell-output}\nscflocal@gandalf:~/tutorial-unix-basics>\n:::\n\n:::{.callout-note title=\"Tutorial code formatting\"}\nIn the remainder of this tutorial, you won't see the prompt in front of the commands. All commands will appear in a grey background, with the output (if any) following the code.\n:::\n\n\n:::{.callout-note title=\"When the shell is waiting for more information\"}\nNote that if you simply see `>` instead of the usual prompt, that means the shell thinks you haven't finished entering your command (usually that you haven't finished entering a string) and is expecting more input from you. If you see a newline but nothing else, the shell probably expects you to enter some text for it to process.\n\nIf you're not sure what to do, type `Ctrl-c` (the control key and 'c' at the same time) to get back to the usual prompt.\n:::\n\nLet's start by running a command, `whoami`, that prints out the username of the current user:\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nwhoami\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nscflocal\n```\n\n\n:::\n:::\n\n\n\n\n\n\n# 2 Using `git` for version control\n\nWe'll discuss `git` briefly, both because it is an important and useful tool, and because it's the easiest way for us to get a set of files to work with in this tutorial. \n\nGit is an important tool to become familiar with, at least at the basic level. Git allows you to share files between different computers and different people and for people to collaborate on projects together. In particular, it is a version control tool that allows you to have different versions of your files and to go back to earlier versions of your files. Git stores the files for a project in a *repository*. \n\nFor our purposes here, we'll simply use Git to download materials from GitHub, a website that stores Git repositories in the cloud. \n\nFirst we'll download the materials for this tutorial.\n\nTo *clone* (i.e., copy) a repository (in this case from GitHub) we do the following. Note that `berkeley-scf` is the *organization* and `tutorial-unix-basics` is the *repository*. Note that everything below that follows the `#` symbol is a comment and not executed.\n\nHere we'll first use the `cd` command (for \"change directory\") to go to our home directory and then use `git clone` to download materials to a subdirectory (which will be called `tutorial-unix-basics`) within our home directory. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd\ngit clone https://github.com/berkeley-scf/tutorial-unix-basics\n```\n:::\n\n\n\n::: {.cell-output}\n```\nCloning into 'tutorial-unix-basics'...\nremote: Enumerating objects: 387, done.\nremote: Counting objects: 100% (66/66), done.\nremote: Compressing objects: 100% (45/45), done.\nremote: Total 387 (delta 37), reused 46 (delta 19), pack-reused 321 (from 1)\nReceiving objects: 100% (387/387), 779.53 KiB | 5.27 MiB/s, done.\nResolving deltas: 100% (199/199), done.\n```\n:::\n\nNow suppose that whoever controls the repository makes some changes to the materials in the repository online and you want an updated copy of the repository on your computer. Simply use `cd` to go into any directory in the repository materials on your computer and run `git pull`.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd tutorial-unix-basics\n```\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\ngit pull\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nAlready up to date.\n```\n\n\n:::\n:::\n\n\n\n\nIn this case, since no changes had been made, git simply reports that things are up-to-date.\n\nWe'll discuss how to use `cd` in more detail in the next section.\n\n# 3 Files and directories\n\n## 3.1 Moving around and listing information\n\nWe'll start by thinking about the filesystem, which organizes our information/data into files on the computer's disk.\n\nAnytime you are at the UNIX command line, you have a *working directory*, which is your current location in the file system. \n\nHere's how you can see where you are using the `pwd` (\"print working directory\") command:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal/tutorial-unix-basics\n```\n\n\n:::\n:::\n\n\n\n\nand here's how you use `ls` to list the files (and subdirectories) in the working directory...\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nls\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets\n_config.yml\nexample.text\nexample.txt\nfilename with spaces.txt\n_freeze\n_includes\nindex.qmd\nindex.rmarkdown\n_layouts\nmv_assets.sh\nmyfile\nname of my file with spaces.txt\n_quarto.yml\nREADME.md\n_sass\n_site\n```\n\n\n:::\n:::\n\n\n\n\nNow suppose I want to be in a different directory so I can see what is there or do things to the files in that directory.\n\nThe command you need is `cd` and an important concept you need to become familiar with is the notion of 'relative' versus 'absolute' *path*. A path is the set of nested directories that specify a location of interest on the filesystem.\n\nFirst let's go to our home directory, which is generally where our files will be. Simply running `cd` will do that.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal\n```\n\n\n:::\n:::\n\n\n\n\n\nNow let's go into a subdirectory. We can use `cd` with the name of the subdirectory. The subdirectory is found 'relative' to our working directory, i.e., found from where we currently are.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd tutorial-unix-basics\npwd\n```\n:::\n\n\n\n\n:::{.cell-output}\n/home/scflocal/tutorial-unix-basics\n:::\n\nWe could also navigate through nested subdirectories. For example, after going back to our home directory, let's go to the `assets` subdirectory of the `tutorial-unix-basics` subdirectory. The `/` is a separate character that distinguishes the nested subdirectories.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd\ncd tutorial-unix-basics/assets\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal/tutorial-unix-basics/assets\n```\n\n\n:::\n:::\n\n\n\n\n\nYou can access the parent directory of any directory using `..`:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\npwd\ncd ..\npwd\n```\n:::\n\n\n\n:::{.cell-output}\n/home/scflocal/tutorial-unix-basics/assets\n/home/scflocal/tutorial-unix-basics\n:::\n\n\nWe can get more complicated in our use of `..` with relative paths. Here we'll go up a directory and then down to a different subdirectory.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd assets\ncd ../_includes \npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal/tutorial-unix-basics/_includes\n```\n\n\n:::\n:::\n\n\n\n\n\nAnd here we'll go up two directories and then down to another subdirectory.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd ../../Desktop # go up two directories and down\npwd\n```\n:::\n\n\n\n\n:::{.cell-output}\n\n/home/scflocal/Desktop\n:::\n\nAll of the above examples used relative paths to navigate based on your working directory at the moment you ran the command.\n\nWe can instead use absolute paths so that it doesn't matter where we are when we run the command. Specifying an absolute path is done by having your path start with `/`, such as `/home/scflocal`. If the path doesn't start with `/` then it is interpreted as being a relative path, relative to your working directory. Here we'll go to the `units` subdirectory again, but this time using an absolute path. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd /home/scflocal/tutorial-unix-basics/assets\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal/tutorial-unix-basics/assets\n```\n\n\n:::\n:::\n\n\n\n\n:::{.callout-warning title=\"Absolute paths are not robust\"}\nNote that using absolute paths in scripts is generally a bad idea because the script wouldn't generally work correctly if run on a different machine (which will generally have a different filesystem structure) or as a different user (who will have a different home directory).\n:::\n\n## 3.2 The filesystem\n\nThe filesystem is basically a upside-down tree.\n\nFor example, if we just consider the `tutorial-unix-basics` directory, we can see the tree structure using `tree`:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ntree\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n.\n├── assets\n│   ├── css\n│   │   └── style.scss\n│   ├── fonts\n│   │   ├── Noto-Sans-700\n│   │   │   ├── Noto-Sans-700.eot\n│   │   │   ├── Noto-Sans-700.svg\n│   │   │   ├── Noto-Sans-700.ttf\n│   │   │   ├── Noto-Sans-700.woff\n│   │   │   └── Noto-Sans-700.woff2\n│   │   ├── Noto-Sans-700italic\n│   │   │   ├── Noto-Sans-700italic.eot\n│   │   │   ├── Noto-Sans-700italic.svg\n│   │   │   ├── Noto-Sans-700italic.ttf\n│   │   │   ├── Noto-Sans-700italic.woff\n│   │   │   └── Noto-Sans-700italic.woff2\n│   │   ├── Noto-Sans-italic\n│   │   │   ├── Noto-Sans-italic.eot\n│   │   │   ├── Noto-Sans-italic.svg\n│   │   │   ├── Noto-Sans-italic.ttf\n│   │   │   ├── Noto-Sans-italic.woff\n│   │   │   └── Noto-Sans-italic.woff2\n│   │   └── Noto-Sans-regular\n│   │   ├── Noto-Sans-regular.eot\n│   │   ├── Noto-Sans-regular.svg\n│   │   ├── Noto-Sans-regular.ttf\n│   │   ├── Noto-Sans-regular.woff\n│   │   └── Noto-Sans-regular.woff2\n│   ├── img\n│   │   ├── logo.svg\n│   │   └── ls_format.png\n│   ├── js\n│   │   └── scale.fix.js\n│   ├── stat_bear.png\n│   └── styles.css\n├── _config.yml\n├── example.text\n├── example.txt\n├── filename with spaces.txt\n├── _freeze\n│   ├── index\n│   │   └── execute-results\n│   │   └── html.json\n│   └── site_libs\n│   └── clipboard\n│   └── clipboard.min.js\n├── _includes\n│   └── toc.html\n├── index.qmd\n├── index.rmarkdown\n├── _layouts\n│   └── default.html\n├── mv_assets.sh\n├── myfile\n├── name of my file with spaces.txt\n├── _quarto.yml\n├── README.md\n├── _sass\n│   ├── fonts.scss\n│   ├── jekyll-theme-minimal.scss\n│   ├── jekyll-theme-minimal.scss.bak\n│   ├── minimal.scss\n│   └── rouge-github.scss\n└── _site\n\n18 directories, 46 files\n```\n\n\n:::\n:::\n\n\n\n\nThe dot (`.`) means \"this directory\", so the top of the tree here is the `tutorial-unix-basics` directory itself, within which there are subdirectories, `asset`, `_includes`, `_layouts`, etc. Then within each of these are files and further subdirectories (as seen in the case of `assets`, which has subdirectories named `css` and `fonts`.)\n\nIf we consider the entire filesystem, the top, or root of the tree, is the `/` directory. Within `/` there are subdirectories, such as `/home` (which contains users' home directories where all of the files owned by a user are stored) and `/bin` (containing UNIX programs, aka 'binaries'). We'll use `ls` again, this time telling it the directory to operate on:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nls /\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\naccounts\napp\nbin\nboot\ndev\netc\nhome\nlib\nlib32\nlib64\nlibx32\nlost+found\nmedia\nmirror\nmnt\nopt\npool0\nproc\nroot\nrun\nsbin\nscratch\nserver\nsrv\nswap.img\nsys\nsystem\ntmp\nusr\nvar\n```\n\n\n:::\n:::\n\n\n\n\n\nIf there is a user named `scflocal`, everything specific to that user would be stored in the user's *home directory*. Here that is `/home/scflocal`, but the exact location may differ on different systems. The shortcut `~scflocal` refers to the `scflocal` home directory, `/home/scflocal`. If you are the `scflocal` user, you can also refer to your home directory by the shortcut `~`.\n\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nls /home\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nscflocal\nshiny\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd /home/scflocal\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal\n```\n\n\n:::\n:::\n\n\n\n\nGo to the home directory of the current user (which happens to be the `scflocal` user):\n\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd ~\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal\n```\n\n\n:::\n:::\n\n\n\n\n\nGo to the home directory of the scflocal user explicitly:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd ~scflocal\npwd\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n/home/scflocal\n```\n\n\n:::\n:::\n\n\n\n\n\nAnother useful directory is `/tmp`, which is a good place to put temporary files that you only need briefly and don't need to save. These will disappear when a machine is rebooted. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd /tmp\nls\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets\nassets.tgz\nquarto-session71f9ea197eacbf29\nRtmpMQcgrV\nTemp-76c6318d-4f54-44d2-8bd9-d9a42eeeb7ce\ntest\n```\n\n\n:::\n:::\n\n\n\n\n\nWe can return to the most recent directory we were in like this:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd -\npwd\n```\n:::\n\n\n\n\n:::{.cell-output}\n/home/scflocal\n:::\n\n# 4 Using commands\n\n## 4.1 Overview\n\nLet's look more at various ways to use commands. We just saw the `ls` command. Here's one way we can modify the behavior of the command by passing a command option. Here the `-F` option (also called a 'flag') shows directories by appending `/` to anything that is a directory (rather than a file) and a `*` to anything that is an executable (i.e., a program).\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nls -F\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets/\n_config.yml\nexample.text\nexample.txt\nfilename with spaces.txt\n_freeze/\n_includes/\nindex.qmd\nindex.rmarkdown\n_layouts/\nmv_assets.sh\nmyfile\nname of my file with spaces.txt\n_quarto.yml\nREADME.md\n_sass/\n_site/\n```\n\n\n:::\n:::\n\n\n\n\n\nNext we'll use multiple options to the `ls` command. `-l` shows extended information about files/directories. `-t` shows files/directories in order of the time at which they were last modified and `-r` shows in reverse order. Before I run `ls`, I'll create an empty file using the `touch` command. Given this, what file do you expect to be displayed last when you do the following?\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ntouch myfile\nls -lrt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\ntotal 112\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 _sass\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 _layouts\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 _includes\n-rw-r--r-- 1 scflocal scflocal 291 Oct 29 15:17 _config.yml\n-rw-r--r-- 1 scflocal scflocal 567 Oct 30 16:35 README.md\n-rw-r--r-- 1 scflocal scflocal 6 Oct 30 16:38 name of my file with spaces.txt\n-rw-r--r-- 1 scflocal scflocal 52 Oct 30 16:45 example.text\n-rw-r--r-- 1 scflocal scflocal 91 Oct 30 17:00 mv_assets.sh\n-rw-r--r-- 1 scflocal scflocal 51 Oct 30 17:03 example.txt\ndrwxr-xr-x 4 scflocal scflocal 4096 Oct 30 17:18 _freeze\ndrwxr-xr-x 6 scflocal scflocal 4096 Oct 31 13:54 assets\n-rw-r--r-- 1 scflocal scflocal 531 Oct 31 14:34 _quarto.yml\n-rw-r--r-- 1 scflocal scflocal 10 Oct 31 14:38 filename with spaces.txt\n-rw-r--r-- 1 scflocal scflocal 26755 Oct 31 14:42 index.qmd\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 31 14:42 _site\n-rw-r--r-- 1 scflocal scflocal 27079 Oct 31 14:42 index.rmarkdown\n-rw-r--r-- 1 scflocal scflocal 0 Oct 31 14:42 myfile\n```\n\n\n:::\n:::\n\n\n\n\nWhile each command has its own syntax, there are some rules usually\nfollowed. Generally, executing a command consists of four things:\n\n - the command\n - command option(s)\n - argument(s) \n - line acceptance\n \nHere's an example:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nwc -l example.txt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n4 example.txt\n```\n\n\n:::\n:::\n\n\n\n\nIn the above example, `wc` is the command, `-l` is a command option\nspecifying to count the number of lines, `example.txt` is the argument, and the\nline acceptance is indicated by hitting the `Enter` key at the end of\nthe line.\n\nSo that invocation counts the number of lines in the file named `example.txt`.\n\nThe spaces are required and distinguish the different parts of the invocation. For this reason,\nit's generally a bad idea to have spaces within file names on a UNIX system. But if you do, you can\nuse quotation marks to distinguish the file name, e.g.,\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\necho \"some text\" > \"filename with spaces.txt\"\nls -l \"filename with spaces.txt\"\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n-rw-r--r-- 1 scflocal scflocal 10 Oct 31 14:42 filename with spaces.txt\n```\n\n\n:::\n:::\n\n\n\n\nAlso, capitalization matters. For example `-l` and `-L` are different options.\n\nNote that options, arguments, or both might not be included in some cases. Recall that we've used `ls`\nwithout either options or arguments.\n\nArguments are usually one or more files or directories.\n\n## 4.2 Options\n\nOften we can specify an option either in short form (as with `-l` here)\nor long form (`--lines` here), as seen in the following equivalent invocations:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nwc -l example.txt\nwc --lines example.txt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n4 example.txt\n4 example.txt\n```\n\n\n:::\n:::\n\n\n\n\n\nWe can also ask for the number of characters with the `-m` option, which can\nbe combined with the `-l` option equivalently in two ways:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nwc -lm example.txt\nwc -l -m example.txt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n 4 51 example.txt\n 4 51 example.txt\n```\n\n\n:::\n:::\n\n\n\n\n\nOptions will often take values, e.g., if we want to get the first two lines of the file,\nthe following invocations are equivalent:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nhead -n 2 example.txt\nhead --lines=2 example.txt\nhead --lines 2 example.txt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nHello there.\nThis is a file\nHello there.\nThis is a file\nHello there.\nThis is a file\n```\n\n\n:::\n:::\n\n\n\n\n\n## 4.3 Comments\n\nAnything that follows `#` is a comment and is ignored.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\n# This is ignored\nls # Everything after the # is ignored\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets\n_config.yml\nexample.text\nexample.txt\nfilename with spaces.txt\n_freeze\n_includes\nindex.qmd\nindex.rmarkdown\n_layouts\nmv_assets.sh\nmyfile\nname of my file with spaces.txt\n_quarto.yml\nREADME.md\n_sass\n_site\n```\n\n\n:::\n:::\n\n\n\n\n## 4.4 Getting help with UNIX commands\n\nEssentially all UNIX commands have help information (called a man page), accessed using `man`. We won't show the results here as they are rather long.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nman ls\n```\n:::\n\n\n\n\nYou should try it yourself to practice viewing man pages. Once you are in the man page, you can navigate by hitting the space bar (to scroll down) and the up and down arrows. You can search by typing `/`, typing the string you want to search for and hitting ``. You can use `n` and `p` for the next and previous search hits and `q` to quit out of the search.\n\nUnfortunately man pages are often quite long, hard to understand, and without examples. But the information you need is usually there if you take the time to look for it.\n\nAlso, UNIX commands as well as other programs run from the command line often provide help information via the `--help` option:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nls --help\n```\n:::\n\n\n\n\nAgain, we're not showing the output as it is rather long.\n\n## 4.5 Seeing if a command or program is available\n\nYou can see if a command or program is installed (and where it is installed) using `type`.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ntype grep\ntype R\ntype python\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\ngrep is /usr/bin/grep\nR is /usr/bin/R\npython is /usr/local/linux/miniforge-3.12/bin/python\n```\n\n\n:::\n:::\n\n\n\n\n# 5 Working with files\n\n## 5.1 Copying and removing files\n\nYou'll often want to make a copy of a file, move it between directories, or remove it. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncp \ncp example.txt example-new.txt\nmv example-new.txt /tmp/.\ncd /tmp\nls -lrt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\ncp: missing file operand\nTry 'cp --help' for more information.\ntotal 468\ndrwx------ 2 scflocal scflocal 4096 Oct 29 15:21 Temp-76c6318d-4f54-44d2-8bd9-d9a42eeeb7ce\ndrwxr-xr-x 6 scflocal scflocal 4096 Oct 31 13:54 assets\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 31 14:38 test\n-rw-r--r-- 1 scflocal scflocal 453183 Oct 31 14:38 assets.tgz\ndrwx------ 37 scflocal scflocal 4096 Oct 31 14:42 quarto-session71f9ea197eacbf29\ndrwx------ 2 scflocal scflocal 4096 Oct 31 14:42 RtmpMQcgrV\n-rw-r--r-- 1 scflocal scflocal 51 Oct 31 14:42 example-new.txt\n```\n\n\n:::\n:::\n\n\n\n\nWhen we moved the file, the use of `/.` in `/tmp/.` indicates we want to use the same name as the original file.\n\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd /tmp\nrm example-new.txt\nls -lrt\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\ntotal 464\ndrwx------ 2 scflocal scflocal 4096 Oct 29 15:21 Temp-76c6318d-4f54-44d2-8bd9-d9a42eeeb7ce\ndrwxr-xr-x 6 scflocal scflocal 4096 Oct 31 13:54 assets\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 31 14:38 test\n-rw-r--r-- 1 scflocal scflocal 453183 Oct 31 14:38 assets.tgz\ndrwx------ 37 scflocal scflocal 4096 Oct 31 14:42 quarto-session71f9ea197eacbf29\ndrwx------ 2 scflocal scflocal 4096 Oct 31 14:42 RtmpMQcgrV\n```\n\n\n:::\n:::\n\n\n\n\n:::{.callout-important title=\"`rm` is forever\"}\nI used `rm` above to remove the file. Be very careful about removing files - there is no Trash folder in UNIX - once a file is removed, it's gone for good.\n:::\n\nThe `mv` command is also used if you want to rename a file. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd ~/tutorial-unix-basics\nmv example.txt silly_example.txt\nls\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets\n_config.yml\nexample.text\nfilename with spaces.txt\n_freeze\n_includes\nindex.qmd\nindex.rmarkdown\n_layouts\nmv_assets.sh\nmyfile\nname of my file with spaces.txt\n_quarto.yml\nREADME.md\n_sass\nsilly_example.txt\n_site\n```\n\n\n:::\n:::\n\n\n\n\n\nWe can copy and remove entire directories. The `-p` flag preserves the time stamp and other information associated with the files/directories, while the `-r` option copies recursively, such that the directory and all its contents (all child files and directories) are also copied.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncp -pr assets /tmp/. # Copy the assets directory into /tmp.\ncd /tmp\nmkdir test\nmv assets test # Move the assets directory into the test directory.\nls -l test/assets\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nmkdir: cannot create directory ‘test’: File exists\ntotal 112\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 css\ndrwxr-xr-x 6 scflocal scflocal 4096 Oct 29 15:17 fonts\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 img\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 js\n-rw-r--r-- 1 scflocal scflocal 92106 Oct 30 17:10 stat_bear.png\n-rw-r--r-- 1 scflocal scflocal 69 Oct 31 13:54 styles.css\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\nrm -rf /tmp/test/assets # Remove the ps directory and anything contained within it.\nls /tmp/test # This should be empty now.\n```\n:::\n\n\n\n\nYou can use a variant of `cp` named `scp` to copy files between different UNIX-like machines. Suppose I have access to the machine *radagast.berkeley.edu* and that my user name on that machine is *scf1*. I can copy a file to that machine or from that machine as follows.\n\n(Note that I am not running the code in the process of generating this document.)\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd ~/tutorial-unix-basics\n\n# FROM the machine you're on TO another machine\n# Copy the file to the Desktop subdirectory of the scf1 home directory on the remote machine\nscp example.txt username@machinename.berkeley.edu:~/Desktop/.\n\n# FROM another machine TO the machine you're on\n# Copy a file from the /tmp directory of the remote machine to a specific directory on this machine\nscp username@machinename.berkeley.edu:/tmp/data.txt ~/Downloads/.\n```\n:::\n\n\n\n\n\n## 5.2 File names and extensions\n\nThe format a file is in is determined by the **actual content** of the file. You can determine the file format using `file`:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nfile index.qmd\nfile /usr/local/linux/miniforge-3.12/lib/python3.12/site-packages/numpy/dtypes.py\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nindex.qmd: exported SGML document, ASCII text, with very long lines (615)\n/usr/local/linux/miniforge-3.12/lib/python3.12/site-packages/numpy/dtypes.py: Python script, ASCII text executable\n```\n\n\n:::\n:::\n\n\n\n\n\nIn many cases, files have extensions such as `.csv` (for comma-separated text files), `.pdf` for PDFs, `.jpg` for JPEG files. The extension is a convention that helps us and programs distinguish different kinds of files and therefore know how to manipulate/interpret the files.\n\n:::{.callout-tip title=\"Filename extensions don't determine the file type\" collapse=\"false\"}\nThe extension is just a convention -- changing the file name doesn't change the file format!\n\nSo if make a copy of the `example.txt` file but name it `example.pdf`, we see that it's still just a simple text file even if I give it a name that would suggest it's a PDF.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncp silly_example.txt silly_example.pdf\ncat silly_example.pdf\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nHello there.\nThis is a file\nthat contains\n4 lines.\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\nfile silly_example.pdf\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nsilly_example.pdf: ASCII text\n```\n\n\n:::\n:::\n\n\n\n\nHowever, changing the extension may prevent a program from using the file simply because the program was written to assume that files in a certain format have a certain extension.\n\n:::\n\n# 6 Other useful tools and information\n\n## 6.1 Compressing and uncompressing files\n\nThe `zip` utility compresses in a format compatible with zip files for Windows:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nzip -r assets.zip assets\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n adding: assets/ (stored 0%)\n adding: assets/css/ (stored 0%)\n adding: assets/css/style.scss (stored 0%)\n adding: assets/js/ (stored 0%)\n adding: assets/js/scale.fix.js (deflated 62%)\n adding: assets/fonts/ (stored 0%)\n adding: assets/fonts/Noto-Sans-regular/ (stored 0%)\n adding: assets/fonts/Noto-Sans-regular/Noto-Sans-regular.ttf (deflated 34%)\n adding: assets/fonts/Noto-Sans-regular/Noto-Sans-regular.svg (deflated 66%)\n adding: assets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff2 (stored 0%)\n adding: assets/fonts/Noto-Sans-regular/Noto-Sans-regular.eot (deflated 0%)\n adding: assets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff (deflated 1%)\n adding: assets/fonts/Noto-Sans-700italic/ (stored 0%)\n adding: assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf (deflated 32%)\n adding: assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2 (stored 0%)\n adding: assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot (deflated 0%)\n adding: assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff (deflated 1%)\n adding: assets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.svg (deflated 68%)\n adding: assets/fonts/Noto-Sans-700/ (stored 0%)\n adding: assets/fonts/Noto-Sans-700/Noto-Sans-700.ttf (deflated 35%)\n adding: assets/fonts/Noto-Sans-700/Noto-Sans-700.eot (deflated 0%)\n adding: assets/fonts/Noto-Sans-700/Noto-Sans-700.svg (deflated 66%)\n adding: assets/fonts/Noto-Sans-700/Noto-Sans-700.woff2 (stored 0%)\n adding: assets/fonts/Noto-Sans-700/Noto-Sans-700.woff (deflated 1%)\n adding: assets/fonts/Noto-Sans-italic/ (stored 0%)\n adding: assets/fonts/Noto-Sans-italic/Noto-Sans-italic.svg (deflated 67%)\n adding: assets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff2 (stored 0%)\n adding: assets/fonts/Noto-Sans-italic/Noto-Sans-italic.eot (deflated 0%)\n adding: assets/fonts/Noto-Sans-italic/Noto-Sans-italic.ttf (deflated 31%)\n adding: assets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff (deflated 1%)\n adding: assets/stat_bear.png (deflated 18%)\n adding: assets/img/ (stored 0%)\n adding: assets/img/logo.svg (deflated 70%)\n adding: assets/img/ls_format.png (deflated 4%)\n adding: assets/styles.css (deflated 4%)\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\nls -l assets.zip\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n-rw-r--r-- 1 scflocal scflocal 444635 Oct 31 14:42 assets.zip\n```\n\n\n:::\n:::\n\n\n\n\n`gzip` is a standard UNIX compression utility to compress individual files:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncp assets/img/ls_format.png test.png\nls -l test.png\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n-rw-r--r-- 1 scflocal scflocal 52402 Oct 31 14:42 test.png\n```\n\n\n:::\n:::\n\n\n\n\nHere we see that gzip can't compress the png file much, but it can help\na lot with other formats.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ngzip test.png\nls -l test.png.gz # Not much smaller than the uncompressed file.\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n-rw-r--r-- 1 scflocal scflocal 50200 Oct 31 14:42 test.png.gz\n```\n\n\n:::\n:::\n\n\n\n\n\n\nFinally, the `tar` utility will combine multiple files and directories into a single archive. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ntar -cvf assets.tar assets\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets/\nassets/css/\nassets/css/style.scss\nassets/js/\nassets/js/scale.fix.js\nassets/fonts/\nassets/fonts/Noto-Sans-regular/\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.ttf\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.svg\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff2\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.eot\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff\nassets/fonts/Noto-Sans-700italic/\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.svg\nassets/fonts/Noto-Sans-700/\nassets/fonts/Noto-Sans-700/Noto-Sans-700.ttf\nassets/fonts/Noto-Sans-700/Noto-Sans-700.eot\nassets/fonts/Noto-Sans-700/Noto-Sans-700.svg\nassets/fonts/Noto-Sans-700/Noto-Sans-700.woff2\nassets/fonts/Noto-Sans-700/Noto-Sans-700.woff\nassets/fonts/Noto-Sans-italic/\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.svg\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff2\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.eot\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.ttf\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff\nassets/stat_bear.png\nassets/img/\nassets/img/logo.svg\nassets/img/ls_format.png\nassets/styles.css\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\nls -l assets.tar\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n-rw-r--r-- 1 scflocal scflocal 686080 Oct 31 14:42 assets.tar\n```\n\n\n:::\n:::\n\n\n\n\nAdding the `-z` flag also gzips the result. In that case there was more noticeable compression.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ntar -cvzf assets.tgz assets\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets/\nassets/css/\nassets/css/style.scss\nassets/js/\nassets/js/scale.fix.js\nassets/fonts/\nassets/fonts/Noto-Sans-regular/\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.ttf\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.svg\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff2\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.eot\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff\nassets/fonts/Noto-Sans-700italic/\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.svg\nassets/fonts/Noto-Sans-700/\nassets/fonts/Noto-Sans-700/Noto-Sans-700.ttf\nassets/fonts/Noto-Sans-700/Noto-Sans-700.eot\nassets/fonts/Noto-Sans-700/Noto-Sans-700.svg\nassets/fonts/Noto-Sans-700/Noto-Sans-700.woff2\nassets/fonts/Noto-Sans-700/Noto-Sans-700.woff\nassets/fonts/Noto-Sans-italic/\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.svg\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff2\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.eot\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.ttf\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff\nassets/stat_bear.png\nassets/img/\nassets/img/logo.svg\nassets/img/ls_format.png\nassets/styles.css\n```\n\n\n:::\n:::\n\n::: {.cell}\n\n```{.bash .cell-code}\nls -l assets.tgz\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n-rw-r--r-- 1 scflocal scflocal 453183 Oct 31 14:42 assets.tgz\n```\n\n\n:::\n:::\n\n\n\n\nNow let's move that *tarball* (as it is called) to a new directory and unzip and expand it using the -x flag. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nmv assets.tgz /tmp\ncd /tmp\ntar -xvzf assets.tgz\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nassets/\nassets/css/\nassets/css/style.scss\nassets/js/\nassets/js/scale.fix.js\nassets/fonts/\nassets/fonts/Noto-Sans-regular/\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.ttf\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.svg\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff2\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.eot\nassets/fonts/Noto-Sans-regular/Noto-Sans-regular.woff\nassets/fonts/Noto-Sans-700italic/\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.ttf\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff2\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.eot\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.woff\nassets/fonts/Noto-Sans-700italic/Noto-Sans-700italic.svg\nassets/fonts/Noto-Sans-700/\nassets/fonts/Noto-Sans-700/Noto-Sans-700.ttf\nassets/fonts/Noto-Sans-700/Noto-Sans-700.eot\nassets/fonts/Noto-Sans-700/Noto-Sans-700.svg\nassets/fonts/Noto-Sans-700/Noto-Sans-700.woff2\nassets/fonts/Noto-Sans-700/Noto-Sans-700.woff\nassets/fonts/Noto-Sans-italic/\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.svg\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff2\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.eot\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.ttf\nassets/fonts/Noto-Sans-italic/Noto-Sans-italic.woff\nassets/stat_bear.png\nassets/img/\nassets/img/logo.svg\nassets/img/ls_format.png\nassets/styles.css\n```\n\n\n:::\n:::\n\n\n\n\n\nYou can see the whole directory structure of what was archived has been recovered in the new location:\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nls -l /tmp/assets\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\ntotal 112\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 css\ndrwxr-xr-x 6 scflocal scflocal 4096 Oct 29 15:17 fonts\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 img\ndrwxr-xr-x 2 scflocal scflocal 4096 Oct 29 15:17 js\n-rw-r--r-- 1 scflocal scflocal 92106 Oct 30 17:10 stat_bear.png\n-rw-r--r-- 1 scflocal scflocal 69 Oct 31 13:54 styles.css\n```\n\n\n:::\n:::\n\n\n\n\n\n## 6.2 Disk usage\n\nYou can can see how much disk space is being used versus available as follows. The 'Mounted on' column will generally identify the parts of the filesystem in a more user-friendly way than the 'Filesystem' column.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ndf -h\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nFilesystem Size Used Avail Use% Mounted on\n/dev/sda2 59G 32G 25G 57% /\ntmpfs 63G 68M 63G 1% /dev/shm\ntmpfs 13G 23M 13G 1% /run\ntmpfs 5.0M 0 5.0M 0% /run/lock\ntmpfs 13G 28K 13G 1% /run/user/3173\ntmpfs 13G 28K 13G 1% /run/user/3520\ntmpfs 13G 28K 13G 1% /run/user/3417\ntmpfs 13G 28K 13G 1% /run/user/764\ntmpfs 13G 28K 13G 1% /run/user/3023\ntmpfs 13G 28K 13G 1% /run/user/3565\ntmpfs 13G 28K 13G 1% /run/user/3530\ntmpfs 13G 28K 13G 1% /run/user/3294\ntmpfs 13G 28K 13G 1% /run/user/3066\ntmpfs 13G 28K 13G 1% /run/user/3180\ntmpfs 13G 40K 13G 1% /run/user/3189\ntmpfs 13G 28K 13G 1% /run/user/3188\ntmpfs 13G 32K 13G 1% /run/user/3605\ntmpfs 13G 28K 13G 1% /run/user/3608\ntmpfs 13G 32K 13G 1% /run/user/3466\ntmpfs 13G 28K 13G 1% /run/user/3604\ntmpfs 13G 28K 13G 1% /run/user/3218\ntmpfs 13G 32K 13G 1% /run/user/3624\ntmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup\n/dev/sda3 59G 34G 22G 61% /var\n/dev/sda4 472G 2.7G 445G 1% /var/tmp\n/dev/sda5 1.3T 76G 1.1T 7% /tmp\noz.berkeley.edu:/pool0/system 6.0T 4.8T 1.3T 80% /system\noz.berkeley.edu:/pool0/scratch 37T 33T 4.3T 89% /scratch\noz.berkeley.edu:/pool0/accounts 66T 20T 47T 30% /accounts\n```\n\n\n:::\n:::\n\n\n\n\n\nIn general, you'll want to look at the '/' line under `Mounted on`, and on standard UNIX machines possibly at '/tmp', '/home', and others.\n\nWe can see usage in specific directories like this:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd assets\ndu -h\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n8.0K\t./css\n8.0K\t./js\n140K\t./fonts/Noto-Sans-regular\n140K\t./fonts/Noto-Sans-700italic\n140K\t./fonts/Noto-Sans-700\n132K\t./fonts/Noto-Sans-italic\n556K\t./fonts\n76K\t./img\n748K\t.\n```\n\n\n:::\n:::\n\n\n\n\n\nHere we see that the total usage is about a bit less than 700 KB, with, for example, about 70 KB of that in the `img` subdirectory.\n\nIf we only want a summary of usage for each top-level subdirectory, rather than showing all nested subdirectories:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd ~/tutorial-unix-basics\ndu -h -d 1\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n28K\t./_sass\n8.0K\t./_layouts\n4.0K\t./_site\n16K\t./_includes\n84K\t./_freeze\n748K\t./assets\n1.5M\t./.git\n172K\t./.quarto\n3.8M\t.\n```\n\n\n:::\n:::\n\n\n\n\n\n## 6.3 Machine information\n\nLinux machines (but not Macs) have system information provided in a few special files.\n\n`/proc/cpuinfo` shows information on each processor. \n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nhead -n 30 /proc/cpuinfo\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nprocessor\t: 0\nvendor_id\t: GenuineIntel\ncpu family\t: 6\nmodel\t\t: 45\nmodel name\t: Intel(R) Xeon(R) CPU E5-2609 0 @ 2.40GHz\nstepping\t: 7\nmicrocode\t: 0x71a\ncpu MHz\t\t: 2394.053\ncache size\t: 10240 KB\nphysical id\t: 0\nsiblings\t: 4\ncore id\t\t: 0\ncpu cores\t: 4\napicid\t\t: 0\ninitial apicid\t: 0\nfpu\t\t: yes\nfpu_exception\t: yes\ncpuid level\t: 13\nwp\t\t: yes\nflags\t\t: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx lahf_lm epb pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid xsaveopt dtherm arat pln pts md_clear flush_l1d\nvmx flags\t: vnmi preemption_timer invvpid ept_x_only ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple\nbugs\t\t: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit mmio_unknown\nbogomips\t: 4800.18\nclflush size\t: 64\ncache_alignment\t: 64\naddress sizes\t: 46 bits physical, 48 bits virtual\npower management:\n\nprocessor\t: 1\nvendor_id\t: GenuineIntel\n```\n\n\n:::\n:::\n\n\n\n\n\nThis indicates there are at least two processors -- numbered 0 and 1 (we'd need to see the whole file to see if there are more). Each is an Intel Core i7. \n\n\nThis file has information on the memory available:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nhead -n 10 /proc/meminfo\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nMemTotal: 131966464 kB\nMemFree: 22645656 kB\nMemAvailable: 98414788 kB\nBuffers: 588304 kB\nCached: 32359372 kB\nSwapCached: 1249372 kB\nActive: 28592240 kB\nInactive: 32685712 kB\nActive(anon): 3933376 kB\nInactive(anon): 24488076 kB\n```\n\n\n:::\n:::\n\n\n\n\n\nThe key line is the *MemTotal* line, indicating 132 GB of RAM.\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncat /etc/issue\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\nUbuntu 22.04.1 LTS \\n \\l\n```\n\n\n:::\n:::\n\n\n\n\nWe're running Ubuntu version 22.04.\n\nWe can also use commands to get information:\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nnproc # how many processors?\n```\n\n\n::: {.cell-output .cell-output-stdout}\n\n```\n8\n```\n\n\n:::\n:::\n\n\n\n\n\n# 7 The shell\n\nThe shell provides a number of useful shortcuts, of which we highlight a couple here.\n\n## 7.1 Tab completion\n\nThe shell will try to auto-complete the names of commands/programs or of files when you type part of the name and then hit ``. This can save quite a bit of typing, particularly for long file names. \n\n\n## 7.2 Keyboard shortcuts\n\nYou can navigate within a line using the usual arrows but also:\n\n* `Ctrl-a` moves to the beginning of the line\n* `Ctrl-e` moves to the end of the line\n* `Ctrl-k` deletes the rest of the line starting at the cursor\n* `Ctrl-y` pastes in whatever was deleted previously with `Ctrl-k`\n* `Ctrl-r` enables an [interactive history search](http://www.techrepublic.com/article/keyboard-shortcuts-in-bash-and-zsh/)\n\n## 7.3 Command history\n\nThe up and down arrow keys will move you through the history of commands you have entered in the terminal. So you can recover something you typed previously and then directly run it again, or edit it and then run the modified version. You run the command by pressing ``, which you can do regardless of where your cursor currently is on the line you are editing.\n\nThere's also lots more functionality along these lines that we won't go into here.\n\n## 7.4 Saving your code as a shell script\n\nOften (particularly as you learn more sophisticated shell functionality) you will want to save your shell syntax in the form of a code file, called a script, that you could run another time.\n\nFor example, suppose you often need to do the following series of steps:\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\ncd \ntar -cvzf assets.tgz assets\nmv assets.tgz /tmp\ncd /tmp\ntar -xvzf assets.tgz\n```\n:::\n\n\n\n\nYou can put those lines into a file, say, `mv_assets.sh`, which will generally end in .sh.\n\nThen we can run the code in the file as follows. (Results not shown here.)\n\n\n\n\n::: {.cell}\n\n```{.bash .cell-code}\nchmod ugo+x mv_assets.sh # Make the script executable by everyone.\n./mv_assets.sh # Run it.\n```\n:::\n\n\n\n\nThe initial `./` is needed because UNIX is not expecting there to be an executable file in this particular directory. \n\nYou'll generally want to have the first line of your shell scripts indicate the shell to be used to execute the script, so you'd want to put `#!/bin/bash` as the first line of `mv_assets.sh`.\n\n# 8 Practice questions\n\n1) Try to run the following command `mkdir ~/projects/drought`. It will fail. Look in the help information on `mkdir` to figure out how to make it work without first creating the `projects` directory.\n\n2) Figure out how to list out the files in a directory in order of decreasing file size, as a way to see easily what the big files are that are taking up the most space. Modify this command to get the result in the ascending order.\n\n3) Use both `zip` and `tar -cvzf` to compress the `tutorial-unix-basics` directory. Is one much smaller than the other?\n\n4) Figure out how to print out free disk space in terms of megabytes. \n\n5) The `ls` command is itself an executable installed on the system. Where is it located?\n\n6) Where is `gzip` installed on the system? What are some other commands/executables that are installed in the same directory?\n\n7) Practice with moving/removing/copying. Make a copy of the `tutorial-unix-basics` directory (and all its contents) in `/tmp`. Now use `cd` to go into the copied directory. Remove the `/tmp/tutorial-unix-basics/.git` directory. Now run `git status`. Congratulations, you should discover that you've turned a directory that is a Git repository into a directory that is not considered a git repository.\n\n\n\n\n\n", 6 | "supporting": [], 7 | "filters": [ 8 | "rmarkdown/pagebreak.lua" 9 | ], 10 | "includes": {}, 11 | "engineDependencies": {}, 12 | "preserve": {}, 13 | "postProcess": true 14 | } 15 | } -------------------------------------------------------------------------------- /assets/fonts/Noto-Sans-700/Noto-Sans-700.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 18 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 35 | 36 | 38 | 41 | 42 | 44 | 47 | 48 | 51 | 54 | 56 | 58 | 59 | 60 | 61 | 64 | 67 | 68 | 70 | 71 | 72 | 73 | 74 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 85 | 86 | 88 | 89 | 91 | 92 | 93 | 94 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 107 | 109 | 110 | 112 | 114 | 115 | 117 | 118 | 119 | 120 | 121 | 122 | 124 | 125 | 127 | 129 | 131 | 132 | 134 | 135 | 136 | 137 | 139 | 140 | 141 | 142 | 144 | 145 | 147 | 149 | 150 | 151 | 153 | 154 | 156 | 157 | 158 | 161 | 163 | 166 | 168 | 169 | 170 | 171 | 174 | 175 | 177 | 178 | 179 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 189 | 190 | 192 | 194 | 197 | 199 | 200 | 201 | 203 | 205 | 207 | 209 | 210 | 212 | 213 | 214 | 215 | 217 | 218 | 219 | 220 | 222 | 223 | 225 | 227 | 229 | 231 | 234 | 237 | 238 | 240 | 242 | 244 | 246 | 248 | 249 | 250 | 253 | 255 | 257 | 259 | 262 | 265 | 268 | 271 | 273 | 275 | 277 | 279 | 282 | 283 | 284 | 285 | 287 | 289 | 291 | 293 | 295 | 297 | 300 | 303 | 305 | 307 | 309 | 311 | 313 | 315 | 317 | 319 | 321 | 322 | 323 | 324 | 325 | 326 | 328 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | --------------------------------------------------------------------------------