UNIX 40 Years and Still Rocking the Terminal

  • Slides: 18
Download presentation
UNIX 40 Years and Still Rocking the Terminal!

UNIX 40 Years and Still Rocking the Terminal!

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

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

Unix is “Open” Built using The C Programming Language Unix is a portable, multitasking

Unix is “Open” Built using The C Programming Language Unix is a portable, multitasking and multi-user operating system consisting of many small, powerful programs

What Makes Unix AWESOME!? Commands, and more Commands

What Makes Unix AWESOME!? Commands, and more Commands

Interpreters • The Bourne-Again Shell (BASH) • AWK • SED These three tools alone

Interpreters • The Bourne-Again Shell (BASH) • AWK • SED These three tools alone can do incredible things

What is BASH • BASH is an improved replacement shell • It’s also a

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

 • Pipes: Some Power Features cat some. File | awk ‘{ print $1

• Pipes: Some Power Features cat some. File | awk ‘{ print $1 }’ - reads some. File to stdout, then redirects it as the stdin to awk • Redirection: diff file 1 file 2 > the. Differences - redirects all output to a file named the. Differences tidy -i an_HTML_file 2> /dev/null - redirects any errors for /dev/null (a. k. a. “the default log file”)

What is AWK? • “AWK is a programming language that is designed for processing

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}'`

What is SED • SED is a stream editor • Using regular expressions, you

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

 • • • • Basic Terminal Commands cd ls rm mkdir - Change

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

Using the Commands. . . • To change a directory - cd the. Dir.

Using the Commands. . . • To change a directory - cd the. Dir. Name - cd ~/level. One/level. Two/level. Three - cd. . / • To list the contents in a directory - ls -l - ls --color=”always”

Using the • To make a directory Commands. . . - mkdir the. Dir.

Using the • To make a directory Commands. . . - mkdir the. Dir. Name - mkdir -p level. One/level. Two/level. Three • To search a file for a pattern - grep -E “p(ython|perl)” file. Name - grep “plain text”. / • Delete a directory structure - rm -Rf ~/temp # will recursively delete everything in temp

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

Customize Your Commands BASH allows you to customize built-in commands with the alias command • alias ls=’ls -G’ • alias ll=’ls -l’ • alias la=’ls -a’

A Quick Script Type the following into a Terminal cat << EOF > /usr/local/bin/hunt

A Quick Script Type the following into a Terminal cat << EOF > /usr/local/bin/hunt #!/bin/bash find $(pwd) -name “$1” -print EOF chmod 755 /usr/local/bin/hunt

A Better Shell Prompt • BASH uses a lot of environment variable • These

A Better Shell Prompt • BASH uses a lot of environment variable • These variables are used by built-in commands and to customize BASH • PS 1 is the variable BASH uses to style your first prompt (Prompt Style 1)

d e h H j l n r s t T @ u v

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

BASH Colors • Black • Blue • Green • Cyan • Red • Purple

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

A Custom PS 1 • [e[1; 30 m][[e[1; 34 m]u[e[1; 30 m]@[ e[0; 31

A Custom PS 1 • [e[1; 30 m][[e[1; 34 m]u[e[1; 30 m]@[ e[0; 31 m]h[e[1; 30 m]] @ [e[1; 30 m]w n$[e[0 m] • Produces the following prompt