Terminal Velocity – An introduction to the shell



Terminal Velocity – An introduction to the shell

0 0


shell-presentation


On Github austinlparker / shell-presentation

Terminal Velocity

An introduction to the shell

2/24/2014

Presented by Austin Parker | @austinlparker

Topics

  • Introduction
  • Conventions and Common Terminology
  • Getting Your Feet Wet
  • Going Off The Deep End
  • Further Reading

Welcome To The Machine

    • A little history...

Early computers used physical switches and printed cards as an interface. The command-line interface became popular in the mid-1960's as video displays were popularized. Since then, the CLI has remained a powerful, fast, and efficient interface for computing.

  • Why should I learn it?
    • It's faster
    • It's built-in
    • It's everywhere

Key Terminology

Interpreter (shell)The software that implements the text interface to the computer.

Prompt (command prompt)The current context for interaction with the interpreter.ITS Unix : unix2%Raspbian : pi@raspberrypi ~ $

CommandAn instruction given by the client (that's you) to the interpreter. It's like tapping on an app to open it, except much less visually stimulating.

ParameterOptional instructions as part of a command. Parameters generally fall into two categories, arguments and options

SyntaxThe grammar that commands to the shell must follow, differs between operating systems and applications.

Conventions of Use

unix2% mkdir foo

prompt - command - argument

unix2% rm -rf ~/path/to/foo

prompt - command - options - argument

In the first example, mkdir is the command and foo is the argument. We want to make a directory named foo.

In the second, rm is the command, r and f are the options, and ~/path/to/foo is the argument. We want to delete the directory foo and all of its subdirectories

Tools of the Trade

Files and Directoriesls cd pwd mv mkdir rm cat touch

Going Everywhere, Doing Thingsssh scp wget chmod chown grep tar

Editing Files and Getting Helpnano pico vim emacs man

Demonstration

Diving Deeper

Popular Shells

bash (Linux, MacOS) bash (an acronym for bourne-again shell) was released in 1989 and remains one of the most widely used shells - It is a replacement for the Unix standard Bourne shell. Useful features include command history and automatic command completion (tab-completion).

zsh (Linux) zsh was written in 1990, and it extends many common Bourne shell features while mixing the best of bash, ksh, and tcsh. The main improvements over bash are a deeper command-line completion algorithm, shared command history across multiple running shells, improved handling of arrays and variables, spell check, and more customization. Find it at SourceForge

PowerShell (Windows 7+) PowerShell was first released in 2006 and is a powerful tool for scripting and working with Windows services and applications such as Windows Server, Outlook, and the WMI. A discussion of PowerShell is beyond this lecture, please visit this wiki for more information.

PuTTY (Windows, Linux) PuTTY isn't actually a shell, it's a terminal and serial emulator. PuTTY and its forks are the preferred method to communicate via ssh to remote servers, but it supports many more. It's relevant because to many people, PuTTY is their only real window into the terminal, so it's something you'll be using a lot if you primarily work with Windows.

Useful Terminal Features

I/O Redirection and Pipesps aux | grep 'apache' The pipe | in bash instructs the shell to send the output of the first command as the input of the second.grep file.txt 'foo' > outfile.txtexampleprogram < infile.txtThe carets < and > direct the input to a command be from a file, or the output to a file, respectively.

Useful Terminal Features

Terminal Multiplexingtmux lstmux -s <session>tmux att -t <session>Terminal Multiplexing is offered by programs such as tmux and screen, the full scope of which is beyond this lecture. The basic concept, however, is that you are able to split your terminal into multiple separate windows that you can move between and save your work as you go. This is very handy to run on remote servers, as if your connection is interrupted, you won't lose all your work!

You can find more information about tmux at its download page. A command reference is located here.

More On Permissions

  • Basics

Everyone on a computer has a unique username. At UA, this is your NetID, but you also set one up for your MacBook or Windows Laptop.

Behind the scenes, these unique usernames (and groups) determine what files you have access to. We can view this on ITS Unix with the ls -l command at a prompt, a sample output of which is below.

unix2% ls -l total 92 -rwx------ 1 ap413335 student 17012 Nov 4 13:13 a.out -rw------- 1 ap413335 student 4020 Jan 22 18:20 cable2.c drwx--S--- 4 ap413335 student 512 Nov 8 14:40 CSI310 drwx--S--- 8 ap413335 student 512 Nov 22 09:12 CSI333 drwx--S--- 4 ap413335 student 512 Feb 9 12:44 CSI402 drwxr-sr-x 2 ap413335 student 512 Sep 6 13:46 flocking -rw------- 1 ap413335 student 0 Nov 4 13:10 outfile

Permissions

  • Position 1 is special, it will read 'd' if it is a directory, - otherwise.
  • Positions 2, 3, 4: read, write, execute for user/owner
  • Positions 5, 6, 7: read, write, execute for group
  • Positions 8, 9, 10: read, write, execute for other/all

So, if we wanted a HTML file to be readable by the webserver, it's permission flags would need to look like... -rw-r--r-- ... baz.html

We can set that state with the following command...chmod 644 filename

Quick Reference

Connect to a hostssh username@host

Copy a file from remote to localscp username@host:filename /local/path

Copy a file from local to remotescp filename username@host:/remote/path

Copy a directory from local to remote homescp -r dir username@host:~

Move a file from one place to anothermv filename /new/path

Change a file namemv filename new_filename

Suggested Further Reading

Questions?

Link to this presentation:

http://goo.gl/vjKdeo