The Medical University of South Carolina
Discovering...Understanding...Healing...

User

Creative Commons License

Class Description

This class deals solely with Linux (read as "cancer" if Steve Ballmer, "GNU/Linux" if Richard Stallman). The class will cover basic use of the command line and progress into shell scripting using bash. It is quite possible that we will morph into a Linux admin class, if the interest is there. All references to operating system concepts, programs, and syntax will exist within the Linux paradigm. We will not be looking at any super user specific information.

Basic Introduction (2.15.2006)

This class consists of introductory concepts and basic commands.

History of Linux

Linux is, strictly speaking, a kernel, which was released in 1991 by Linus Torvalds. The word was derived from "Linus' Minix". It is a Unix clone. Linux is not Unix. Neither is GNU. Linux is released under the GPL v2 only. More information can be found here.

Introduction to Shells

  • A command line shell provides a command line interface (CLI) to the OS (specifically, the kernel). GUIs can be considered shells, but we're not going there. Most programs start out as solely CL apps.

  • Bourne shell (sh) (UNIX, version 7, 1978)
    • ash (sh compatable, 92K)
    • bash (Bourne again in 1987)
  • C shell (csh) (BSD 4.1)
    • tcsh (TENEX c shell)
  • ksh (sh/csh mix)
  • zsh (is apparently the bomb diggity, though less popular)

Some Initial Commands

  • man
  • info
  • ls
  • cd
  • pwd
  • tab completion
    • single tab to complete a command or path
    • press tab twice if the line is not completed. This means that there are multiple choices that begin with what you have started typing, and all of the possible choices will show up on the screen.
  • paths: relative, absolute
  • how to access a shell
    • telnet does not exist
    • ssh
    • gui: xterm, gnome-terminal, aterm
    • ctrl-alt-F1 ... ctrl-alt-F6
  • mkdir
  • touch
  • rm
  • cp
  • mv (as apposed to rename)
  • echo
  • alias
  • date

Directory Structure

Location

Use

/bin

binaries for boot / may be used by users

/dev

device files

/boot

files used by boot loader

/mnt

mount points

/sbin

system binaries, mostly used by super user

/var

files that change often - logs, mail, etc.

/sys

information about the system - sysfs in memory (kernel 2.6 +)

/tmp

temporary files

/home

where everyone lives

/etc

configuration files

/root

super user home

/lib

shared libs

/usr

bins, libs, man pages, static files for users

/proc

procfs - access to processes and system information

Introduction Continued (2.22.2006)

CL Ctrl Keys

ctrl key

action

ctrl-c

interrupt

ctrl-z

force foreground process to background - suspend

ctrl-a

beginning of line

ctrl-e

end of line

ctrl-k

cut after cursor

ctrl-u

cut whole line

ctrl-y

paste

More Commands

  • ln: creating symbolic / hard links
  • chmod
  • ps
  • reset
  • uname
  • grep
  • find
  • locate
  • history
  • compression (zip, gzip, bzip) and tar
  • file
  • tac, head, tail, wc,

Meet Bash

  • bash is a program, you can run bash from within bash
  • startup scripts
    • /etc/profile
    • ~/.bash_profile
    • ~/.bash_login
    • ~/.profile
  • another file
    • ~/.bash_history
  • login exit script
    • ~/.bash_logout
  • non login shell startup
    • ~/.bashrc
  • escape character
  • commands on more than one line
  • variables: assignment and evaluation
  • environment
  • set
  • assignment
  • export to environment
  • $(<stmt>)

  • math - (())
  • backticks
  • multiple commands (;,&&,||)

  • code blocks: { }
  • stty -a

Processes

  • init - the parent of all processes
  • forking (&)

  • bg
  • fg
  • kill, killall
  • killing daemon children (ps -l)
  • killing zombies (you cannot kill the dead) / orphans
  • top

Bash I/O Features

  • file descriptors (stdout(1), stdin(0), stderr(2)), 1>, 1>>, 2>, 2>>, &>, 2>&1

  • I/O redirection (<,>,<<,>>)

  • pipes (|)

Introduction to Text Editors

  • vi
  • emacs
  • pico

Bash Scripting Basics (3.1.2006)

First Bash Script

#!/bin/bash
echo hello, I am a script
sleep 2
echo I am talking to $(whoami)
exit 0

Important Scripting Commands

  • clear
  • source
  • exec
  • eval
  • exit
  • export
  • let
  • read
  • trap
  • wait
  • test
  • tee

Advanced Bash Scripting (3.8.2006)

  • loops (for, while)
  • comparisons
  • arithmetic and string comparisons
  • functions
  • arrays
  • arguments

TBA (3.15.2006)

Example Scripts

Additional Resources

CarcWiki: Documentation/LinuxCommandLine (last edited 2006-03-01 14:40:24 by BrianMuller)

171 Ashley Avenue · Charleston SC 29425 · (843) 792-2300