UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in...

18
UNIX 40 Years and Still Rocking the Terminal!

Transcript of UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in...

Page 1: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

UNIX40 Years and Still Rocking the

Terminal!

Page 2: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

A Little History•Developed by AT&T @ Bell Labs in

1969

•Many different variants

•BSD, Solaris, HP-UX, AIX

•Version 7 or System V

•Linux is not UNIX but a “Unix-like” system

Page 3: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

Unix is “Open”

Built using The C Programming Language

Unix is a portable, multi-tasking and multi-user

operating system consisting of many small, powerful

programs

Page 4: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

What Makes Unix

AWESOME!?

Commands, Commands, and more Commands

Page 5: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

•The Bourne-Again Shell (BASH)

•AWK

•SED

Interpreters

These three tools alone can do incredible things

Page 6: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

What is BASH•BASH is an improved replacement shell

•It’s also a powerful scripting language

•It supports full logical expressions and looping mechanics

•But its true power is it’s ability to chain together commands with pipes and redirects

Page 7: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

Some Power Features•Pipes:

cat someFile | awk ‘{ print $1 }’- reads someFile to stdout, then redirects it as the stdin to awk

•Redirection:diff file1 file2 > theDifferences - redirects all output to a file named theDifferences

tidy -i an_HTML_file 2> /dev/null- redirects any errors for /dev/null (a.k.a. “the default log file”)

Page 8: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

What is AWK?•“AWK is a programming language that

is designed for processing text-based data, either in files or data streams”

•Powerful enough to write full programs

•Incredible enough to use from the terminal kill -9 `ps aux | awk -V user=$(whoami) '{ if ($1 ~ user ) print $2}'`

Page 9: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

What is SED•SED is a stream editor

•Using regular expressions, you can edit an input stream

•Most powerful when used in conjunction within a BASH script

•sed ‘s/p(ython|erl)/ruby/g’- searches for the word python or perl and replace it with ruby

Page 10: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

Basic Terminal Commands• cd - Change directories

• ls - Directory listing• rm - Remove a file• mkdir - Make a new directory• pwd - Print the Present Working Directory• cp - Copy a file• mv - Move or Rename a file• wc - Word or Line or Character count• cat - Concatenate multiple files• head - Output the first line of an input file• tail - Output the last line of an input file• grep - Search a file and print matching lines• vi - Complicated Text Editor (Alt is nano or pico)

Page 11: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

Using the Commands...

•To change a directory- cd theDirName- cd ~/levelOne/levelTwo/levelThree- cd ../

• To list the contents in a directory- ls - ls -l- ls --color=”always”

Page 12: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

Using the Commands...•To make a directory

- mkdir theDirName- mkdir -p levelOne/levelTwo/levelThree

• To search a file for a pattern- grep -E “p(ython|perl)” fileName- grep “plain text” ./

•Delete a directory structure- rm -Rf ~/temp# will recursively delete everything in temp

Page 13: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

Customize Your Commands

•alias ls=’ls -G’

•alias ll=’ls -l’

•alias la=’ls -a’

BASH allows you to customize built-in commands with the alias command

Page 14: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

A Quick Script

cat << EOF > /usr/local/bin/hunt#!/bin/bash

find $(pwd) -name “$1” -printEOF

chmod 755 /usr/local/bin/hunt

Type the following into a Terminal

Page 15: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

A Better Shell Prompt•BASH uses a lot of environment

variable

•These variables are used by built-in commands and to customize BASH

•PS1 is the variable BASH uses to style your first prompt (Prompt Style 1)

Page 16: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

\d the date in "Weekday Month Date" format \e an ASCII escape character (033) \h the hostname up to the first `.' \H the hostname \j the number of jobs currently managed by the shell \l the basename of the shell's terminal device name \n newline \r carriage return \s the name of the shell, the basename of $0 (the portion following the final slash) \t the current time in 24-hour HH:MM:SS format \T the current time in 12-hour HH:MM:SS format \@ the current time in 12-hour am/pm format \u the username of the current user \v the version of bash (e.g., 2.00) \V the release of bash, version + patchlevel (e.g., 2.00.0) \w the current working directory \W the basename of the current working direcory \! the history number of this command \# the command number of this command \$ if the effective UID is 0, a #, otherwise a $ \nnn the character corresponding to the octal number nnn \\ a backslash \[ begin a sequence of non-printing characters \] end a sequence of non-printing characters

Page 17: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

•Black 0;30 Dark Gray 1;30•Blue 0;34 Light Blue 1;34•Green 0;32 Light Green 1;32•Cyan 0;36 Light Cyan 1;36•Red 0;31 Light Red 1;31•Purple 0;35 Light Purple 1;35•Brown 0;33 Yellow 1;33•Light Gray 0;37 White 1;37

BASH Colors

Page 18: UNIX 40 Years and Still Rocking the Terminal!. A Little History Developed by AT&T @ Bell Labs in 1969 Many different variants BSD, Solaris, HP-UX, AIX.

A Custom PS1

•\[\e[1;30m\][\[\e[1;34m\]\u\[\e[1;30m\]@\[\e[0;31m\]\h\[\e[1;30m\]] \@ \[\e[1;30m\]\w \n$\[\e[0m\]

•Produces the following prompt