class: center, middle, inverse, title-slide # An Introduction to the shell ### Jelmer Poelstra ### MCIC Wooster ### 2020/12/16 (updated: 2020-12-16) --- class:inverse middle center # Overview .pull-left[ ### [Introduction](#intro) ### [Navigation](#navigation) ### [Standard In/Out and Pipes](#stdin) ### [Managing Files](#managing_files) ] --- class:inverse middle center name: overview # Overview .pull-left[ ### [Introduction](#intro) ### [Navigation](#navigation) ### [Standard In/Out and Pipes](#stdin) ### [Managing Files](#managing_files) ] .pull-right[ ### [Wildcards](#wildcards) ### [Viewing Text Files](#text_files) ### [Variables and Scripts](#script) ### [Bonus Material](#bonus) ] --- class:inverse middle center name:intro # Introduction ----- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Terminology | short | long | meaning | |-|-|-| | **dir** | directory | folder | | **GUI** | Graphical User Interface | Point-and-click interface | | **CLI** | Command Line Interface | Interface where you type commands | --- ## What is a shell? - The shell is a **command-line interface (CLI) to the operating system**. - A shell is always available on Unix-like operating systems, such as Linux and Mac. (In Windows, there are [ways to get one](#windows-shell).) -- <br> ### Shell flavors - Of many very similar shell variants, we will be using the **bash shell**. This is most common shell -- e.g. the default in Mac and Linux, including at OSC. --- ## But what can I do in the shell? -- - Manage and manipulate files. -- - Run bioinformatics programs and submit scripts. -- - Interact with remote computers, such as OSC clusters. -- - ... While keeping track of what you've done. --- ## Let's open up a shell at OSC! - The Ohio Supercomputer Center (OSC) allows us to use a shell *within* a browser at <https://ondemand.osc.edu/>. <br> <p align = "center"> <img src=figs_shell/OSC_shell.png width="900"> </p> <br> - In the "`Clusters`" dropdown menu, click "`Pitzer Shell Access`". --- ## The shell prompt - OSC shows us lots of welcome messages and information: <p align="left"> <img src=figs_shell/OSC_welcome.png width="550"> </p> <p align="center"> <img src=figs_shell/OSC_welcome2.png width="1000"> </p> -- - And a **prompt** -- this is where we type. <p align="center"> <img src=figs_shell/OSC_prompt.png width="900"> </p> --- class: center middle # In the shell, <br> we're mostly typing commands ### Basic usage is just memorizing commands for common utilities --- ## A first example: the "`cal`" command - Just typing `cal` prints a calendar to screen: ```sh $ cal # - I'm using a $ to indicate the prompt. # - Everything after a "#" is ignored. ``` -- <p align="center"> <img src=figs_shell/cal.png width="400"> </p> --- ## A first example: the "`cal`" command - Just typing `cal` prints a calendar to screen: ```sh $ cal # - I'm using a $ to indicate the prompt. # - Everything after a "#" is ignored. ``` - We can use the "-j" or "-m" **options** (flags): ```sh $ cal -j # Show a Julian calendar $ cal -m # Have weeks start on Monday ``` -- - We can use a year as an **argument** (parameter): ```sh $ cal 2020 # Print the calendar for 2020 ``` -- - We can combine options and arguments, e.g.: ```sh $ cal -j -m 2020 $ cal -jm 2020 # Shorter notation! ``` --- ## What we've learned from `cal` - After typing a command, we issue it using `Enter`, the result will be printed to screen, and we get our prompt back. - We can use **options (flags) and arguments (parameters)** <br> to modify or determine what a command does. - These arguments and options are **separated by spaces**. -- <br> .content-box-purple[
Everything after a **"`#`"** is ignored -- useful for comments! ] --- ## How can we know a command's options? Many commands have a "**-h**" help option: ```sh $ cal -h # Usage: # cal [options] [[[day] month] year] # Options: # -1, --one show only current month (default) # -3, --three show previous, current and next month # -s, --sunday Sunday as first day of week # -m, --monday Monday as first day of week # -j, --julian output Julian dates # -y, --year show whole current year # -V, --version display version information and exit # -h, --help display this help text and exit ``` - Note the short ("**-h**") vs long ("**--help**") option notation! --- ## How can we know a command's options? (cont.) - Using the **`man`** ("manual") command, whose argument is the command or utility we want the manual for: ```sh $ man ls ``` <p align="center"> <img src=figs_shell/man_ls.png width="600"> </p> --- class: center middle # Let's learn some useful commands... <br><br> --- class: center middle inverse name:navigation # Navigation ---- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Commands for navigation: Overview .pull-left[ ### `pwd` **P**rint **W**orking **D**irectory <br> ### `cd` **C**hange (working) **D**irectory ] .pull-right[ ### `ls` **L**i**S**t files and directories ] --- ## Commands for navigation: Overview ```sh $ pwd # Print Working Directory (where am I?) $ cd # Change (working) Directory $ ls # LiSt files and dirs in your current working directory ``` <br> - Which of these commands might need an *argument*? -- ```sh $ cd destination_dir ``` --- ## Navigation: `pwd` To let the shell tell you what your working directory is, <br> use **`pwd`** (**P**rint **W**orking **D**irectory): ```sh $ pwd # /users/PAS0471/jelmer/ ``` -- <br> - Notice that directories are separated by **forward slashes "`/`"** <br> in Unix environments. <br> --- ## Navigation: `cd` To change working directory, use **`cd`** (**C**hange **D**irectory). - Using an **absolute path** (i.e., starting from the root dir): ```sh $ cd /fs/project/PAS0471/ ``` -- .content-box-green[ ###
Try this: - Shells have tab completion! - Type `/f` and press `Tab` (will autocomplete to `fs/`) - Then add `pr` (`/fs/pr`) and press `Tab` - Add `PAS` (`fs/project/PAS`) and press `Tab Tab` - Add `04` (`fs/project/PAS04`) and press `Tab Tab` - You can paste text into your OSC browser shell using **`Ctrl` + `v`** ] --- ## Navigation: `cd` To change working directory, use **`cd`** (**C**hange **D**irectory). - Using an **absolute path** (i.e., starting from the root dir): ```sh $ cd /fs/project/PAS0471/ ``` - Using a **relative path** (i.e., not starting from the root dir): ```sh $ cd workshops/2020-12_micro/$USER # Absolute: /fs/project/PAS0471/workshops/2020-12_micro/$USER ``` -- <br> - **The shell does not give us any feedback when it succeeds.** Check whether it worked: ```sh $ pwd # /fs/project/PAS0471/workshops/2020-12_micro/jelmer ``` --- ## Navigation: `cd` To change working directory, use **`cd`** (**C**hange **D**irectory). - Using an **absolute path** (i.e., starting from the root dir): ```sh $ cd /fs/project/PAS0471/ ``` - Using a **relative path** (i.e., not starting from the root dir): ```sh $ cd workshops/2020-12_micro/$USER # Absolute: /fs/project/PAS0471/workshops/2020-12_micro/$USER ``` <br> - **The shell does not give us any feedback when it succeeds.** What happens when I make a mistake? ```sh $ cd sdkjgkhh # bash: cd: sdkjgkhh: No such file or directory ``` --- ## Navigation: `cd` (cont.) ### Tricks! ```sh $ cd ~ # Move to your home dir (~ is always /home/<user>/ !) $ cd .. # Move one directory up $ cd ../.. # Move two directories up $ cd - # Go back to last visited dir (like "Back" in a browser) $ cd . # This doesn't move you anywhere, as `.` is a shortcut # for the current working directory (useful elsewhere) ``` --- ## Navigation: `ls` - To list the contents of your current working directory, use **`ls`** (**L**i**S**t). ```sh $ ls ``` <p align="center"> <img src=figs_shell/ls.png width="700"> </p> -- - Useful options to modify the output: ```sh $ ls -lh # -l: long format / -h: human-readable file sizes ``` <p align="center"> <img src=figs_shell/ls-lh.png width="700"> </p> --- ## Navigation: `ls` (cont.) - We can also provide a directory or file name as an argument: ```sh $ ls -lh metadata ``` <p align="center"> <img src=figs_shell/ls-metadata.png width="500"> </p> -- ```sh $ ls -lh metadata/Experiment description # ls: cannot access Experiment: No such file or directory # ls: cannot access description: No such file or directory ``` What just happened? And how do we get around this? -- - **To interpret spaces literally**, quote the full string or "escape" the space: ```sh $ ls "Experiment description" # Quote the file name $ ls Experiment\ description # Escape the space with a "\" ``` -- - **But, better to avoid spaces in file names!** --- class: center middle inverse name:stdin # Standard Input/Output and Pipes ---- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Standard output and redirection - The regular output of a command is called **"standard out"** ("*stdout*"). By default, this is printed to screen, but it can be "redirected" to a file. -- - With "**`>`**", we **redirect** output to a file: - If the file doesn't exist, it will be *created*. - If the file does exist, any contents will be *overwritten*. ```sh $ ls -lhr data/raw > list_of_files.txt ``` -- - With "**`>>`**", we **append** the output to a file: ```sh $ ls -lhr metadata >> list_of_files.txt ``` -- <br> .content-box-purple[
**Error messages** are also printed to screen but are **not** part of standard out. See the [bonus materials](#stderr) to learn about redirecting error messages. ] --- ## Standard input and pipes - A file name can be given as an argument to most commands. This "`grep`" command will search for the string "soil_blank" inside the contents of our metadata file: ```sh $ grep "soil_blank" metadata/sample_meta.txt ``` -- <br> - Most commands *also* accept input from "standard input" (*stdin*), using the **pipe**, "**`|`**": ```sh $ cat metadata/sample_meta.txt | grep "soil_blank" ``` Here, the pipe presents the standard output (*stdout*) of `cat` as input (*stdin*) to `grep`. --- class: center middle inverse name:managing_files # Managing Files ---- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Commands to manage files: Overview .pull-left[ ### `mkdir` Make a new dir <br> ### `cp` Copy files (and dirs) ] -- .pull-right[ ### `mv` Move or rename files and dirs <br> ### `rm` Remove files (and dirs) ] --- ## Commands to manage files ```sh $ mkdir <dirname> # Make a new directory $ cp <from> <to> # Copy files (and/or directories) $ mv <from> <to> # Move or rename files and/or directories $ rm <file> # Remove files (and/or directories) # BEWARE: There is no Thrash Bin in the shell! ``` <br> -- - Examples: ```sh mkdir figures/ mkdir -p manuscript/fig/supp/ # "-p": multiple levels ``` -- ```sh cp metadata/sample_meta.txt . # "." for current wd ``` ```sh mv sample_meta.txt meta.txt ``` ```sh rm meta.tx ``` --- ## Commands to manage files (cont.) ```sh $ mkdir <dirname> # Make a new directory $ cp <from> <to> # Copy files (and/or directories) $ mv <from> <to> # Move or rename files and/or directories $ rm <file> # Remove files (and/or directories) # BEWARE: There is no Thrash Bin in the shell! ``` <br> - For `cp` and `rm`, use **"`-r`"** (for "recursive") to act on directories and their contents: ```sh cp -r data/raw/ backup/ rm -r backup/ # Confirm removal for each file rm -rf backup/ # `-f` for force, no prompting ``` -- - The `-r` option is not needed with `mv`. --- class:inverse middle center name:wildcards # Wildcards ---- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Matching file names with wildcards |Wildcard | Matches | |-|-| | * | Any number of any character, including nothing | | ? | Any single character | [] and [^] | One or none (`^`) of the "character set" within the brackets -- - Say we have the following files in a directory: ```sh # sample1_F.fastq.gz sample1_R.fastq.gz # sample2_F.fastq.gz sample2_R.fastq.gz # sample3_F.fastq.gz sample3_R.fastq.gz ``` -- - **To match both "sample1" files:** ```sh ls sample1_?.fastq.gz ls sample1* ls sample1*fastq.gz ``` --- ## Matching file names with wildcards (cont.) |Wildcard | Matches | |-|-| | * | Any number of any character, including nothing | | ? | Any single character | [] and [^] | One or none (`^`) of the "character set" within the brackets - Say we have the following files in a directory: ```sh # sample1_F.fastq.gz sample1_R.fastq.gz # sample2_F.fastq.gz sample2_R.fastq.gz # sample3_F.fastq.gz sample3_R.fastq.gz ``` - **To match only files with forward ("F) reads:** ```sh $ ls *F* $ ls *F.fastq.gz ``` --- ## Matching file names with wildcards (cont.) |Wildcard | Matches | |-|-| | * | Any number of any character, including nothing | | ? | Any single character | [] and [^] | One or none (`^`) of the "character set" within the brackets - Say we have the following files in a directory: ```sh # sample1_F.fastq.gz sample1_R.fastq.gz # sample2_F.fastq.gz sample2_R.fastq.gz # sample3_F.fastq.gz sample3_R.fastq.gz ``` - When using a "character set", the presence of *any* of the characters will trigger a match. **To match files for sample1 and sample2 only:** ```sh $ ls sample[12]* # Use the character class notation $ ls sample[1-2]* # Can use ranges like [0-9], [A-Z], [a-z]. $ ls sample[^3]* # Other way around: exclude sample3 ``` --- background-color:#e4ede4 ##
Your turn: Navigation, managing files & wildcards 1. Go to "`/fs/project/PAS0471/workshops/2020-12_micro/$USER`" (if not there already). **This is your base directory for this workshop.** 2. Rename "`metadata/Experiment description`" to "`metadata/Experiment_description`". 3. Check whether this worked. 4. Move up one dir (to "`2020-12_micro`") -- try to avoid using the absolute (full) path notation. 5. Using an **`ls`** command, match *only your* directory using as few characters as possible, and one or more wildcards (**`*`** and perhaps **`?`**). --- background-color:#e4ede4 ## Solutions: Navigation, managing files & wildcards ```sh # 1. Go to `/fs/project/PAS0471/workshops/2020-12_micro/`. $ cd /fs/project/PAS0471/workshops/2020-12_micro/$USER # 2. Rename "`metadata/Experiment description`". $ mv "metadata/Experiment description" metadata/Experiment_description # 3. Check whether this worked. $ ls metadata # 4. Move one level up. $ cd .. # 5. Match your directory. $ ls *lm* ``` --- class: center middle inverse name:text_files # Viewing Text Files ---- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Commands to view text files: Overview .pull-left[ ### `cat` Print the contents of (a) file(s). <br> ### `head` / `tail` Show the first or last lines of a file. ] -- .pull-right[ ### (In bonus materials: [`less`](#less)) ] --- ## Text files: `cat` - `cat` will print one or more files, by default to screen. ```sh $ cat metadata/sample_meta.txt $ cat metadata/sample_meta.txt > tmp.txt ``` -- - If you have 10,000 `fasta` files in a directory (e.g. one per gene), and you want to put them all into a single `fasta` file: ```sh $ cat *.fasta > all.fasta # Recall the `*` wildcard ``` -- <br> .content-box-purple[
Try "`column -t`" for better viewing of tabular files. ] --- ## Text files: `head` and `tail` - `head` / `tail` will simply show the first / last few lines of a file. ```sh $ head my_file.txt # Default: shows first/last 10 lines $ tail -n 1 my_file.txt # Just show the last/first line ``` - Showing the last line of a 100 GB file outside of the shell can be a big pain -- in the shell it's very simple and fast! -- <br> - Skip the first line of a file (*cut off the header*, if you only want the data): ```sh $ tail -n +2 file ``` -- - Print line number 1866: ```sh $ head -n 1866 file | tail -n 1 ``` --- class: center middle inverse name:script # Variables and Scripts ---- <br><br><br><br> ### [[Back to overview]](#overview) --- ## Assigning and using variables .pull-left[ **Assign** a variable (no **`$`**): ```sh # Any string: my_name=Jelmer ``` ] .pull-right[ **Recall** a variable (with **`$`**): ```sh $ echo $my_name # Jelmer ``` ] -- .pull-left[ ```sh # A file name: my_file="README.txt" ``` ] .pull-right[ ```sh $ ls -lh $my_file # -rw-r--r-- 1 jelmer PAS0471 568 Dec 7 09:58 README.txt ``` ] -- .pull-left[ ```sh # Use "command substitution" # to assign a command's output today=$(date +"%Y-%m-%d") ``` ] .pull-right[ ```sh $ touch README_$today.txt $ ls README_* # README_2020-12-10.txt ``` ] -- .pull-left[ Pre-existing variables: ("**Environment variables**") ] .pull-right[ ```sh $ echo $USER # jelmer ``` ] -- --- ## Assigning and using variables (cont.) - **It can be useful to use variables for things that:** - May be subject to change over time or in reruns (dir names, settings). - Need to be manipulated. - Are re-used often. --- ## A very minimal script - Create and run a very simple script: ```sh $ echo 'echo "Hello $1"' > hello.sh $ bash hello.sh Jelmer # Hello Jelmer ``` -- .pull-left[ - Or, assign a variable first: ```sh $ my_name=Jelmer $ hello.sh $my_name # Hello Jelmer ``` ] .pull-right[ - Or use `$USER`: ```sh $ hello.sh $USER # Hello jelmer ``` ] -- - We can also redirect the output to a file: ```sh $ hello.sh Jelmer > hello.txt $ cat hello.txt # Hello Jelmer ``` --- class: center middle inverse # Questions? --- class: inverse center middle name:bonus # Bonus Materials ----- ### I: [Keyboard Shortcuts and General Tricks](#tricks) ### II: [Text File Data Tools](#datatools) ### III: [The `less` Pager](#less) ### IV: [Standard Error](#stderr) <br><br> ### [[Back to overview]](#overview) --- class: center middle inverse name:tricks # Bonus Material I: # Keyboard Shortcuts and General Tricks ---- <br><br><br><br> ### [[Back to overview]](#overview) --- background-color: #ededed # Keyboard Shortcuts and Tricks I | Shortcut | Command | Function |--|--| | `Tab` | | Tab completion! Files, commands, etc. <br> Double `Tab` to show options when <br> multiple are still available.| | Up/Down arrow | | Cycle through command history| | `CTRL` + `R` | | Enter characters to search for in the history <br> (repeat `CTRL` + `R` to keep going back, <br> `ENTER` to put command in prompt) | | `CTRL` + `C` | | Abort (kill) current process | | `CTRL` + `D` | `exit` | Exit the current shell (/ interactive job) | | `CTRL` + `Z` | (`bg` / `fg`)| Suspend (pause) a process, <br> then use `bg` to move to background| --- background-color: #ededed # Keyboard Shortcuts and Tricks II | Shortcut | Function |--|--| | `Ctrl` + `Shift` + `c` | Copy | | `Ctrl` + `Shift` + `v` | Paste | | `Ctrl` + `a` | Go to beginning of line | | `Ctrl` + `e` | Go to end of line | | `Ctrl` + `u` | Cut to beginning of line | | `Ctrl` + `k` | Cut to end of line | | `Ctrl` + `w` | Cut previous word | | `Ctrl` + `y` | Paste previously cut element | | `Alt` + `.` | Paste last argument of last command | --- # Keyboard Shortcuts and Tricks III:<br>The OSC browser shell - No right-mouse click options - Double-clicking text will copy it to the clipboard - `Ctrl` + `v` will paste (no `Shift` needed) - `Ctrl` + `w` (cut last word) does not work -- reserved browser shortcut to close a tab. --- background-color: #ededed ## Brace expansion ```sh $ touch sample{1,2,3}_{F,R}.fastq.gz $ ls #sample1_F.fastq.gz sample1_R.fastq.gz sample2_F.fastq.gz sample2_R.fastq.gz sample3_F.fastq.gz sample3_R.fastq.gz ``` --- class: center middle inverse name: datatools # Bonus Material II: # Text File Data Tools ---- <br><br><br><br> ### [[Back to overview]](#overview) --- background-color: #ededed ## Text files: `grep` `grep` searches for strings (or regular expression patterns) in files. By default, it returns lines for which matches were found. - Create a file for all annotations for "Gene001": ```sh grep "Gene001" my.gff > Gene001.gff ``` -- - Count the number of lines containing "exon": ```sh grep -c "exon" my.gff # -c: count matches ``` -- - Remove the header lines, which start with a `#`, from a VCF file: ```sh grep -v "^#" my.vcf # -v: reverse search ``` -- Many options, e.g.: - `-r` to search recursively (search all your files for a certain word) - `-n` to print line numbers along with matches --- background-color: #ededed ## Text file data tools - **`cut`**: cut (select) one or more columns from a tabular file ```sh $ cut -f 2-5 < my.gff # Cut the 2nd through 5th column ``` - **`wc` / `wc -l`**: count words / lines. ```sh $ wc -l my.fastq # Count the number of lines in a fastq file. ``` -- <br> - **`sort`**: sort a file by a specified column ```sh $ sort -k5,5 my.bed ``` - **`uniq` / `uniq -c`**: retain / count unique occurrences (*if in order!*) ```sh $ uniq -c list_of_names.txt # Would return count for each name ``` --- background-color: #ededed ## Combining these tools can be very powerful! For instance, the "pipeline" below will return a sorted list (most commmon to least common) of annotation types from an annotation file<sup>[1]</sup>: ```sh $ grep -v "^#" my.gff | cut -f3 | sort | uniq -c | sort -rn # 36128 exon # 25901 CDS # 7588 UTR # ... ``` -- - Command-by-command (note **`\`** to continue across lines): ```sh $ grep -v "^#" my.gff | \ # Excl. header lines starting with `#` + cut -f3 | \ # Select only the 3rd column + sort | \ # Sort alphabetically + uniq -c | \ # Count each unique element + sort -rn # Numerically reverse-sort ``` .footnote[<sup>[1]</sup>From: Bioinformatics Data Skills (Buffalo 2015)] --- background-color:#e4ede4 ##
Your turn: Working with text files I **Now, we'll look at a file with some metadata for our samples.** 1. Move into the `metadata` folder within our workshop's home directory (`/fs/project/PAS0471/workshops/2020-12_micro/`). 1. Print the entire file to screen with `cat` and with `column -t`. Compare the output, especially in the first lines of the file. 2. Print the first 6 lines of the file, then make them line up with `column -t`. 2. Print everything but the first line, which has the column headers. 3. Print the line for sample "304-S1". --- background-color:#e4ede4 ## Solutions: Working with text files I 1. Move into the `metadata` folder: ```sh mv metadata/ ``` 1. Print the entire file to screen with `cat` and with `column -t`: ```sh cat V4_meta.txt column -t V4_meta.txt ``` 2. Print the first 6 lines of the file, then make them line up with `column -t`: ```sh head V4_meta.txt | column -t ``` 2. Print everything but the first line, which has the column headers: ```sh tail -n +2 ``` 3. Print the line for sample "304-S1": ```sh grep "304-S1" V4_meta.txt ``` --- background-color:#e4ede4 ##
Your Turn: Working with text files II 1. How many samples (lines) do we have for each "Experiment"? 2. How many different "Blocks" do we have? Hint: Make sure to exclude the lines which have "NA" in the "Blocks" column. 3. Earlier, with `less`, we looked for the pattern *"GAGTGCCAGCCGCCGCGGTAATACGTAGGGTGCGAGCGTTAATCGGAATTACTGGGC"* in the file `data/fastq/502-S4-V4-V5_S66_L001_R1_001.fastq.gz`. Now, count how many times this pattern occurs in the file using `grep`. --- background-color:#e4ede4 ## Solutions: Working with text files II 1. How many samples (lines) do we have for each "Experiment"? ```sh tail -n +2 V4_meta.txt | cut -f 3 | sort | uniq -c ``` 2. How many different "Blocks" do we have? ```sh $ tail -n +2 V4_meta.txt | grep -v "NA" | \ + cut -f 6 | sort | uniq | wc -l ``` 3. Count occurences of *"GAGTGCCAGCCGCCGCGGTAATACGTAGGGTGCGAGCGTTAATCGGAATTACTGGGC"* in the file `data/fastq/502-S4-V4-V5_S66_L001_R1_001.fastq.gz`. ```sh $ grep -c "GAGTGCCAGCCGCCGCGGTAATACGTAGGGTGCGAGCGTTAATCGGAATTACTGGGC" \ + data/fastq/502-S4-V4-V5_S66_L001_R1_001.fastq.gz ``` --- class: center middle inverse name:less # Bonus Material III: # The `less` Pager ---- <br><br><br><br> ### [[Back to overview]](#overview) --- background-color: #ededed ## The `less` pager - `less` doesn't load entire files into memory: **easy to look at large files**. ```sh $ less my_file.txt $ zless my_fastq.gz # `zless` variant to view zipped files! ``` - Now you'll be inside the pager, and your prompt is gone. -- - Keyboard shortcuts: | key | function | |--|--| | `q` | Exit `less` | | `d` / `u` | Go down / up half a page. <br>Note: arrow keys and `pgup` / `pgdn` usually also work.| | `g` / `G` | Go to the first / last line (`home` / `end` also work) |`/` | Search: next type keyword to search for | `n` / `N` | Go to next/previous search match --- background-color:#e4ede4 ## Your turn: `less` You should still be in our workshop's home directory (`/fs/project/PAS0471/workshops/2020-12_micro/`). This directory contains the data we will be working with today and tomorrow. In `data/fastq`, you can find the raw gzipped fastq files. - Open a gzipped fastq file with `less`: ```sh zless data/fastq/502-S4-V4-V5_S66_L001_R1_001.fastq.gz ``` - Try to move around a bit. - Jump to the first and last line. - Now look for the following pattern: "GAGTGCCAGCCGCCGCGGTAATACGTAGGGTGCGAGCGTTAATCGGAATTACTGGGC" - Exit. --- class: center middle inverse name:stderr # Bonus Material IV: # Standard Error ---- <br><br><br><br> ### [[Back to overview]](#overview) --- background-color: #ededed ## Standard error - When commands run into errors, they will print error messages. Error messages are **not** part of standard out, and instead represent a separate output stream: **"standard error"**. -- - We can see this when we try to list a non-existing directory: ```sh ls -lhr solutions/ > solution_files.txt # ls: cannot access solutions.txt: No such file or directory ``` - The error was printed to screen. What about the file? -- ```sh $ ls # solution_files.txt $ cat solution_files.txt $ # We just get our prompt back - file is empty ``` -- - To redirect the standard error: ```sh ls -lhr solutions/ > solution_files.txt 2> errors.txt ls -lhr solutions/ &> out.txt # `&>`: combine stdout and stderr ```