Beginner Lab 2 - Core Shell

Welcome to Lab 2! In this lab you will be learning how to work productively in a shell.

Don’t forget to use Google and man when stuck. The resources linked at the bottom may be helpful as well.

XKCD 1319

Setting up

This lab requires a bash shell, vim, and tmux.

SSH (Secure Shell)

SSH allows you to log in to a remote computer through the internet. It is the equivalent of opening a shell on a remote computer.

The usage is ssh [remote username]@[remote host].

Question

  1. Log on to tsunami.ocf.berkeley.edu with your OCF username and password. There is a file in ~staff/public_html/decal. Open it. What is the secret in the file?

Managing Files, Pipes and Redirection

Combining commands

Chaining together commands is essential to automating your way through the shell. Here’s a quick cheat sheet:

> : Redirect stdout to a file. (Will overwrite the file)

>> : Append stdout to a file.

< : Read input from a file.

| : Send output from one program to the input of the next.

Questions

  1. What line could you use to save the first 10 lines of a file that do not contain any vowels to a new file called return.txt?
  2. How could you save the last 3 lines of ls into output.txt? (See tail)
  3. You have a set of old log files that you want to move to a directory of newer logs. What flag would you use to avoid overwriting the newer log file?

Other useful tricks

!! can be used to repeat the previous command in the shell.

E.g.

python program.py = python program.py sudo !! = sudo python program.py

!:[num] is treated as the previous command’s [num] argument.

E.g.

touch doc.txt = touch doc.txt vim doc.txt = vim !:1

Note: This behavior is from bash and some other shells that implement it.

A quick intro to vim

Why vim?

Hello World

Vim is a modal text editor, meaning that you can change editing modes in order to do different things. There are 3 primarily used modes: Normal, Insert, and Visual mode.

Normal mode:

Insert mode:

Example

Visual mode:

A key feature of vim is chaining together commands. Normal mode is essentially a massive amount of shortcuts that you can combine to quickly navigate and edit a file. Want to move down 3 lines? You know that j means move down 1 line, so you can use 3j to move down 3. d is for deletion and w is to jump to the next word, so what does dw do?

Questions

Try playing around with lab2.md while looking up some new commands. Use wget to download it!

If you’re interested in emacs instead

A quick intro to tmux

Example

Why tmux?

Getting Started:

Question

Advanced usage (optional)

Checking off

Once you’re done remember to fill out the check off form. There are multiple valid answers for some of the questions. Please answer the feedback questions if there’s anything you want to say!

Resources

One of the best parts about vim and tmux is their customizability. Look up some configuration files (aka dotfiles) online and see what you like!

Keybindings

Learning vim progressively

Tmux cheat sheet