CLI

TotT 2014

Command Line Interface

"a means of interacting with a computer program where the user (or client) issues commands to the program in the form of successive lines of text."
- Wikipedia

Use Cases

  • Large vocab interaction
  • Remote work
  • Constrained environments
  • Automation
  • Toolchains

Tools

We'll bootstrap our work with four:

  1. Bash
  2. SSH
  3. Vi
  4. Screen

Bash Shell

  • Command language interpreter
  • Reads commands from user or script
  • Concerned with manipulation of files, execution of other programs

Bash Language

  • Scripting language to automate shell functions
  • Has constructs like loops and conditionals
#!/bin/bash

if [ -z "$1" ]; then
  echo "Hello, World!"
else
  echo "Hello, $1!"
fi

Basic Bash Concepts

  • File
  • Directory
  • Session
  • Process
  • Script

Demo: Bash Basics

pwd, ls, cd, mkdir, touch, cp, mv, less, man

Demo: Bash Basics

Demo: Bash Basics++

find, grep, history, pkill

Demo: Bash Basics++

Secure Shell (SSH)

"cryptographic network protocol for secure data communication, remote command-line login, remote command execution, and other secure network services between two networked computers"
- Wikipedia

SSH Client

  • ssh
  • Establishes a secure connection with a remote machine
  • Runs a shell session through the connection
  • Can tunnel other traffic too

SSH Basics

# start a remote shell session
$ ssh some.machine.com

# run a remote command
$ ssh some.machine.com 'cd my_scripts; ./do_stuff.sh'

# start a remote shell session on a vagrant box
$ vagrant ssh

# copy a file from remote to local
$ scp some.machine.com:my_scripts/do_stuff.sh .

Other SSH Topics

Google these if interested:

  • Tunneling
  • Port forwarding
  • Secure file transfer
  • Pub-key auth
  • ~/.ssh/config

vi

  • Screen oriented text editor
  • Modal: insert or normal mode
  • Good for remote editing over ssh
  • Some people swear by it for all work

Demo: Simple Editing

Navigation, modes, yanking, pasting, deleting, saving, quitting

Demo: Simple Editing

More vi Commands

GNU Screen

  • CLI window manager
  • Allows fast switching among shell sessions
  • Allows detached process execution

Running / Resuming Screens

# start a new screen
$ screen

# start a new named screen
$ screen -S my_name

# list running screens
$ screen -ls

# connect to a running screen
$ screen -rx my_name

Demo: Working in Screen

Create window, switch window, kill window, rename window, scrollback, disconnect

Demo: Working in Screen

More Screen Commands

Review

  • CLI
  • Bash
  • SSH
  • Vi
  • Screen