diff --git a/assets/reference.pptx b/assets/reference.pptx new file mode 100644 index 0000000..fa8d635 Binary files /dev/null and b/assets/reference.pptx differ diff --git a/images/chess-logo.png b/images/chess-logo.png new file mode 100644 index 0000000..50caa2d Binary files /dev/null and b/images/chess-logo.png differ diff --git a/images/chess-logo.svg b/images/chess-logo.svg new file mode 100644 index 0000000..1d9c739 --- /dev/null +++ b/images/chess-logo.svg @@ -0,0 +1 @@ +CHESS Tower Logo FV \ No newline at end of file diff --git a/images/isi-logo.png b/images/isi-logo.png new file mode 100644 index 0000000..5012ce9 Binary files /dev/null and b/images/isi-logo.png differ diff --git a/images/renci-logo.png b/images/renci-logo.png new file mode 100644 index 0000000..8ca5367 Binary files /dev/null and b/images/renci-logo.png differ diff --git a/images/x-cite-logo-2.png b/images/x-cite-logo-2.png new file mode 100644 index 0000000..aa04718 Binary files /dev/null and b/images/x-cite-logo-2.png differ diff --git a/theme2/SF100/cheat-sheet.png b/theme2/SF100/cheat-sheet.png new file mode 100644 index 0000000..c190449 Binary files /dev/null and b/theme2/SF100/cheat-sheet.png differ diff --git a/theme2/SF100/commandline-slides.md b/theme2/SF100/commandline-slides.md deleted file mode 100644 index 01f6e73..0000000 --- a/theme2/SF100/commandline-slides.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: "Commmandline and Scripting" -# author: "Sajith Sasidharan" -date: last-modified -format: - revealjs: - theme: default - output-file: commandline-slides-revealjs.html - beamer: - # aspectratio: 32 - # navigation: horizontal - theme: default ---- - -# Linux - -## The command line - -# The shell - -## Bash - -## Environment variables - -# Files and directories - -## Directory navigation - -## Wildcards - -## The current working directory - -## Fun facts about file names - -## Standard input, output, and error - -## I/O redirection - -## Pipes - -## Symbolic links - -# Users and Groups - -## Permissions and ownership - -## Changing permissions - - -# Processes - -## Background and foreground processes - -## Terminating processes - -## Signals - -# Text editors - -# Shell Scripting - -# Terminal multiplexers diff --git a/theme2/SF100/linux-commandline-scripting.md b/theme2/SF100/linux-commandline-scripting.md index cc9bf4a..d09cf7d 100644 --- a/theme2/SF100/linux-commandline-scripting.md +++ b/theme2/SF100/linux-commandline-scripting.md @@ -1,4 +1,10 @@ -# Linux, Command Line, and Scripting +--- +title: "Linux, Command Line, and Scripting" +date: "2024-05-08" +date-modified: last-modified +aliases: + - "/theme2/SF100/" +--- The following notes assume that you are all set up to use your accounts on the CLASSE Linux systems. @@ -21,8 +27,8 @@ systems. Slides accompanying these notes are available in [HTML][html-slides] and [PDF][pdf-slides] formats. -[html-slides]: commandline-slides-revealjs.html -[pdf-slides]: commandline-slides.pdf +[html-slides]: slides.html +[pdf-slides]: slides.pdf ::: @@ -733,7 +739,7 @@ What if you want to discard `stdout` completely? You can redirect it to the special file `/dev/null`: ```{.bash} -[ssasidharan@lnx201 ~]$ ls -l >> ls-output.txt +[ssasidharan@lnx201 ~]$ ls -l > /dev/null ``` If you want to append `stdout` to a file instead of overwriting it, diff --git a/theme2/SF100/slides.css b/theme2/SF100/slides.css new file mode 100644 index 0000000..241da68 --- /dev/null +++ b/theme2/SF100/slides.css @@ -0,0 +1,13 @@ +#org-logos { + display: flex; + align-items: center; + justify-content: center; +} + +#org-logos img { + float: left; + width: 200px; + object-fit: cover; + display: inline-block; + margin: 0 20px 0 0; +} diff --git a/theme2/SF100/slides.md b/theme2/SF100/slides.md new file mode 100644 index 0000000..b38b6d0 --- /dev/null +++ b/theme2/SF100/slides.md @@ -0,0 +1,490 @@ +--- +title: "The commmand-line" +subtitle: "X-CITE 2024 workshop" +# author: "Sajith Sasidharan" +date: last-modified +format: + revealjs: + theme: default + # output-file: commandline-slides-revealjs.html + footer: | + + + Supported by the NSF awards + [OAC-2320373](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2320373), + [OAC-2320374](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2320374), + and + [OAC-2320375](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2320375). + + logo: ../../images/x-cite-logo-2.png + + template-partials: + - title-slide.html + css: + - slides.css + + pptx: + theme: default + slide-level: 2 + reference-doc: ../../assets/reference.pptx + + beamer: + # aspectratio: 32 + # navigation: horizontal + theme: default + slide-level: 2 + # logo: ../../images/x-cite-logo-2.png +--- + +# Preliminaries + +Getting into CLASSE Linux systems + +## Assumptions + +- You have your CLASSE accounts set up. + - Talk to CLASSE staff otherwise! + +- Options: + + - Use ssh + - Use NoMachine + - Use JupyterLab + + +## Use SSH + +![](lnx201.png) + +`ssh ${username}@lnx201.classe.cornell.edu` + + +## Use NoMachine + +![](nomachine.png) + + + + +## Use JupyterLab + +![](jupyter01.png) + + + + +# Linux, command line, etc. + +## Linux + +- A popular operating system. + - (Actually an OS kernel, plus userland from various other projects. + But those are details...) +- Unix-like, which traces back to 1969, therefore has accumulated + quirks. + - Expect "hysterical raisins". + +## `lnx201` + +- The Linux host we'll be using is `lnx201.classe.cornell.edu`. +- Runs a **distribution** called Scientific Linux. +- Good enough for general use. +- Do not run anything resource heavy on `lnx201`. + + +## The command line + +![](lnx201.png) + +- You will type **commands** in a **shell**, hint + {{}} key, and then things happen. + + + + +## Commands + +- Commands are either **programs** or **shell builtins**. +- Use one of these commands to read documentation: + + - `man ${command}` + - `info ${command}` + - or `${command} --help` (sometimes!) + +## The shell + +- A program that accepts commands, and passes those commands to the OS + to execute. +- A popular shell is `bash`, which is the default on `lnx201`. + + +## Bash + +- "Bourne-again shell" + - Based on an earlier Bourne shell, thus the "again". + - Developed by the [GNU project][gnu]. + - On `lnx201`, `/bin/bash` is the program. +- For documentation: `info bash` or `man bash`. + +[gnu]: http://gnu.org/ + + + + +# Files and directories + +Unix slogan: Everything is a file! + + +## Directory navigation + +```{.bash} +[ssasidharan@lnx201 ~]$ tree -d -L 1 / +/ +├── bin -> usr/bin +├── boot +├── cdat +├── cifs +├── cvmfs +├── dev +├── etc +├── home +├── lib -> usr/lib +├── lib64 -> usr/lib64 +├── media +├── misc +├── mnt +├── net +├── nfs +├── opt +├── proc +├── root +├── run +├── sbin -> usr/sbin +├── srv +├── sys +├── tmp +├── usr +└── var + +25 directories +``` + +## Your home directory + +- You have a "home" directory. +- Usually `/home/$USER` + - Also `$HOME` +- You can write your files and create directories here. + + + + +## The current working directory + +"Wherever you go, there you are" + +- At any time in the shell, you are "inside" a single directory, + called the **current working directory**. +- When you log in, your current work will be `/home/${username}`. +- You will use `cd` (change directory) to move around. +- Use the command `pwd` to find where you are. + + +## Absolute and relative paths + +- **Absolute path names** begin with the root directory, `/`. + - Example: `/home/ssasidharan/Documents/hello.txt` + +- **Relative paths** start with the working directory. + - Example: `./Documents/hello.txt` (or just `Documents/hello.txt`) + when I'm in my home directory. + +## Fun facts about file names + +- Names that begin with "." are "hidden". + - Omitted from directory listing when you do `ls`. + +- `.` and `..` are special directory names. + - `.` stands for the current directory. + - `..` stands for the directory above the current directory. + + +## More fun facts about file names + +- File and directory names are case sensitive. + - (Depends on filesystem, but that is a detail.) +- Better to avoid spaces in file names, because they are a hassle. + - Use `_` (underscore character) instead (example: `file_name`), or + CamelCase (example: `FileName`). + +## Wildcards + +Some characters are given special treatment: + +- `*` matches any set of characters. + + +```{.bash} +[ssasidharan@lnx201 ~]$ ls /usr/bin/ab* +/usr/bin/ab /usr/bin/abs2rel +``` + +- `?` matches any one character. + +```{.bash} +[ssasidharan@lnx201 ~]$ ls /usr/bin/?abc* +/usr/bin/kabc2mutt /usr/bin/kabcclient +``` + + +## Standard input, output, and error + +- Input is read from **standard input** (or `stdin`). +- Output is written to **standard output** (or `stdout`). +- Error messages are written to **standard error** (or `stderr`). + +::: {.callout-note} + +They are files too: `/dev/stdin`, `/dev/stdout`, and `/dev/stderr`. + +::: + +## I/O redirection + +You can redirect `stdout` to a file with `>` operator: + +```{.bash} +[ssasidharan@lnx201 ~]$ ls -l > ls-output.txt +``` + +Or append with `>>`: + +```{.bash} +[ssasidharan@lnx201 ~]$ ls -l >> ls-output.txt +``` + +To direct a file to a programs input, use `<` operator: + +```{.bash} +[ssasidharan@lnx201 ~]$ cat < sonnet18.txt +Shall I compare thee to a summer’s day? +``` + + +## Pipes + +- Using the `|` ("pipe") operator, you can "chain" programs such that +one programs output is another programs input: + +```{.bash} +[ssasidharan@lnx201 ~]$ ls -l /bin/ | less +``` + +- You can create longer pipes: + +```{.bash} +[ssasidharan@lnx201 ~]$ ls /bin /sbin | sort | uniq | wc + 4289 4288 46820 +``` + + + + +# Users and Groups + +## You belong (to groups) + +Your account belongs to several groups: + +```{.bash} +[ssasidharan@lnx201 ~]$ id +uid=63499(ssasidharan) gid=262(chess) groups=262(chess),750(classeuser) +[ssasidharan@lnx201 ~]$ groups +chess classeuser +``` + +## Permissions and ownership + +Do a "long" file listing (with `ls -l`) and behold: + +```{.bash} +$ ls -l +total 8 +drwxr-xr-x 2 ssasidharan chess 44 May 8 10:42 bin +drwxr-xr-x 2 ssasidharan chess 144 Mar 12 00:27 CLASSE_shortcuts +drwxr-xr-x 2 ssasidharan chess 52 Apr 2 00:27 Desktop +drwxr-xr-x 2 ssasidharan chess 28 Apr 2 00:27 Documents +lrwxrwxrwx 1 ssasidharan chess 31 Mar 26 15:21 Downloads -> /cdat/tem/ssasidharan/Downloads +drwxr-xr-x 2 ssasidharan chess 28 Apr 2 00:27 Music +drwxr-xr-x 2 ssasidharan chess 28 Apr 2 00:27 Pictures +drwxr-xr-x 2 ssasidharan chess 28 Apr 2 00:27 Public +drwxr-xr-x 2 ssasidharan chess 28 Apr 2 00:27 Templates +drwxr-xr-x 2 ssasidharan chess 28 Apr 2 00:27 Videos +``` + +What do those characters mean? + + +## Changing permissions + +- Use `chmod` command to change file mode bits (the first column in + the previous listing). + +```{.bash} +[ssasidharan@lnx201 ~]$ chmod +x test.sh +[ssasidharan@lnx201 ~]$ ls -l test.sh +-rwxr-xr-x 1 ssasidharan chess 0 Mar 28 13:39 test.sh +[ssasidharan@lnx201 ~]$ chmod -x test.sh +[ssasidharan@lnx201 ~]$ ls -l test.sh +-rw-r--r-- 1 ssasidharan chess 0 Mar 28 13:39 test.sh +``` + +- Use `chown` and `chgrp` commands to change owner and group (the + third and fourth columns in the previous listing). + - Probably not immediately useful; just know that they exist. + + +# Processes + +## Listing processes + +- List running processes using `ps` command: + +```{.bash} +[ssasidharan@lnx201 ~]$ ps + PID TTY TIME CMD + 694411 pts/81 00:00:00 ps +3479688 pts/81 00:00:00 bash +``` + +The four columns: + +- `PID` is process id. +- `TTY` is the terminal associated with the process. +- `TIME` is the elapsed CPU time for the process. +- `CMD` is the command that created the process. + + +(Also see: `top` and `htop`.) + +## Background and foreground processes + +- Some processes run in the foreground: + - They read input, write output, etc. + - Attached to a terminal. +- Background processes, well, run in the background. Send things to + the background with `&`: + +```{.bash} +[ssasidharan@lnx201 ~]$ sleep 100 & +[1] 949751 +``` + +- Bring a background process to foreground using `fg` command, and +terminate it using {{}}: + +```{.bash} +[ssasidharan@lnx201 ~]$ fg 2 +sleep 100 +^C +``` + +## Terminating processes + +- `kill PID` command to end one process. +- `killall` command to end many processes + + + +# Other tools of the trade + +## Text editors + +Many choices! Use: + +- Emacs +- Vim +- Nano +- JupyterLab + + +## Terminal multiplexers + +![](tmux.png) + + +# Shell scripts + +## Hello world! + +```{.bash filename=hello.sh code-line-numbers="true"} +#! /bin/bash + +# A simple script. + +echo "Hello $USER!" +``` + +- Make the thing executable with `chmod +x hello.sh` +- Run the thing with `./hello.sh` + +## Other things + +Bash supports a programming language with: + +- Conditionals (with `if` statements) +- Loops (with `for` and `while` statements) +- Et cetera +- Take a peek at `/etc/bashrc` for a taste + +BUT + +- This is another topic, not really in scope of this presentation +- We're likely out of time anyway + + +# Some resources + +# A cheat sheet + +[![](cheat-sheet.png){height=600}](cheat-sheet.png) + + +# Resources elsewhere + +- [Shell Tools and Scripting][missing] module of MIT "The Missing + Semester of Your CS Education" class. +- [The Linux Command Line, A Complete Introduction][tlcl] by William + E. Shotts, Jr. The book is freely available under a Creative + Commons license, and contains a good discussion about shell + scripting. +- [The Unix Programming Environment][tupe] by Brian W. Kernighan and + Rob Pike. Good old classic, still useful. Places things in a + historical context. + + +# Fin! + +[missing]: https://missing.csail.mit.edu/2020/shell-tools/ +[tlcl]: http://linuxcommand.org/tlcl.php +[tupe]: https://archive.org/details/UNIXProgrammingEnvironment diff --git a/theme2/SF100/title-slide.html b/theme2/SF100/title-slide.html new file mode 100644 index 0000000..ed87dfa --- /dev/null +++ b/theme2/SF100/title-slide.html @@ -0,0 +1,22 @@ +
+

$title$

+$if(subtitle)$ +

$subtitle$

+$endif$ +$for(author)$ +

$author$

+$endfor$ +$for(institute)$ +

$institute$

+$endfor$ +$if(date)$ +

$date$

+$endif$ + +
+ + + +
+ +