Unix Old Book
Unix Old Book
3/5/13 11:00 AM
This book includes material from the http://www.osdata.com/ website and the text book on computer
programming.
Distributed on the honor system. Print and read free for personal, non-profit, and/or educational purposes.
If you like the book, you are encouraged to send a donation (U.S dollars) to Milo, PO Box 5237, Balboa
Island, California, USA 92662.
This is a work in progress. For the most up to date version, visit the website http://www.osdata.com/ and
http://www.osdata.com/programming/shell/unixbook.pdf Please add links from your website or Facebook
page.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 1 of 319
3/5/13 11:00 AM
requirements
You need a willingness to learn.
You need a working computer or server or access to one.
The computer needs a working version of UNIX, Linux, Mac OS X, AIX, HP/UX, Solaris, etc. (it can be a
dual boot computer).
The new version of Mac OS X 10.8.1 (Mountain Lion) is now available on the Mac App Store at
www.apple.com as of August 23, 2012. The new version of Mac OS X 10.8 (Mountain Lion) is now
available on the Mac App Store at www.apple.com as of July 25th, 2012. Tell them you heard about it from
www.osdata.com when you register your new copy.
You need a working connection to the internet, preferably a high speed connection.
You may want to have a domain name of your own and web hosting to try out controlling a server. There
is a chapter on how to use GoDaddy to obtain these servcies for low cost with great telephone tech support.
The OSdata.com website where this book is offered to the public is hosted by Host Gator. You may use any
other hosting service you want.
options
Almost anyone can learn this material. It isnt complicated. It really helps if you enjoy doing this kind of
thing. You will learn faster and you will enjoy the work. If you dont enjoy this kind of computer activity,
please think carefully about whether or not you want to spend decades at a job you hate.
Almost anyone can slog through and learn at least some of this material, but an aptitude for this material
greatly helps learning. If you are strong at grammar, then you will probably be able to master. This material.
mathematical ability is useful, but not necessary.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 2 of 319
3/5/13 11:00 AM
Many portions of this book require root or administrator access. While you learn better if you can actually
try out each command for yourself, you can just read about root material if you dont have root or
administrator access.
Some portions of this book require special software. Most of the software can be downloaded for free.
Those with Mac OS X should have the Developer Tools installed. These are available for free on either the
install DVD/CD or from Apple at http://connect.apple.com/
A static IP address is in general useful and is required for some portions of this book.
goals
Please note that at the time this paragraph was written, these goals are not yet implemented in the text.
Now is a good time to make suggestions on modifications of the goals.
The reader will understand the UNIX computing environment and history.
The reader will be able to access the UNIX system and perform basic operations, including using help
features.
The reader will be able to access and manipulate files and directories, including basic and advanced
directory and file management. The reader will be able to use file system utilities.
The reader will be able to design and implement file system security.
The reader will be able to print documents.
The reader will be able to perform system backups and restores.
The reader will be able to troubleshoot system processes.
The reader will be able to perform environment customization.
The reader will become acquainted with networks, web servers, web clients, transaction security, and other
basic network concepts.
The reader will learn how to create a web page that accepts input, program the server response, and
interface the input with a database.
The reader will understand web server functionailty and be able to install and configure Apache.
The reader will be able to work with, understand, and configure DNS functionality.
The reader will be able to set up and maintain his or her own general purpose server, including hosting,
server administration, security, user interactivity, and database integration.
The reader will be familiar with SQL Server architecture and able to efficiently administer and maintain
SQL Server instances and databases.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 3 of 319
3/5/13 11:00 AM
The reader will be able to secure a web server and its websites.
chapter contents
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 4 of 319
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
3/5/13 11:00 AM
du
processes
ps
kill
nice
w
uptime
uname
top
lsof
free
vmstat
defaults (screencapture; Mac Flashback Trojan)
init (init; Linux run levels)
sendmail
ifconfig (view configuration; static IP address)
arp
netstat (view connections; main info; routing address)
route (view connections; routing commands)
ping (test packets; measuring)
nslookup
traceroute (entire route; etiquette)
curl
sysstat
at (example; removing a job; timing)
back ups
tar
touch (multiple files; specific time)
find
sed (fixing end of line; adding line numbers)
awk (remove duplicate lines)
screencapture (from graphic user interface; changing defaults; command line screenshots)
signals
kernel modules
LAMP
installing software from source code
test bed
Appendix:
A.
B.
C.
D.
command summaries
computer history
critical reasoning
Forth-like routines
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 5 of 319
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Page 6 of 319
3/5/13 11:00 AM
definitions
UNIX is one of the ground-breaking operating systems from the early days of computing. Mac OS X is
built on top of UNIX. Linux is a variation of UNIX.
The shell is the command line interface for running UNIX (and Mac OS X and Linux) with just typing (no
mouse).
operating system The software that provides a computers basic tasks, such as scheduling tasks,
recognizing input from a keyboard, sending output to a display screen or printer, keeping track of files and
folders (directories), running applications (programs), and controlling peripherals. Operating systems are
explained in more detail for beginners just below.
UNIX UNIX (or Unix) is an interactive multi-user multitasking timesharing operating system found on
many types of computers. It was invented in 1969 at AT&Ts Bell Labs by a team led by Ken Thompson and
Dennis Ritchie. Some versions of UNIX include: AIX, A/UX, BSD, Debian, FreeBSD, GNU, HP-UX, IRIX,
Linux, Mac OS X, MINIX, Mint, NetBSD, NEXTSTEP, OpenBSD, OPENSTEP, OSF, POSIX, Red Hat
Enterprise, SCO, Solaris, SunOS, System V, Ubuntu, Ultrix, Version 7, and Xenix.
Linux An open-source version of the UNIX operating system.
graphical user interface A graphical user interface (GUI) is a windowing system, with windws, icons,
and menus, operated by a mouse, trackball, touch screen, or other pointing device, used for controlling an
operating system and application programs (apps). The Macintosh, Windows, Gnome, and KDE are famous
examples of graphical user interfaces.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 7 of 319
3/5/13 11:00 AM
command line interface A command line interface (CLI orcommand line user interface CLUI) is a text
only interface, operated by a keyboard, used for controlling an operating system and programs.
shell The shell is the command line interface for UNIX, Linux, and Mac OS X. In addition to intrepetting
commands, it is also a programming language.
shell uses
The UNIX shell is a very powerful programming language, with access to hundreds of useful tools that are
designed to work with each other, and access to the very heart of the operating system (although this is only
available to the root or superuser account for security reasons).
UNIX (and therefore also Mac OS X and Linux) has more than 200 basic commands (also called tools or
utilities) that are distributed with the standard operating system. This collection and the ease with which they
work together is the major source of the power of UNIX. The vast majority of these standard tools are
designed to be used from a command line (the shell).
The shell is most commonly used to control servers. Servers are the computers used to host websites. The
most common operating system for the worlds web servers is Linux. If you learn shell scripting and system
administration, you can run your own server and possibly get a job.
The shell can be used to control a desktop or portable computer. Some tablets and smart phones have a
shell. The iPhone actually has a shell, but it cant be accessed witout jailbreaking the iPhone.
The shell will often run even when a computer is partly broken. Both Mac OS X and Linux (as well as
almost all versions of UNIX) can be run in a special single user mode. This starts up the computer or server
with just the command line shell running. This can be used to service a computer or server, including both
diagnosis and repair.
The shell is extremely useful for programming. Even when a programmer uses a graphical integrated
development environment (IDE), the programmer is likely to still heavily use the shell for programming
support. Some IDEs even have shell access built-in.
Shell scripts are widely used by system administrators for performing common tasks.
Page 8 of 319
3/5/13 11:00 AM
backward compatible and still run shell scripts that are decades old, but essential to continued operation of
legacy systems.
This historical limitation makes it difficult for newcomers to figure out how to use a UNIX/Linux shell.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 9 of 319
3/5/13 11:00 AM
On Ubuntu Linux, look in Applications menu > Accessories > Terminal. Single click and hold, then drag
to your panel, because you will be using it a lot.
On some versions of Linux, you can press the CONTROL and the ALT and the F1 keys all at once to bring
up Terminal.
In Gnome, use the Applications menu > Accessories > Terminal or the keyboard shortcut of CONTROL
and ALT and T (all at the same time).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 10 of 319
3/5/13 11:00 AM
In KDE, use the KMenu > System > Terminal Program (Konsole).
In Linux Mint you can use the keyboard shortcut of holding down the CONTROL and ALT and T keys all
at once.
warnings
Be careful about any hints you find on the internet. There are people who suggest very destructive
commands in the guise of a useful or fun hint just to trick beginners into destroying their computers.
Be very careful if you use any command that includes sudo, because it runs at the root level, allowing
complete access to the entire computer with all safeguards turned off. Very powerful. Potentially very
distructive in a hurry. There are legitimate hints and cool tricks that use sudo, but be careful to type them
exactly as you you see them in the hint (or copy and paste) and only use sudo hints from trusted soruces.
Watch out for anything that includes the command rm or rm *. That is the remove command versions of it
can literally wipe out all of your hard drives in seconds in such a way that only a very expensive data
recovery specialist (thousands of dollars) can get your data back.
Also watch out for anything that includes the command shred. That is the secure delete and even the most
expensive data recovery specialist in the world cant get your data back.
Page 11 of 319
3/5/13 11:00 AM
play a CD
On Linux you can play a CD from the command line. The following example plays the first track of the
CD. Change the number to play a different track.
$ cdplay play 1
On Linux you can get a free coffee cup holder (eject the CD-ROM tray).
$ eject
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 12 of 319
3/5/13 11:00 AM
basics of computers
chapter 2
summary
This chapter will cover some very basic information on how computers work. Im not trying to insult
anyones intelligence. This material addresses some of the questions asked by novice test readers.
definitions
UNIX is one of the ground-breaking operating systems from the early days of computing. Mac OS X is
built on top of UNIX. Linux is a variation of UNIX.
The shell is the command line interface for running UNIX (and Mac OS X and Linux) with just typing (no
mouse).
operating system The software that provides a computers basic tasks, such as scheduling tasks,
recognizing input from a keyboard, sending output to a display screen or printer, keeping track of files and
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 13 of 319
3/5/13 11:00 AM
folders (directories), running applications (programs), and controlling peripherals. Operating systems are
explained in more detail for beginners just below.
UNIX UNIX (or Unix) is an interactive multi-user multitasking timesharing operating system found on
many types of computers. It was invented in 1969 at AT&Ts Bell Labs by a team led by Ken Thompson and
Dennis Ritchie. Some versions of UNIX include: AIX, A/UX, BSD, Debian, FreeBSD, GNU, HP-UX, IRIX,
Linux, Mac OS X, MINIX, Mint, NetBSD, NEXTSTEP, OpenBSD, OPENSTEP, OSF, POSIX, Red Hat
Enterprise, SCO, Solaris, SunOS, System V, Ubuntu, Ultrix, Version 7, and Xenix.
Linux An open-source version of the UNIX operating system.
graphical user interface A graphical user interface (GUI) is a windowing system, with windws, icons,
and menus, operated by a mouse, trackball, touch screen, or other pointing device, used for controlling an
operating system and application programs (apps). The Macintosh, Windows, Gnome, and KDE are famous
examples of graphical user interfaces.
command line interface A command line interface (CLI orcommand line user interface CLUI) is a text
only interface, operated by a keyboard, used for controlling an operating system and programs.
shell The shell is the command line interface for UNIX, Linux, and Mac OS X.
the shell
UNIX (and therefore also Mac OS X and Linux) has more than 200 basic commands (also called tools or
utilities) that are distributed with the standard operating system. This collection and the ease with which they
work together is the major source of the power of UNIX. The vast majority of these standard tools are
designed to be used from a command line (the shell).
A shell is primarily a command interpreter.
In a graphical user interface such as Macintosh or Windows, the user controls the computer and programs
primarily through pointing and clicking, supplemented by some typing.
In a shell, all of the commands are typed. The shell figures out the meaning of what you typed and then has
the computer do as instructed.
But the shell is much more than just a command interpreter. It is also a complete programming language.
Because the shell is a complete programming language, with sequences, decisions, loops, and functions, it
can do things well beyond pointing and clicking. It can take control of your computer and react to changing
circumstances.
Programming languages are used to make all of the computer programs and smart phone apps youve ever
seen or used. Your imagination is the only limit on the power of the shell. Anything that can be done with a
computer can be done with the shell.
operating systems
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 14 of 319
3/5/13 11:00 AM
The seven layers of software are (top to bottom): Programs; System Utilities; Command Shell; System
Services; User Interface; Logical Level; and Hardware Level. A Graphics Engine stradles the bottom three
layers. Strictly speaking, only the bottom two levels are the operating system, although even technical
persons will often refer to any level other than programs as part of the operating system (and Microsoft tried
to convince the Justice Department that their web browser application is actually a part of their operating
system).
The following are examples of each category:
Programs: Examples of Programs include your word processor,
spreadsheet, graphics programs, music software, games, etc.
System Utilities: Examples of System Utilities include file copy,
hard drive repair, and similar items. On the Macintosh, all the
Desk Accessories (calculator, key caps, etc.) and all of the
Control Panels are examples of System Utilities.
Command Shell: The Command Shell on the Macintosh is the
Finder and was the first commercially available graphic
command shell. On Windows, the Command Shell is a poorly
integrated comination of the File Manager and the Program
Manager. The command line (C:\ prompt) of MS-DOS or Bourne
Shell of UNIX are examples of the older style text-based
command shells.
System Services: Examples of System Services are built-in data
base query languages on mainframes or the QuickTime media
layer of the Macintosh.
User Interface: Until the Macintosh introduced Alan Kays
(inventer of the personal computer, graphic user interfaces,
object oriented programming, and software agents) ground breaking ideas on human-computer
interfaces, operating systems didnt include support for user interfaces (other than simple text-based
shells). The Macintosh user interface is called the Macintosh ToolBox and provides the windows,
menus, alert boxes, dialog boxes, scroll bars, buttons, controls, and other user interface elements shared
by almost all programs.
Logical Level of Operating System: The Logical Level of the operating system provides high level
functions, such as file management, internet and networking facilities, etc.
Hardware Level of Operating System: The Hardware Level of the operating system controls the use of
physical system resources, such as the memory manager, process manager, disk drivers, etc.
Graphics Engine: The Graphics Engine includes elements at all three of the lowest levels, from
physically displaying things on the monitor to providing high level graphics routines such as fonts and
animated sprites.
Human users normally interact with the operating system indirectly, through various programs (application
and system) and command shells (text, graphic, etc.), The operating system provides programs with services
thrrough system programs and Application Program Interfaces (APIs).
Page 15 of 319
3/5/13 11:00 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 16 of 319
3/5/13 11:00 AM
parts of a computer
The classic crude oversimplication of a computer is that it
contains three elements: processor unit, memory, and I/O
(input/output). The borders between those three terms are
highly ambigious, non-contiguous, and erratically shifting.
A slightly less crude oversimplification divides a
computer into five elements: arithmetic and logic
subsystem, control subsystem, main storage, input
subsystem, and output subsystem.
processor
arithmetic and logic
control
main storage
external storage
input/output overview
input
output
processor
The processor is the part of the computer that actually does the computations. This is sometimes called an
MPU (for main processor unit) or CPU (for central processing unit or central processor unit).
A processor typically contains an arithmetic/logic unit (ALU), control unit (including processor flags, flag
register, or status register), internal buses, and sometimes special function units (the most common special
function unit being a floating point unit for floating point arithmetic).
Some computers have more than one processor. This is called multi-processing.
The major kinds of digital processors are: CISC, RISC, DSP, and hybrid.
CISC stands for Complex Instruction Set Computer. Mainframe computers and minicomputers were CISC
processors, with manufacturers competing to offer the most useful instruction sets. Many of the first two
generations of microprocessors were also CISC.
RISC stands for Reduced Instruction Set Computer. RISC came about as a result of academic research that
showed that a small well designed instruction set running compiled programs at high speed could perform
more computing work than a CISC running the same programs (although very expensive hand optimized
assembly language favored CISC).
DSP stands for Digital Signal Processing. DSP is used primarily in dedicated devices, such as MODEMs,
digital cameras, graphics cards, and other specialty devices.
Hybrid processors combine elements of two or three of the major classes of processors.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 17 of 319
3/5/13 11:00 AM
control
Control units are in charge of the computer. Control units fetch and decode machine instructions. Control
units may also control some external devices.
A bus is a set (group) of parallel lines that information (data, addresses, instructions, and other
information) travels on inside a computer. Information travels on buses as a series of electrical pulses, each
pulse representing a one bit or a zero bit (there are trinary, or three-state, buses, but they are rare). An
internal bus is a bus inside the processor, moving data, addresses, instructions, and other information
between registers and other internal components or units. An external bus is a bus outside of the processor
(but inside the computer), moving data, addresses, and other information between major components
(including cards) inside the computer. Some common kinds of buses are the system bus, a data bus, an
address bus, a cache bus, a memory bus, and an I/O bus.
main storage
Main storage is also called memory or internal memory (to distinguish from external memory, such as
hard drives).
RAM is Random Access Memory, and is the basic kind of internal memory. RAM is called random
access because the processor or computer can access any location in memory (as contrasted with sequential
access devices, which must be accessed in order). RAM has been made from reed relays, transistors,
integrated circuits, magnetic core, or anything that can hold and store binary values (one/zero, plus/minus,
open/close, positive/negative, high/low, etc.). Most modern RAM is made from integrated circuits. At one
time the most common kind of memory in mainframes was magnetic core, so many older programmers will
refer to main memory as core memory even when the RAM is made from more modern technology. Static
RAM is called static because it will continue to hold and store information even when power is removed.
Magnetic core and reed relays are examples of static memory. Dynamic RAM is called dynamic because it
loses all data when power is removed. Transistors and integrated circuits are examples of dynamic memory.
It is possible to have battery back up for devices that are normally dynamic to turn them into static memory.
ROM is Read Only Memory (it is also random access, but only for reads). ROM is typically used to store
thigns that will never change for the life of the computer, such as low level portions of an operating system.
Some processors (or variations within processor families) might have RAM and/or ROM built into the same
chip as the processor (normally used for processors used in standalone devices, such as arcade video games,
ATMs, microwave ovens, car ignition systems, etc.). EPROM is Erasable Programmable Read Only
Memory, a special kind of ROM that can be erased and reprogrammed with specialized equipment (but not
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 18 of 319
3/5/13 11:00 AM
by the processor it is connected to). EPROMs allow makers of industrial devices (and other similar
equipment) to have the benefits of ROM, yet also allow for updating or upgrading the software without
having to buy new ROM and throw out the old (the EPROMs are collected, erased and rewritten centrally,
then placed back into the machines).
Registers and flags are a special kind of memory that exists inside a processor. Typically a processor will
have several internal registers that are much faster than main memory. These registers usually have
specialized capabilities for arithmetic, logic, and other operations. Registers are usually fairly small (8, 16,
32, or 64 bits for integer data, address, and control registers; 32, 64, 96, or 128 bits for floating point
registers). Some processors separate integer data and address registers, while other processors have general
purpose registers that can be used for both data and address purposes. A processor will typically have one to
32 data or general purpose registers (processors with separate data and address registers typically split the
register set in half). Many processors have special floating point registers (and some processors have general
purpose registers that can be used for either integer or floating point arithmetic). Flags are single bit memory
used for testing, comparison, and conditional operations (especially conditional branching).
external storage
External storage (also called auxillary storage) is any storage other than main memory. In modern times
this is mostly hard drives and removeable media (such as floppy disks, Zip disks, DVDs, CDs, other optical
media, etc.). With the advent of USB and FireWire hard drives, the line between permanent hard drives and
removeable media is blurred. Other kinds of external storage include tape drives, drum drives, paper tape, and
punched cards. Random access or indexed access devices (such as hard drives, removeable media, and drum
drives) provide an extension of memory (although usually accessed through logical file systems). Sequential
access devices (such as tape drives, paper tape punch/readers, or dumb terminals) provide for off-line storage
of large amounts of information (or back ups of data) and are often called I/O devices (for input/output).
input/output overview
Most external devices are capable of both input and output (I/O). Some devices are inherently input-only
(also called read-only) or inherently output-only (also called write-only). Regardless of whether a device is
I/O, read-only, or write-only, external devices can be classified as block or character devices.
A character device is one that inputs or outputs data in a stream of characters, bytes, or bits. Character
devices can further be classified as serial or parallel. Examples of character devices include printers,
keyboards, and mice.
A serial device streams data as a series of bits, moving data one bit at a time. Examples of serial devices
include printers and MODEMs.
A parallel device streams data in a small group of bits simultaneously. Usually the group is a single eightbit byte (or possibly seven or nine bits, with the possibility of various control or parity bits included in the
data stream). Each group usually corresponds to a single character of data. Rarely there will be a larger group
of bits (word, longword, doubleword, etc.). The most common parallel device is a printer (although most
modern printers have both a serial and a parallel connection, allowing greater connection flexibility).
A block device moves large blocks of data at once. This may be physically implemented as a serial or
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 19 of 319
3/5/13 11:00 AM
parallel stream of data, but the entire block gets transferred as single packet of data. Most block devices are
random access (that is, information can be read or written from blocks anywhere on the device). Examples of
random access block devices include hard disks, floppy disks, and drum drives. Examples of sequential
access block devcies include magnetic tape drives and high speed paper tape readers.
input
Input devices are devices that bring information into a computer.
Pure input devices include such things as punched card readers, paper tape readers, keyboards, mice,
drawing tablets, touchpads, trackballs, and game controllers.
Devices that have an input component include magnetic tape drives, touchscreens, and dumb terminals.
output
Output devices are devices that bring information out of a computer.
Pure output devices include such things as card punches, paper tape punches, LED displays (for light
emitting diodes), monitors, printers, and pen plotters.
Devices that have an output component include magnetic tape drives, combination paper tape
reader/punches, teletypes, and dumb terminals.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 20 of 319
3/5/13 11:00 AM
UNIX history
When UNIX came into existence digital computers had been in commercial use for more than a decade.
Mainframe computers were just starting to be replaced by minicomputers. The IBM 360 mainframe
computer and clones by other manufacturers was still the dominant computer. The VAX, with its virtual
memory addressing, was still in development. Microcomputers were just an experimental idea. The CDC
mainframe, a forerunner of the more famous Cray supercomputers, was still the worlds fastest computer.
COBOL was the most common programming language for business purposes. FORTRAN was the most
popular programming language for scientific and systems programming. PL/I was a common third language.
ALGOL was dominate in the academic community.
Most data entry was still performed using punched cards. Directly connected terminals were typically
teletypes (TTY), a technology originally developed for telegraph systems. New terminals combining a
keyboard and a monitor were still rare. These were also called CRTs (for Cathode Ray Tube) or dumb
terminals or smart terminals (depending on the capabilities). Unlike modern black letters on white
background terminals (pioneered with the Apple Lisa and Apple Macintosh) and full color monitors
(popularized with the Atari and Commodre Amiga personal computers), these monitors were a single color
phosphor (usually green) on a dark gray background. Even though disk drives existed, they were expensive
and had small capacities. Magnetic tape was still the most commonly used form of storage of large data sets.
Minicomputers were making use of punched paper tape.
Interactive computing was still rare.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 21 of 319
3/5/13 11:00 AM
Bell Telephone Laboratories was still using the BESYS operating system from 1957. In 1964, Bell Labs
decided to update their operating system, leading to a 1965 partnership between the Massachusetts Institute
of Technology (MIT), AT&T Bell Labs, and General Electric to create an experimental operating system
called Multics (MULTIplexed operating and Computing System) for the GE-645 mainframe computer.
AT&T intended to offer subscription-based computing services over the phone lines, an idea similar to the
modern cloud approach to computing.
While the Multics project had many innovations that went on to become standard approaches for operating
systems, the project was too complex for the time.
Bell Labs pulled out of the Multics project in 1969.
Ken Thompson and Dennis Ritchie offered to design a new operating system using a DEC PDP-7
computer that was available at the time.
UNICS (UNIplexed operating and Computing System, a pun on MULTICS) was created at AT&Ts Bell
Labs in 1969 by a group that included Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy,
Michael Lesk and Joe Ossanna.
This group of researchers, the last of the AT&T employees involved in Multics, decided to attempt the
goals of Multics on a much more simple scale.
What we wanted to preserve was not just a good environment in which to do programming, but a system
around which a fellowship could form. We knew from experience that the essence of communal computing,
as supplied by remote-access, time-shared machines, is not just to type programs into a terminal instead of a
keypunch, but to encourage close communication, according to Dennis Ritchie.
UNIX was originally intended as a programmers workbench. The original version was a single-user
system. As UNIX spread through the academic community, more general purpose tools were added, turning
UNIX into a general purpose operating system.
While Ken Thompson still had access to the Multics environment, he wrote simulations on Multics for
UNIXs file and paging system.
Ken Thompson ported the Space Travel computer game from Multics to a Digital Equipment Corporation
(DEC) PDP-7 he found at Bell Labs.
Ken Thompson and Dennis Ritchie led a team of Bell Labs researchers (the team included Rudd Canaday)
working on the PDP-7 to develop a hierarchial file system, computer processes, device files, a command-line
interpreter, and a few small utility programs.
Early work was done in a BCPL (Basic Combined Programming Language) a language intended for
writing compilers and system software. BCPL was simplified and revised into the B programming language.
By the end of 1969, UNICS had a primitive kernel, an editor, an assembler, a simple shell command
interpreter, and a few basic command utilities, including rm, cat, and cp.
The first UNIX command shell, called the Thompson shell and abbreviated sh, was written by Ken
Thompson at AT&Ts Bell Labs, was much more simple than the famous UNIX shells that came along later.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 22 of 319
3/5/13 11:00 AM
The Thompson shell was distributed with Versions 1 through 6 of UNIX, from 1971 to 1975.
In 1970 Dennis Ritchie and Ken Thompson traded the promise to add text processing capabilities to UNIX
for the use of a Digital Equipment Corporation (DEC) PDP-11/20. The initial version of UNIX, a text editor,
and a text formatting program called roff were all written in PDP-11/20 assembly language.
The PDP-11/20 computer had 24K of RAM. The operating system used 12K. The remaining 12K was split
between application programs and a RAM disk. The file size limit was 64K and the disk size limit was 512K.
Soon afterwards roff evolved into troff with full typesetting capability. The first UNIX book, UNIX
Programmers Manual, by Ken Thompson and Dennis Ritchie, was published on November 3, 1971. The
book described more than 60 commands, including b (compile a B program), chdir (change working
directory), chmod, chown, ls, and who.
By 1971, many fundamentally important aspects of UNIX were already in place, including file ownership
and file access permissions.
The first commercial UNIX system was installed in early 1972 at the New York Telephone Co. Systems
Development Center under the direction of Dan Gielan. Neil Groundwater build an Operational Support
System in PDP-11/20 assembly language.
With funding from the Patent Department, the UNIX team upgraded to a DEC PDP-11/45.
In 1972, Dennis Ritchie and Ken Thompson rewrote the B programming language into C. Work started on
converting UNIX to C. UNIX was originally written in assembly language and B, but by 1973 it had been
almost completely converted to the C language. At the time it was common belief that operating systems
must be written in assembly in order to perform at reasonable speeds. Writing UNIX in C allowed for easy
portability to new hardware, which in turn led to the UNIX operating system being used on a wide variety of
computers.
Ken Thompson invented the pipe in 1972. Pipes allow the output of one process to be used as the input for
another. Pipes allow the UNIX philosophy of having many small programs that each do one function very
well and then write scripts that combine these small utility programs to accomplish bigger tasks.
By 1973, UNIX was running at sixteen (16) sites, all within AT&T and Western Electric. UNIX was
presented to the public in an October 1973 conference and within six months the number of sites running
UNIX had tripled.
A version of UNIX was published in the July 1974 issue of the Coomunications of the ACM, leading to
widespread requests for copies. Under the antitrust consent decree with the U.S. government, Bell Labs was
required to give a free copy to anyone who requested it. Ken Thompson personally signed a note for many of
these early copies.
Because C was a complete, platform-independent programming language and UNIXs more than 11,000
lines of code were written in C, it was possible to easily port UNIX to any computer platform. And UNIX did
quickly spread to almost every available computer platform, becoming the first true universal operating
system.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 23 of 319
3/5/13 11:00 AM
In fall of 1974, Ken Thompson went to the University of California at berkeley to teach for a year. Ken
Thompson, Bill Joy, and Chuck Haley worked together to create the Berkeley version of UNIX, called the
Berkeley Software Distribution, or more commonly BSD.
The souce code for BSD UNIX was widely distributed to students and other schools. Students at UCBerkeley and other schools around the world worked on improvements and the BSD UNIX replaced the Bell
Laboratories UNIX as the primary UNIX.
BSD UNIX added the vi editor, the C shell, the Sendmail email system, virtual memory, and support for
TCP/IP (Transmission Control Protocol/Internet Protocol). Because email was built into the operating
system, email was the method UNIX used for sending notifications to the system administrator of system
status, reports, problems, etc.
The Fifth Edition of UNIX was released in 1975 and licensed to universities for free.
The PWB shell or Mashey shell, abbreviated sh, was a variation of the Thompson shell that had been
augmented by John Mashey and others at Bell Labs. The Mashey shell was distributed with the
Programmers Workbench UNIX in 1976.
The Bourne shell, created by Stephen Bourne at AT&Ts Bell Labs (in New Jersey) as a scripting
language, was released in 1977 as the default shell in the Version 7 Unix release distributed to colleges and
universities. It gained popularity with the publication of The UNIX Programming Environment by Brian W.
Kernighan and Rob Pike. The book was the first commercially published tutorial on shell programming.
In 1977, the University of California, Berkeley, released the Berkeley Software Distribution (BSD) version
of UNIX, based on the 6th edition of AT&T UNIX.
The C shell, abbreviated csh, was created by Bill Joy, a graduate student at the University of California,
Berkeley. With additional work by Michael Ubell, Eric Allman, Mike OBrien, and Jim Kulp, it was released
in the 2BSD release of BSD Unix in 1978.
It became common to use the C shell for everyday interactive computing and to use the Bourne shell for
script programming.
The improved C shell, abbreviated tcsh, was created by Ken Greer by September 1975 and merged into
the C shell in December 1983. Ken Greer based the shell on the TENEX operating system (hence, the t in
tsch). Mike Ellis, Paul Placeway, and Christos Zoulas made major contributions to tcsh.
The release of the Seventh Edition of UNIX in 1978 led to the divergence of UNIX on the System V (Bell
Labs) and BSD (Berkeley) paths. System V was often called sys-five. System V was the for pay version and
BSD was the free open source version.
The Korn shell, abbreviated ksh, was created by David Korn at AT&Ts Bell Labs and announced at
USENIX on July 14, 1983. Mike Veach and Pat Sullivan were also early contributors. The Korn shell added
C shell features to the Bourne shell.
When the AT&T broke up in 1984 into Baby Bells (the regional companies operating local phone
service) and the central company (which had the long distance business and Bell Labs), the U.S. government
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 24 of 319
3/5/13 11:00 AM
which stands for Bourne Again SHell, was created by Brian Fox for the Free Software Foundation
and first released on June 7, 1989. bash combined features from the Bourne shell, the C shell, and the Korn
shell. bash is now the primary shell in both Linux and Mac OS X.
The Z shell, abbreviated zsh, was written by Paul Flastad in 1990 when he was a student at Princton
University.
The Linux operating system was first released on September 17, 1991, by Finnish student Linus Torvalds.
With the permission of Andrew S. Tanenbaum, Linus Torvalds started work with MINIX. There is no
MINIX source code left in Linux. Linux Torvalds wrote Linux using the GNU C compiler running on MINIX
on an Intel 80386 processor.
Linus Torvalds started work on open source Linux as a college student. After Mac OS X, Linux is the most
widely used variation of UNIX.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 25 of 319
3/5/13 11:00 AM
Linux is technically just the kernel (innermost part) of the operating system. The outer layers consist of
GNU tools. GNU was started to guarantee a free and open version of UNIX and all of the major tools
required to run UNIX.
In 1992 Unix System Laboratories sued Berkeley Software Design, Inc and the Regents of the University
of California to try to stop the distribution of BSD UNIX. The case was settled out of court in 1993 after the
judge expressed doubt over the validity of USLs intellectual property.
See the appendix for a more detailed summary of the history of computers.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 26 of 319
3/5/13 11:00 AM
choice of shells
chapter 4
summary
This chapter looks at the shells available for Linux and UNIX.
This includes an explanation of what a shell is and a list of the popular shells.
what is a shell?
UNIX (and therefore also Mac OS X and Linux) has more than 200 basic commands (also called tools or
utilities) that are distributed with the standard operating system. This collection and the ease with which they
work together is the major source of the power of UNIX. The vast majority of these standard tools are
designed to be used from a command line (the shell).
A shell is primarily a command interpreter.
In a graphical user interface such as Macintosh or Windows, the user controls the computer and programs
primarily through pointing and clicking, supplemented by some typing.
In a shell, all of the commands are typed. The shell figures out the meaning of what you typed and then has
the computer do as instructed.
But the shell is much more than just a command interpreter. It is also a complete programming language.
Because the shell is a complete programming language, with sequences, decisions, loops, and functions, it
can do things well beyond pointing and clicking. It can take control of your computer and react to changing
circumstances.
Programming languages are used to make all of the computer programs and smart phone apps youve ever
seen or used. Your imagination is the only limit on the power of the shell. Anything that can be done with a
computer can be done with the shell.
choice of shells
Most versions of UNIX and Linux offer a choice of shells.
The term shell comes from a concept of UNIX being a series of layers of software that work together
rather than one single monolithic operating system program. The command line shell was part of the outer
shell of a series of programs that eventually reach down to the kernel or innermost portion of the operating
system.
Steve Bourne created the original Bourne shell called sh.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 27 of 319
3/5/13 11:00 AM
Some other famous shells were C Shell (csh), Korn Shell (ksh), Turbo C Shell (tsch), and the Z Shell (zsh).
A shell that combined the major advntages of each of these early shells was the Bourne Again SHell (BASH).
The default shell in Linux and MacOS X is normally BASH (Bourne Again SHell). The following
instruction assumes the use of BASH.
It is possible to change the shell you are currently using (especially useful if you need to run a line or script
from an alternative shell).
original shell
The original shell, called the Thompson shell and abbreviated sh was written by Ken Thompson at
AT&Ts Bell Labs, was very rudimentary. The Thompson shell was distributed with Versions 1 through 6 of
UNIX, from 1971 to 1975.
Note that the same sh is also used for other shells, including the Bourne shell.
The PWB shell or Mashey shell, abbreviated sh, was a variation of the Thompson shell that had been
augmented by John Mashey and others at Bell Labs. The Mashey shell was distributed with the
Prorgammers Workbench UNIX in 1976.
Bourne shell
Stephen Bourne created the Bourne shell, abbreviated sh, at AT&Ts Bell Labs in New Jersey as a
scripting language.
The Bourne shell was released in 1977 as the default shell in the Version 7 Unix release distributed to
colleges and universities. It gained popularity with the publication of The UNIX Programming Environment
by Brian W. Kernighan and Rob Pike. The book was the first commercially published tutorial on shell
programming.
The Bourne shell (or a shell that is compatible and will run Bourne shell scripts) is usually located at
/bin/sh.
C shell
The C shell, abbreviated csh, was created by Bill Joy, a graduate student at the University of California,
Berkeley. With additional work by Michael Ubell, Eric Allman, Mike OBrien, and Jim Kulp, it was released
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 28 of 319
3/5/13 11:00 AM
Korn shell
The Korn shell, abbreviated ksh, was created by David Korn at AT&Ts Bell Labs and announced at
USENIX on July 14, 1983. Mike Veach and Pat Sullivan were also early contributors.
After years of UNIX users having to learn two different shells, one for scripting and oen for interactive
control, David Korn built the Korn shell by adding C shell features to the Bourne shell.
In addition to adding command history, history substitution, aliases, and file name completion from the C
shell, the Korn shell also included arrays and built-in integer arithmetic.
The three major versions of the Korn shell are the official version ksh, the public domain version pdksh,
and the desktop version dtksh
CDE shipped with the Desktop version of the Korn shell.
The POSIX shell is a variant of the Korn Shell. HP shipped the POSIX shell with HP-UX 11.0
BASH shell
bash, which stands for Bourne Again SHell, was created by Brian Fox for the Free Software Foundation
and first released on June 7, 1989.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 29 of 319
3/5/13 11:00 AM
bash combined features from the Bourne shell, the C shell (both the original C shell and tcsh), and the
Korn shell, while using the syntax of the original Bourne shell, allowing it to run almost all historical Bourne
shell scripts. bash is now the primary shell in both Linux and Mac OS X.
tt>bash introduced name completion for variable names, usernames, host names, and commands (in
addition to file names), spelling correction for pathnames in the cd command, arrays of unlimited size, and
integer arithmetic in any base from 2 to 64.
Z shell
The Z shell, abbreviated zsh, was written by Paul Flastad in 1990 when he was a student at Princton
University.
The Z shell combines features of the Bourne Shell, the C shell, and bash.
other shells
The POSIX shell, abbrevaited sh, (POSIX = Portable System Interface) is based on the Korn shell and is
the official IEEE P1003.2 shell. It is the /bin/sh shell on some systems.
The Almquist shell, abbreviated ash, was written by Keneth Almquist as a replacement for the Bourne
shell written for BSD systems. The sh in FreeBSD and NetBSD were based on the Almquist shell.
The Debian Almquist shell, abbreviated dash, is a modern replacement for the Almquist shell in Debian
and Ubuntu Linux. While the default shell in both Debian and Ubuntu Linux are bash, /bin/sh is a symlink
to ash.
ash and dash are minimalist shells that interpret scripts and are not intended for interactive use. Their
small size and fast execution time make them good for embedded systems. Because many scripts call for the
use of /bin/sh, Debian and Ubuntu UNIX gain speed of execution for scripts, while still allowing bash as
the primary interactive shell.
The Public domain Korn shell, abbreviated pdksh, is based on the Korn shell.
The MirBSD Korm shell, abbreviated mksh, is based on the OpenBSD version of the Korn shell and the
pdksh and was released as part of MirOS BSD.
Busybox is a set of tiny utilities, including a version of ash, used in embedded systems.
rc,
written by Tom Duff, was the default shell for AT&Ts Bell Labs Plan 9 and Version 10 UNIX. Plan 9
was an improved operating system based on UNIX, but was not a significant enough improvement to
overtake its predecessor. rc is available on some modern versions of UNIX and UNIX-like operating
systems.
es
Perl shell, abbreviated psh, is a shell that combines bash and the Perl scripting language. it is available for
UNIX-like and Windows operating systems.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 30 of 319
3/5/13 11:00 AM
is a profile in the IPython project that combines a UNIX-style shell with a Python scripting language
shell.
wish
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 31 of 319
3/5/13 11:00 AM
connecting to a shell
chapter 5
This chapter looks at how to connect to a shell.
If you are connecting to a remote computer (such as web server), then you can use telnet or SSH.
If you connecting to the shell from a modern graphic user interface, then you need to start up a terminal
emulator.
If you connecting to a mainframe computer, minicomputer, or the equivalent, you use any terminal
connected to the system.
physical terminal
For old style systems where UNIX runs on a mainframe or minicomputer, there will be actual physical
terminals that are connected by wires or MODEM to the mainframe or minicomputer. These systems are
increasingly rare.
The terminal may already be at the login prompt. If not, try pressing the RETURN key several times until
the login prompt shows up.
or SSH are the two basic methods for connecting to a remote server.
was the original method. There are telnet client programs available for most computer systems.
Unfortunately, telnet performs all communications in plain text, including passwords, which means that
anyone malicious along the path between you and your server can easily read the information needed to hack
into your system using your account. For this reason, many servers no longer allow telnet access.
telnet
SSH is Secure Shell. It has the same basic capabilities as the older telnet, but includes security, including
encrypted communications. There are SSH client programs for most modern computer systems.
You can also use SSH through a terminal emulator, which is how many system administrators now access
their servers from their personal or portable computer.
terminal emulator
As mentioned in the history chapter, the UNIX shells were accessed through interactive terminals,
originally teletype machines and later special combinations of keyboards and cathode ray tubes (CRTs).
There are programs for graphic user interfaces that allow you to interact with a shell as if you were using
one of those ancient terminal devices. These are called terminal emulators (they emulate the signals of a
terminal).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 32 of 319
3/5/13 11:00 AM
Some common terminal emulators include eterm, gnome-terminal, konsole, kvt, nxterm, rxvt, terminal,
and xterm.
Note that if you are logging in to a web server or other remote computer, you should use an SSH (Secure
SHell) client program instead of a terminal emulator. A terminal emulator program is for gaining shell access
to a personal computer or workstation. With a little bit more knowledge, you can use the shell on a personal
computer or workstation as your SSH client.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 33 of 319
3/5/13 11:00 AM
shell basics
chapter 6
summary
This chapter looks at UNIX (and Linux) shell basics.
This includes an explanation of what a shell is, how to get to your shell, and a simple example of how to
use your shell.
The short version of this chapter is to start up your terminal emulator (or SSH client), type in your account
name at the login prompt, followed by your password at the password prompt (using the RETURN or
ENTER button at the end of each line). Then type a valid command (such as who) and an invalid command
(such as asdf) and see the results. The rest of the commentary helps you through common questions and
problems.
book conventions
The following conventions are used in this book.
Examples are displayed in a gray box. In the PDF version of this book the gray box does not appear, but
the box is indented from the regular text. In the on-line version at www.osdata.com the gray box displays
correctly. I need to find someone with a legal copy of Adobe Acrobat to help out. If you are in the Costa
Mesa, California, area and can help out with a legal copy of Adobe Acrobat, please contact me.
Additionally, anything that will appear on the screen (whether you type it or the shell produces it as output)
will appear in a monospace type. This will help identify the examples in the PDF version. This also applies
to material contained in ordinary descriptive paragraphs that you will type.
$ date
Wed Nov 10 18:08:33 PST 2010
$
Bold italics type is used to indicate items that you must customize, such as file names or user account
name. In a descriptive paragraph, these items will be in ordinary italics.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 34 of 319
3/5/13 11:00 AM
$ AccountName
Material that the shell will output will be in ordinary monospace type. In some cases where the material
will be variable, the shell output will be in italics.
Wed Nov 10 18:08:33 PST 2010
VariableInformation
$
root or superuser
Do not run your terminal emulator or shell in root or superuser.
Root or superuser has complete control over the entire computer. A regular user account has limitations.
Experienced programmers run BASH as a regular user to protect themselves from destructive mistakes
and they are already skilled at using BASH.
A beginner running BASH as superuser or root can turn a simple typing mistake into a disaster.
If you already have a regular user account created, make sure you use it. If you only have the superuser or
root account running, immediately create a regular user account and switch to it for all of your learning
exercises.
Both the Bourne style shells (including BASH) and the C style shells display a # prompt when you are
running the shell as root. Be careful.
#
Page 35 of 319
3/5/13 11:00 AM
available. You do not have to have a matching operating system. You can use an SSH client program on
Windows, Macintosh, Linux, or almost any other operating system to sign into a Linux or UNIX server.
You login into a large multi-user traditional command line UNIX system by typing your user name,
ENTER, your password, and ENTER (in that order). This will enter you into the default shell set up for your
account.
On a computer that runs a graphic interface (such as Gnome, KDE, and Mac OS X) you will want to use a
terminal emulator program. Typically a terminal emulator program starts with you already logged-in to the
same account that you have running in the graphic user interface.
On Mac OS X and most versions of Linux, the icon for the Terminal program will look like this:
On a Mac OS X computer, Terminal will be located in the Utilities directory, which is located in the
Applications directory. When you find it, you can drag it onto the Dock to make it easily accessible. Apple
purposely hid the UNIX command line to avoid confusing the typical consumer.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 36 of 319
3/5/13 11:00 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 37 of 319
3/5/13 11:00 AM
In KDE, use the KMenu > System > Terminal Program (Konsole).
In Linux Mint you can use the keyboard shortcut of holding down the CONTROL and ALT and T keys all
at once.
You may want to try out the various terminal emulators and decide which works best for you (each offer
slightly different features).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 38 of 319
3/5/13 11:00 AM
prompt
Once the shell is running it will present a shell prompt. This shell prompt is normally the U.S. dollar sign (
$ ). Other common prompts are the percent sign ( % ) and the pound sign ( # ). The shell prompt lets you
know that the shell is ready and waiting for your input.
$
The most common prompt in the Bourne shell (sh or bsh) and Bourne Again shell (bash) and Korn shell
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 39 of 319
3/5/13 11:00 AM
When the the Bourne Again shell (bash) or Korn shell (ksh) is running as root or superuser, the prompt is
changed to the U.S. number or pound sign ( # ) as a clear reminder that you are using a much more powerful
account.
#
The Bourne Again shell (bash) shell typically reports the current working directory and user name before
the $ prompt, often inside of square braces. An example:
[admin:~ admin]$
The most common prompt in the C shell (csh) and TENEX C shell (tsch) is the percent sign ( % ).
%
When running as root or superuser, the C shell (csh) shows the U.S. number or pound sign sign ( # ).
#
The Z shell (zsh) shows the short machine name followed by the percent sign ( % ).
mac%
When running as root or superuser, the Z shell (zsh) shows the short machine name followed by the U.S.
number or pound sign sign ( # ).
mac#
Almost all of the shell examples in this book will use bold face to show what you type and plain fixed
space characters to show shell output. Items that you need to modify according to your local needs are
normally going to be presented in italics.
You are likely to see information before the actual command prompt. It may the current working directory.
It may be the current user name. There are ways to change what is presented. For now, dont worry about it,
just be aware that you are likely to see some text before the prompt.
example command
You can run a UNIX (or Linux or Mac OS X) command (also called a tool) by typing its name and then
the ENTER or RETURN key.
The following example uses the date command or tool.
$ date
Wed Nov 10 18:08:33 PST 2010
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 40 of 319
3/5/13 11:00 AM
The format is: day of the week, month, day of the month, 24 hour time, time zone, year.
failed command
BASH will let you know when you have typed something it doesnt understand.
Type asdf and then the ENTER or RETURN key. You should see a message similar to the following:
$ asdf
-bash: asdf: command not found
$
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 41 of 319
3/5/13 11:00 AM
login/logout
chapter 7
summary
This chapter looks at login and logout, a pair of UNIX (and Linux) commands.
On a personal computer or workstation you probably dont need to login. You can just start your terminal
emulator (see previous chapter).
On a multi-user UNIX or Linux system, such as a web server, you will need to login. This chapter furthers
the discussion login in more detail than the previous chapters introduction, including special cases and
solutions to common problems.
In particular, this chapter discusses choosing the system and terminal type, rare options that you might
encounter.
This chapter also discusses the logout command and the importance of always logging out from a running
system.
login
login
login
is a builtin command in csh. There is also an external utility with the same name and functionality.
In many modern systems, the functionality of login is hidden from the user. The login command runs
automatically upon connection. In some old computers you may need to type a special character or even type
login to bring up the login program.
If you login remotely to a server you will be prompted for your user/account name and password. If you
start up a terminal emulator and shell from a graphic user interface you will probably already be
authenticated and immediately go to the shell (although some of the startup activity of login will still be done
for you).
The activities that login performs at startup of a shell will be covered in a later chapter, because you need
more familiarity with the shell before you can understand that material.
Starting a shell is covered in the previous chapter about shell basics.
Page 42 of 319
3/5/13 11:00 AM
You may already be logged in if you are using a terminal emulator on a personal computer or workstation.
If so, you dont need this step.
You will see a prompt indicating a choice of computer, such as (only one of these will appear):
host:
pad:
request:
system:
account name
You may already be logged in if you are using a terminal emulator on a personal computer or workstation.
If so, you dont need this step.
Ask your system administrator for your account name. If this is your own personal system, then use the
account name set up during installation. Many modern install disks include a utility for creating a new
account.
At the login: prompt, enter your account name, followed by the ENTER or RETURN key.
Type your account name in lower case letters. UNIX assumes that an account name in ALL CAPITAL
LETTERS indicates an old input/out device that doesnt support lower case letters (such as an old style
teletype, or TTY). Also, if you use upper case letters for the login, then you can not use lower case letters in
the password.
If you enter a valid account name, you will be asked for your password. On many computers, you will be
asked for a password even if you enter an incorrect password. This is a security measure to help prevent
guessing account names.
login: accountname
Password:
password
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 43 of 319
3/5/13 11:00 AM
You may already be logged in if you are using a terminal emulator on a personal computer or workstation.
If so, you dont need this step.
Ask your system administrator for your password. If this is your own personal system, then use the
password set up during installation. Many modern install disks include a utility for changing the password for
an existing account or for creating a new account with a new password.
At the Password: prompt, enter your password, followed by the ENTER or RETURN key.
Password: password
$
In some cases, a new account doesnt have a password. Also, it is common for Mac OS X to have no
password for the user account.
If your account doesnt have a password, just press the ENTER or RETURN key.
Change your password to a secure password at your earliest opportunity. If you dont know how to do this
yet, the upcoming chapter on passwd (yes, that is the correct spelling) will tell you how. That same chapter
gives advice on how to select a secure password.
Failure will be indicated by an error message. The exact error message varies by system, but will probably
be something similar to:
Login incorrect
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 44 of 319
3/5/13 11:00 AM
terminal type
On some older UNIX systems you may be asked to provide the terminal type you are using. Some modern
terminal emulator programs offer the choice of emulating various different terminals from the early UNIX
era. These different terminal types had different specialized capabilities.
Because the early traditional UNIX was created primarily on Digital Equipment Corporation (DEC)
computers (first the PDP, followed by the VAX), the default terminal device was the DEC VT100. Most
modern terminal emulator programs act like the VT100.
On older UNIX systems you may see the terminal type prompt:
Term:
In some cases, the prompt may give the default terminal setting in parenthesis.
Term = (VT100)
If the default terminal setting is correct, simply press the RETURN or ENTER key.
Otherwise, type in the correct terminal type, followed by the ENTER or RETURN key.
If you are uncertain, try the vt100 or UNKNOWN, followed by ENTER or RETURN.
Some common terminal types:
h19
tvi925
vt100
wyse50
After you are logged in, you can set the terminal type (capitalization matters).
Shell
csh
Command
or tcsh
sh
ksh, bash,
VMS
If you do not know your shell type, use the following command (followed by ENTER or RETURN):
$ echo $SHELL
You will need to enter the appropriate command each time you login.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 45 of 319
3/5/13 11:00 AM
Alternatively, you can add the appropriate command line to the initialization file in your home directory.
Shell Login file
or .login
csh
.cshrc
tcsh
.cshrc
ksh
.profile
zsh
.zshrc
bash
.bash_profile
VMS users need to modify the login.com file, adding the line $set term/device=vt100 .
logout
When you finish using the shell, type the exit or logout command. This will either display a new login
prompt or close the terminal emulator window.
When you finish using the shell, type the exit or logout command. This will either display a new login
prompt or close the terminal emulator window. if you are logged in remotely to a server, this will break your
connection. If you are logged in physically on a large UNIX system, this will prevent someone else from
abusing your account.
Some of the possible variations of this command include: bye, exit, lo, logout, and quit.
Typing CtrlL-D (holding down the CONTROL key and the D key at the same time) will also log you out
of most shells. The Ctrl-D tells the shell it has reached the end-of-file (EOF). Because the shell is a filter and
filters terminate when EOF is reached, the shell terminates and you log off the system or return to the parent
process.
While it might not be a big deal to skip this step on a single user computer that you never leave unattended,
forgetting to logout from a remote server is a serious security hole. If you leave your computer or terminal
unattended, someone else can sit down and gain access to all of your files, including the ability to read,
modify, or delete them. The imposter can send spam emails from your user ID. The imposter can even use
your computer or account to attempt to hack or damage or break into any system in the world from your user
ID. If this occurs from a school or business account, you will be responsible for any damage done.
Most modern systems accept either logout or exit.
On Mac OS X, typing logout produces the following result:
$ logout
[Process completed]
On Mac OS X, typing exit produces the following result (notice that the shell automatically runs logout
for you):
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 46 of 319
3/5/13 11:00 AM
$ exit
logout
[Process completed]
A successful logout will stop all running foreground or background processes. There is a way to keep
processes running, which is useful for things like starting up your Apache web server and MySQL data base,
but the method will be discussed later.
$ logout
There are suspended jobs.
If you see the message There are stopped jobs. it means that you have one or more suspended jobs. The
shell is letting you know in case you forgot about them. If you type logout again without running the jobs in
between, the system will go ahead and log you out and terminate all suspended jobs.
logout
exit
exit is a built-in shell command (for the shells that support it), while logout is a program. In the csh (C
Shell), logout is an internal built-in command. sh (the original Bourne shell) and ksh (the Korn Shell) do not
officially have the logout command, but many modern versions support it.
exit
exit can also be used to send a return value (often an error code) to the parent process. Simply add an
integer following exit. This is particularly useful in scripting.
$ exit n
exit
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 47 of 319
3/5/13 11:00 AM
passwd
chapter 8
summary
This chapter looks at passwd, a UNIX (and Linux) command.
passwd
This chapter also includes the list of the 100 worst (most commonly used) passwords.
As mentioned in the previous chapter, you should change your password from the original default or
assigned password to a secure password that nobody else knows. And please dont leave the new password
on a sticky note attached to your computer.
You will be prompoted to give your current (old) password (to make sure it is really you) and then
prompted to enter your new password twice. For security purposes, the password is typically replaced with
asterisks or some other character so that nobody can read your password over your shoulder. To make sure
that you have typed what you thought you typed you are asked to type the new password twice. The two
copies must match before your new password replaces your old password.
local password
The password set by passwd is your local password. On a single user system, this is probably your only
password.
On Mac OS X the use of the passwd may or may not be sufficient to change your password for the entire
system. This depends on which version of Mac OS X you are using. It is best to change your password using
the install disc. If you do not have a copy of the install disc, there are instructions on the internet on how to
manually change the password.
On a large system, there may be multiple passwords spread across multiple computers. The passwd
command will only change the password on the one server that you are currently logged into (normally
through SSH). You may need to use yppasswd or a web interface to change your password for the entire
system.
You can check for your account or username in /etc/passwd. If its not listed there, then dont use the
passwd. Check with your system administrator.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 48 of 319
3/5/13 11:00 AM
periodic changes
Whenever you first login into a new system, the first thing you should do is change your password. In
particular, immediately change the initial root password for a new system. Leaving the initial default
password is a huge security hole and hackers do try all of the standard default passwords to see if they can
find an easy way into a computer. Even with a user account, it is common for initial passwords to be
generated poorly and be easy for hackers to guess.
Additionally, you want to change your password on a regular basis. It only takes a few months to figure
out a password through brute force attacks. Some systems require that you change your password on a regular
basis. Once a month is a good time period. More often if you suspect that someone saw you typing or there is
any other possibility that your password might have been compromised.
You can set up your account to remind you to change your password on a regular basis. If you are the
system administrator, you can set up these reminders for everyone (and should do so). As system
administrator you can even require that users change their passwords on a regular basis (or they become
locked out and have to come to you to beg for re-entry). As system administrator you can also set up a system
that requires (or even suggests) secure passwords.
password
123456
12345678
1234
qwerty
12345
dragon
pussy
baseball
football
letmein
monkey
696969
abc123
mustang
michael
shadow
master
jennifer
111111
2000
jordan
superman
harley
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 49 of 319
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
3/5/13 11:00 AM
1234567
trustno1
iloveyou
sunshine
ashley
bailey
passw0rd
123123
654321
qazwsx
Football
seinfeld
princess
peanut
ginger
tigger
fuckme
hunter
fuckyou
ranger
buster
thomas
robert
soccer
fuck
batman
test
pass
killer
hockey
babygirl
george
charlie
andrew
michelle
love
jessica
asshole
6969
pepper
lovely
daniel
access
123456789
joshua
maggie
starwars
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 50 of 319
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
3/5/13 11:00 AM
silver
william
dallas
yankees
666666
hello
amanda
orange
biteme
freedom
computer
sexy
nicole
thunder
heather
hammer
summer
corvette
taylor
fucker
austin
1111
merlin
matthew
121212
golfer
cheese
martin
chelsea
Approximately 4.7% of all users have a password of password. 8.5% have one of the top two passwords.
9.8% (nearly one tenth) have one of the three top passwords. 14% have one of the top 10 passwords. 40%
have one of the top 100 passwords. 79% have one of the top 500 passwords. 91% have one of the top 1,000
passwords.
secure passwords
It is important to have secure passwords.
The more characters, the more secure. A minimum of six or eight characters is barely adequate.
A strong mixture of characters for a password includes at least one capital letter, at least one lower case
letter, at least on digit, and at least one punctuation character. You should avoid repeating any character more
than once in the same password. The special character (such as !@#$%^&*,;) should not be th efirst or last
character in the password.
Avoid using any word that occurs in your own or any other natural langauge. Hackers use a dictionary
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 51 of 319
3/5/13 11:00 AM
attack that tries words from the dictionary. Also avoid spelling words backwards, using common
misspellings, or using abbreviations. Avoid using dates that are important to you (someone can easily look up
your birthday or anniversary on the world wide web). Avoid using names of family, friends, or even pets.
secure technique
A technique that generates decent passwords is to use a key phrase and then use the first letter of each
word in the keyword. Sprinkle in digits and special characters (punctuation) and make some of the letters
upper case and some lower case.
Never use the same password for more than one purpose. People have the tendency to reuse the same
password over and over. If a hacker gets your password from one system, the hacker will see if it also works
on your bank account and other systems.
superuser
The super user (root) can use the passwd command to reset any other users password. There is no prompt
for the current (old) password.
$ passwd username
The super user (root) can also remove a password for a specific user with the -d option. The disable option
then allows the specified user to login without a password.
$ passwd -d username
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 52 of 319
3/5/13 11:00 AM
command structure
chapter 9
summary
This chapter looks at simple UNIX/Linux commands to get you started with using the shell.
You will learn the basic format or structure of a shell command.
You can run a UNIX (or Linux or Mac OS X) command (also called a tool) by typing its name and then
the ENTER or RETURN key.
single command
The most simple form of a UNIX command is just a single command by itself. Many UNIX/Linux
commands will do useful work with just the command by itself. The next examples show two commands
(who and date) by themselves.
The output generated by a single command by itself is called the default behavior of that command.
who
The who command will tell you all of the users who are currently logged into a computer. This is not
particularly informative on a personal computer where you are the only person using the computer, but it can
be useful on a server or a large computing system.
Type who followed by the ENTER or RETURN key.
$ who
admin
admin
$
The format is the login name of the user, followed by the users terminal port, followed by the month, day,
and time of login.
failed command
The shell will let you know when you have typed something it doesnt understand.
Type asdf and then the ENTER or RETURN key. You should see a message similar to the following:
$ asdf
-bash: asdf: command not found
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 53 of 319
3/5/13 11:00 AM
date
The following example uses the date command or tool.
$ date
Wed Nov 10 18:08:33 PST 2010
$
The format is: day of the week, month, day of the month, 24 hour time, time zone, year.
universal time
Adding the -u flag to the command date will cause it to report the time and date in UTC (Coordinated
Universal) time (also known as Zulu Time and formerly known as Greenwich Mean Time or GMT). The
seconds are slightly higher in the second example because of the passage of time.
$ date
Sat Aug 25 19:09:19 PDT 2012
$
$ date -u
Sun Aug 26 02:09:27 UTC 2012
$
arguments
Commands may also optionally have arguments. The most common arguments are the names of files.
Technically, the options just mentioned are also arguments, but in common practice options are separated
from other arguments in discussions. Also, technically, the operators mentiond below are also arguments, but
again it is useful to separate operators from other arguments in discussions.
The following shows the difference between the default behavior (no arguments) of who and a version with
arguments who am i.
The default behavior of who lists all users on the computer.
$ who
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 54 of 319
admin
admin
$
3/5/13 11:00 AM
The use of the arguments with who am i causes the command to only lists the one user who typed the
command.
The command is who and the arguments are am i.
$ who am i
admin
ttys000
$
Aug 25 17:30
one argument
In an upcoming chapter on the cat you will use the command cat with the file name file01.txt to
confirm that you correctly entered your sample file.
just observe this example
do not type this into your shell
$ cat file01.txt
This is a line of text in my first file.
This is another line.
To be, or not to be: that is the question:
1234567890
ABC
XYZ
abc
xyz
$
two arguments
In the upcoming chapter on the cat you will use the command cat with two file names (file01.txt and
numberfile.txt) to confirm that you correctly entered two of your sample files.
just observe this example
do not type this into your shell
$ cat file01.txt numberfile.txt
This is a line of text in my first file.
This is another line.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 55 of 319
3/5/13 11:00 AM
4
5
1234567890
ABC
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 56 of 319
6
7
8
3/5/13 11:00 AM
XYZ
abc
xyz
If you accidentally typed in the above command, hold down the CONTROL key and the D key at the same
time to return to your shell.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 57 of 319
3/5/13 11:00 AM
echo text
Use the echo command to send text to the terminal. Remember to press the ENTER or RETURN key after
each command. Note that this will be particularly useful in your future UNIX/Linux scripts to report
information back from your scripts.
$ echo hello world
hello world
$
Movies
Music
Pictures
Send registration
Sites
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 58 of 319
Library
$
3/5/13 11:00 AM
Public
The choice of names is based on the most popular names in the United States in the year before this
chapter was written. Bribe me if you want your name put into the example.
Movies
Music
Pictures
Public
Send registration
Sites
names
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 59 of 319
3/5/13 11:00 AM
38 names
The format is the number of lines (6), followed by the number of words (6), followed by the number of
characters (38), followed by the name of the file (names).
copy a file
Use the cp command to make a copy of a file.
$ cp names saved_names
$
Movies
Music
Pictures
Public
Send registration
Sites
names
saved_names
rename a file
Use the mv command to rename a file.
$ mv saved_named old_names
$
Notice that the shell is once again silent with success. You can use the ls command to confirm that the
rename really was made.
$ ls
Desktop
Documents
Downloads
Movies
Music
Pictures
Send registration
Sites
names
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 60 of 319
Library
$
3/5/13 11:00 AM
Public
old_names
delete a file
Use the rm (remove) command to delete a file.
$ rm old_names
$
You can use the ls command to confirm that the file was really deleted.
$ ls
Desktop
Documents
Downloads
Library
$
Movies
Music
Pictures
Send registration
Sites
names
current directory
Use the pwd command to determine the current directory. Your version should give the name of your home
directory, which normally matches the name of your user account. The example include the directory as part
of the prompt (your system may not include this) and the tilde ( ~ ) character indicates the home directory.
$ pwd
/Users/admin
admins-power-mac-g5:~ admin$
make a directory
Use the mkdir command to make a new directory (folder).
$ mkdir testdir
admins-power-mac-g5:~ admin$
change directory
Use the cd command to change to your new directory (folder). if your prompt includes the current
directory, then you will see your prompt change to show the new location.
$ cd testdir
admins-power-mac-g5:testdir admin$
Page 61 of 319
3/5/13 11:00 AM
$ pwd
/Users/admin/testdir
admins-power-mac-g5:testdir admin$
Now you are ready to dive in and start becoming proficient at using the UNIX or Linux shell.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 62 of 319
3/5/13 11:00 AM
man
chapter 11
summary
This chapter looks at man, a UNIX (and Linux) command.
man
man
This chapter show you how to use the man command to get help. Because of huge variation in the various
flavors of UNIX and Linux, the man installed on your computer or server is the best source of detailed
information. If you have trouble with any of the lessons in this book or in general use of your UNIX or Linux
system, always refer to the local man for help.
UNIX was the first operating system distributed with online documentation. This included man (manual
pages for each command, library component, system call, header file, etc.) and doc (longer documents
detailing major subsystems, such as the C programming language and troff.
DATE(1)
NAME
date -- display or set date and time
SYNOPSIS
date [-ju] [-r seconds] [-v [+|-]val[ymwdHMS]] ... [+output_fmt]
date [-jnu] [[[mm]dd]HH]MM[[cc]yy][.ss]
date [-jnu] -f input_fmt new_date [+output_fmt]
date [-d dst] [-t minutes_west]
DESCRIPTION
When invoked without arguments, the date utility displays the current
date and time. Otherwise, depending on the options specified, date will
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 63 of 319
3/5/13 11:00 AM
Typing the RETURN or ENTER key will bring up the next line of the manual page.
Typing the SPACE-BAR key will bring up the next page of text.
Typing the UP-ARROW or DOWN-ARROW key will move up or down one line.
Typing q will end viewing the manual page and return to the BASH prompt (the entire manual page will
disappear from view).
The man command or tool will be a very useful reference.
A man page is typically organized:
NAME:
SYNOPSIS:
The syntax for using the command, along with the flags (options) the command takes.
DESCRIPTION:
ENVIRONMENT:
EXIT STATUS:
FILES:
SEE ALSO:
related commands.
STANDARDS:
man sections
The first seven distributions of UNIX (called V1 UNIX through V7 UNIX and collectively called
traditional UNIX) included a two volume printed manual, which was divided into eight sections.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 64 of 319
3/5/13 11:00 AM
Some manual pages are located in sections. There are generally eight sections:
1.
2.
3.
4.
5.
6.
7.
8.
General commands
System [kernel] calls
C library functions
Special files (such as devices) and drivers
File formats, conventions, and miscellaneous information
games and screensavers
Macro packages
System administration commands and daemons
Note that on some systems, the system administration commands are in section 1m. This section is also
sometimes called the Maintenance commands.
Note that on some systems, section 7 is Miscellaneous.
You can look at a particular section by adding the section number to the command line.
$ man SECTION-NUMBER commandname
You can use the whatis command to find the sections and then look at the particular section of your
choice.
$ whatis crontab
$ whatis crontab
crontab(1)
crontab(5)
$ man 5 crontab
-f option
The -f option is used to show all man page titles for entries that begin with a particular word. man -f file
will show all the manual pages that have the word file in the title.
$ man file
-k option
The -k option runs a search on all manual pages for any manual page with a particular word anywhere on
the page. The man -k file will show all the manual pages that have the word file anywhere in the manual
page. The -k option can take a while to run.
$ man file
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 65 of 319
3/5/13 11:00 AM
cat
chapter 12
summary
This chapter looks at cat, a UNIX (and Linux) command.
The cat (as in concatenate) utility can be used to concatenate several files into a single file.
cat
is most often used to obtain the contents of a file for input into a Linux or UNIX shell script.
cat
cat
was part of the original 1969 version of UNICS (the original name for UNIX).
The choice of names is based on the most popular names in the United States in the year before this
subchapter was written. Bribe me if you want your name put into the example.
Movies
Music
Send registration
Sites
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 66 of 319
Downloads
Library
$
3/5/13 11:00 AM
Pictures
Public
names
creating files
One simple use of cat is to create simple files.
Type cat > file01.txt, followed by ENTER or RETURN.
$ cat > file01.txt
The cursor will be at the beginning of a line that has no prompt. You are no longer in the shell, but instead
in the cat utility. There is no cat prompt.
Type the following lines (by convention, all of the input should be in bold, but to make it easier on the eye,
it is in italics here):
This is a line of text in my first file.
This is another line.
To be, or not to be: that is the question:
1234567890
ABC
XYZ
abc
xyz
Once you have typed in these lines, press RETURN to make sure you are at the beginning of a new line.
Press Ctrl-D (hold down the CONTROL key and the D key at the same time). This indicates end-of-file
(EOF), which informs cat that you have no more input. This will return you to the shell.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 67 of 319
3/5/13 11:00 AM
Note that unlike some operating systems, the .txt file extension is not required by UNIX or Linux. It is
optional, but the file extensions are often used to make it easier for a human to distinguish file types.
Now repeat the process with the following file (by convention, all of the input should be in bold, but to
make it easier on the eye, it is in italics here):
There is a lot of typing in this example, but it is important for the upcoming exercises. Type the following
lines (by convention, all of the input should be in bold, but to make it easier on the eye, it is in italics here):
Because of the length of this file, you may want to download a copy from the internet. There is a copy at
http://www.osdata.com/programming/shell/file02.txt if you know how to download a copy and place it in
your home directory, save yourself some typing time.
$ cat > file02.txt
This is a line of text in my second file.
This is another line.
To be, or not to be: that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them? To die: to sleep;
No more; and by a sleep to say we end
The heart-ache and the thousand natural shocks
That flesh is heir to, 'tis a consummation
Devoutly to be wish'd. To die, to sleep;
To sleep: perchance to dream: ay, there's the rub;
For in that sleep of death what dreams may come
When we have shuffled off this mortal coil,
Must give us pause: there's the respect
That makes calamity of so long life;
For who would bear the whips and scorns of time,
The oppressor's wrong, the proud man's contumely,
The pangs of despised love, the law's delay,
The insolence of office and the spurns
That patient merit of the unworthy takes,
When he himself might his quietus make
With a bare bodkin? who would fardels bear,
To grunt and sweat under a weary life,
But that the dread of something after death,
The undiscover'd country from whose bourn
No traveller returns, puzzles the will
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all;
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought,
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 68 of 319
3/5/13 11:00 AM
Now repeat the process with the following file (by convention, all of the input should be in bold, but to
make it easier on the eye, it is in italics here note the cheat method below):
$ cat > numberfile.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Once again, use the RETURN key to enter a new line and then use Ctrl-D to exit cat.
If you want to cheat on making this file, you can use the following command on Mac OS X or BSD
systems:
$ jot 20 1 > numberfile.txt
$
You will use these files in many of the exercises in this book.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 69 of 319
3/5/13 11:00 AM
PC-DOS equivalent
cat is the UNIX equivalent of the MS-DOS or PC-DOS command TYPE. You can add the PC-DOS
equivalent to your shell session with the alias command. To make the change permanent, add the following
line to the .bashrc file in your home directory. Note that if you add this PC-DOS/MS-DOS equivalent, only
add the all upper case version, because the lower case type is an important UNIX command that you will
also need.
$ alias TYPE="cat"
Page 70 of 319
3/5/13 11:00 AM
This should list your new file that combines combines two of the files you created. The beginning of the
listing will scroll off the top of your screen. Dont worry about it. Well see how to view long files in the
chapter about less.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 71 of 319
4
5
6
7
8
3/5/13 11:00 AM
1234567890
ABC
XYZ
abc
xyz
empty a file
You can use cat to empty a file by sending /dev/null to the file to be emptied. The null device is bit
nothingness.
Start by making a copy of one of the files you just created so that you dont wipe out your hard work.
$ cp file01.txt emptyfile
$
Use cat to verify that the new file really does exist and has a complete copy of the original file.
$ cat emptyfile.txt
This is a line of text in my first file.
This is another line.
To be, or not to be: that is the question:
1234567890
ABC
XYZ
abc
xyz
$
Now type cat /dev/null > emptyfile.txt. This will leave the file in existence, but empty it of all
characters.
$ cat /dev/null > emptyfile.txt
$
Confirm this by using both cat and wc (word count). The cat will simply return to the prompt because
there is nothing to print out. The wc will show zero lines, zero words, and zero characters.
$ cat file01.txt > emptyfile.txt
$ wc names
0
0
0 emptyfile.txt
$
replacing files
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 72 of 319
3/5/13 11:00 AM
The previous example brings up the point that if you use cat to output to an existing file, the previous file
will be completely replaced by the new one. There is no warning at all.
appending files
You can append to the end of an existing file by using two greater than signs (no spaces in between) >>.
Start by making a copy of an existing file and then confirming the copy is correct.
$ cp file01.txt file03.txt
$ cat file03.txt
This is a line of text in my first file.
This is another line.
To be, or not to be: that is the question:
1234567890
ABC
XYZ
abc
xyz
$
Page 73 of 319
3/5/13 11:00 AM
8
9
10
11
12
13
14
15
16
17
18
19
20
$
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 74 of 319
3/5/13 11:00 AM
command separator
chapter 13
This chapter looks at the command separator in UNIX or Linux.
The semicolon ( ; ) is used as a command separator.
You can run more than one command on a single line by using the command separator, plaing the
semicolon between each command.
$ date; who am i
Mon Aug 27 19:15:41 PDT 2012
admin
ttys000 Aug 27 17:50
$
It does not matter if you have a space before the semicolon or not. Use whichever method is more readable
and natural for you.
$ date ; who am i
Mon Aug 27 19:15:41 PDT 2012
admin
ttys000 Aug 27 17:50
$
Each command is processed in order, as if you had typed each individually, with the exception that the line
with the prompt is only displayed once, at the end of the series of commands.
If you forget the semicolon, you will get an error message. The following two examples are from different
systems.
$ date who am i
date: illegal time format
$
$ date who am i
date: bad conversion
$
The semicolon is a common terminator or separator in many common programming languages, including
Ada, C, Java, Pascal, Perl, PHP, and PL/I.
Many programmers automatically place the semicolon at the end of any shell command. The shell is fine
with this.
$ date;
Mon Aug 27 19:15:41 PDT 2012
$
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 75 of 319
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Page 76 of 319
3/5/13 11:00 AM
less, more, pg
chapter 14
summary
This subchapter looks at less, more, and pg, a related family of UNIX (and Linux) commands.
less, more,
pg
and pg are utilities for reading a very large text file in small sections at a time.
more
and more are very similar and have almost the same functionality and are used in almost the exact same
manner, except for whether you type pg or more.
pg
less
is a more modern version that has the capaibilites of more along with additional new capabilities.
Mac OS X has all three versions installed. It is common to find both more and less on Linux systems. The
older versions are typically included so that old scripts written before the invention of less will still work.
The name less is a pun, from the expression less is more.
Try using less with your test file file01.txt.
You are going to try less first.
$ less file01.txt
One of the three will work. You can try the others to see if they are available on your system, but for the
exercise, use the first one that works.
$ less file01.txt
This is a line of text in my first file.
This is another line.
To be, or not to be: that is the question:
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 77 of 319
3/5/13 11:00 AM
1234567890
ABC
XYZ
abc
xyz
$
Now we are going to see the real power of less with a long file.
$ less file02.txt
This is a line of text in my second file.
This is another line.
To be, or not to be: that is the question:
Whether 'tis nobler in the mind to suffer
The slings and arrows of outrageous fortune,
Or to take arms against a sea of troubles,
And by opposing end them? To die: to sleep;
No more; and by a sleep to say we end
The heart-ache and the thousand natural shocks
That flesh is heir to, 'tis a consummation
Devoutly to be wish'd. To die, to sleep;
To sleep: perchance to dream: ay, there's the rub;
For in that sleep of death what dreams may come
When we have shuffled off this mortal coil,
Must give us pause: there's the respect
That makes calamity of so long life;
For who would bear the whips and scorns of time,
The oppressor's wrong, the proud man's contumely,
The pangs of despised love, the law's delay,
The insolence of office and the spurns
That patient merit of the unworthy takes,
When he himself might his quietus make
File02.txt
Notice that you are not yet back to the shell prompt. You are still in the less
command. You are only one page into the file. less allows you to view long files one page
at a time, instead of scrolling them off the top of your screen.
Type the SPACE key to see another page of text.
That patient merit of the unworthy takes,
When he himself might his quietus make
With a bare bodkin? who would fardels bear,
To grunt and sweat under a weary life,
But that the dread of something after death,
The undiscover'd country from whose bourn
No traveller returns, puzzles the will
And makes us rather bear those ills we have
Than fly to others that we know not of?
Thus conscience does make cowards of us all;
And thus the native hue of resolution
Is sicklied o'er with the pale cast of thought,
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 78 of 319
3/5/13 11:00 AM
Notice that you are not yet back to the shell prompt. Even though the entire file contents have been listed,
you are still in the less command.
Typing lower case q will quit the less (or more or pg) program.
less (and the other two utility commands) displays one page at a time. This is in contrast with cat, which
displays the entire file at once.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 79 of 319
3/5/13 11:00 AM
graphics example
In a graphic user interface, you can see the file system directory structure in some kind of picture version.
This varies by system.
The following example is from Mac OS X. If you use Mac OS X, the UNIX directories are kept hidden in
Finder. You can see them by using Finders Go menu, Go To Folder, and type private.
Do not mess with your system files until you know what you are doing. You can cause your computer to
stop working.
Some of the typical UNIX/Linux directories are etc, tmp, var, bin, sbin, dev, boot, or home.
some basics
Both UNIX and Linux organize the entire file system into a single collection (called the directory tree).
This is in sharp contrast to Windows dividing the file system into multiple parts, each based on a particular
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 80 of 319
3/5/13 11:00 AM
drive or device.
File names are case sensitive. The file names File and file are different files. This is in sharp contrast
with Windows and Macintosh (where they are alternate names for the same file). Note that this is a Mac OS
X variation from the standard UNIX practice.
A file name that starts with a period is a hidden file. In Mac OS X, you can toggle between showing and
hiding hidden files in Finder by typing Command-Shift-Period.
Neither UNIX nor Linux enforce or recognize file extensions (such as .txt). In some operating systems
(such as Windows and traditional Macintosh), the file extensions are recognized by the operating system and
are used for such purposes as deciding which program is used to open the file. You can add file extensions
UNIX or Linux file names (and this is commonly done to help humans organize their files), but the file
extension is ignored by the operating system and has no special meaning.
Most modern Linux and UNIX operating systems support long file names with a wide variety of
characters, including the space character. Shells are set up for old school UNIX, which had a limited number
of characters in file names and a very limited choice of characters in file names. it is best to use these old
school limits for files you manipulate through the UNIX or Linux shell. Mac OS X allows you to put file
names inside quotation marks (to allow such things as spaces in file names). You can also access files
through their inode numbers (which will let the shell work on any file name). Still, it is wise to use only
letters, numbers, period, hyphen, and underscore in UNIX or Linux file names 9and particularly to avoid the
space character).
directory tree
A directory in UNIX or Linux is the same as a folder in Macintosh or Windows.
Directories may contain any combination of files and subordinate directories.
This structure is called a tree. It branches out from a root.
Unix and Linux are organized into a single file system tree, under a master directory called root and
designated by the forward leaning slash ( / ). This is in sharp contrast with Windows, where there is a
seperate file system tree for each drive letter.
In UNIX, everything is is a file. Even a directory is just a special file that stores information about other
files.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 81 of 319
3/5/13 11:00 AM
Page 82 of 319
3/5/13 11:00 AM
absolute paths
Every directory or file can be defined by a complete absolute path. The complete absolute path gives every
level of directory, starting from the root. An absolute path name is sometimes called the full path name.
An example might be the /usr/java/bin. This would be a directory containing Java binaries. In this
example, under the / root directory there is a directory called usr and inside that directory there is a directory
called java and inside that directory there is a directory called bin and inside that directory there are
programs for running Java.
Absolute paths normally start at the root of the file system.
relative paths
Relative paths describe where to find a file or directory from the current working directory.
A single period (or dot) character ( ./ ) indicates that you are describing the path to a directory or file from
the current working directory.
If your current working directory is www and that directory is under /usr, then the file index.html inside
the current working directory can be described by the full or absolute path of /usr/www/index.html or a
relative path name of ./index.html.
The single period is called dot.
Two periods ( ../ called dot dot) take you up one directory to the parent directory.
You can use a series of two dots ( ../../ ) to go up more than one directory level.
./
../
Two dots are used to indicate the parent of the current working directory.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 83 of 319
3/5/13 11:00 AM
. A single dot in front of a file name (such as .Trash) is used to make a hidden file. Hidden files are only
listed when specifically requested.
hidden files
A file name that starts with a period is a hidden file. In Mac OS X, you can toggle between showing and
hiding hidden files in Finder by typing Command-Shift-Period. In MS-DOS, a hidden file cant be written to.
In UNIX and Linux a hidden file can be read and written.
Some important hidden files are the files used to configure the working environment, including .cshrc,
and .profile.
.login,
moving around
This will all make a bit more sense in the next chapter as you learn how to actually move around your file
system.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 84 of 319
3/5/13 11:00 AM
pwd
chapter 16
summary
This chapter looks at pwd, a UNIX (and Linux) command.
is used to Print the Working Directory. It provides the full path for the current working directory. and
is normally run without any options.
pwd
pwd
is a builtin command in bash. There is also an external utility with the same name and functionality.
working directory
The working directory is whatever directory you happen to be working in. The working directory is always
the same as the home directory when you start a shell session, but you can change your working directory at
any time (and typically do change it). Commands normally are applied to the current working directory.
The working directory may also be called the current directory, current working directory, or present
working directory.
using pwd
Type pwd from the command line, followed by ENTER or RETURN, and you will see the current working
directory.
$ pwd
/Users/admin
$
Theres not much else to tell you about this command, but this is an important one because you will
continually have the need to know where you are.
moving around
We will go into more detail about these commands later, but for now you need to know how to move
around in your file system.
The ls command is used to list the contents of the current directory.
Go ahead and type ls followed by ENTER or RETURN and you will see a list of the files and directories
in your current working directory (which should still also be your home directory).
The cd command is used to change directories.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 85 of 319
3/5/13 11:00 AM
Go ahead and type cd directory-name followed by ENTER or RETURN and you will move to the new
directory. You can confirm this by then typing pwd followed by ENTER or RETURN. You will see that you
have successfully changed working directories.
$ pwd
/Users/admin
$ ls
Desktop
Movies
Documents
Music
Downloads
Pictures
Library
Public
$ cd Desktop
$ pwd
/Users/admin/Desktop
$
Send Registration
Sites
As you move around the directory tree, it is common to forget exactly where you are, especially if you do
some other tasks (such as file editing). pwd provides an easy way to determine where you are and insure that
your next actions are happening in the correct directory.
Use cd command all by itself to return to your home directory.
$ cd Desktop
$ pwd
/Users/admin
$
options
is almost always used without options and never uses any arguments (such as file names). Anything
other tahn legal options typed after pwd are ignored. Some shells ignore anything other than the legal options
typed after pwd without reporting any errors, while most shells report errors for illegal options. All shells
seem to ignore all arguments without reporting any errors.
pwd
The -P option displays the physical current working directory, with all symbolic links resolved.
$ pwd -P
/Users/admin
$
You can use the help command to get information about pwd.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 86 of 319
3/5/13 11:00 AM
$ help pwd
Some early Linux shells allow the --help command to get information about pwd.
$ pwd --help
Some early Linux shells allow the --version option gives the version number for your copy of pwd.
$ pwd --version
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 87 of 319
3/5/13 11:00 AM
command history
chapter 17
summary
This chapter looks at command history in a UNIX (and Linux) BASH shell.
Command history is used to recall recent commands and repeat them with modifications.
You will find that you are often repeating a few common commands over and over with variations in the
options and arguments (such as file names). Having the ability to recall a previous example and make a few
changes will greatly save on typing.
arrow keys
Pushing the Up Arrow key will bring back previously typed commands one at a time (from most recently
typed to the first typed).
Pushing the Down Arrow key will move from the oldest to the newest commands one at a time.
The commands brought back by the Up Arrow and Down Arrow keys will appear after the current prompt.
You can press the ENTER or RETURN key to immediately run any selected command.
After using the Up Arrow or Down Arrow keys, your cursor is at the end of the line. You can use the
DELETE key to remove old arguments and then start typing in new ones.
Note that holding down the CONTROL key and pressing the p key at the same time will take you to the
previous command just like the Up Arrow key. This is written ^p.
Holding down the CONTROL key and pressing the n key at the same time will take you to the next
command just like the Down Arrow key. This is written ^n.
Pressing the META key (or on some systems pressing the ESCAPE key), then releasing it, then typing the
less than < key will take you to the beginning of the command history. Pressing the META key (or on many
modern systems pressing the ESCAPE key or ESC key), then releasing it, then typing the greater than > key
will also move to the end (most recent) command history. These are written M-< and M->.
editing a line
As mentioned above, when you use command history, the cursor is at the end of the recalled command.
Either the Left Arrow or ^b will go one character backward (towards the beginning of line).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 88 of 319
3/5/13 11:00 AM
Either the Right Arrow or ^f will go one character forward (towards the end of line).
Typing inside a line will place characters in front of the cursor. The character inside the cursor remains
unchanged.
Using the DELETE key will delete the character in front of the cursor. The character inside the cursor
remains unchanged.
^k will delete everything from the cursor to the end of the line.
^d will delete the character inside (under) the cursor.
M-b will move you one word back (towards beginning of line). In this case, a word is a collection of
characters, usually separated by a space character.
M-f will move you one word forward (towards end of line).
^e will move to the end of the line and ^a will move to the beginning of the line.
Once you have edited your command, use the RETURN or ENTER key to run the new command. You can
use the ENTER or RETURN key from anywhere in the command line. You do not have to be at the end of
the command line.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 89 of 319
3/5/13 11:00 AM
built-in commands
chapter 18
summary
This chapter looks at built-in commands in a UNIX (and Linux) BASH shell.
tools
Most of the commands in the UNIX or Linux shell are actually programs. If you look at the usr/bin
directory, you will see the actual programs. Most of these programs were written in the C programming
language.
There is a common core of tools/commands that will be available on almost every UNIX or Linux
machine, but exactly how many and which commands/tools are available varies widely.
The good news is that if a command or tool is missing from your system, you can go out and get the source
code and recompile it for your local computer.
built-in
Many of the shells have special built-in commands. These are not separate programs, but are part of the
code for the shell itself.
One example would be the shell command cd that you just saw in the previous quick tour chapter.
There are some built-in commands are only available in selected shells and these can make your scripts
shell-dependent.
Some examples of built-in commands include the history command in the C shell, and the export
command in the Bourne shell. The cd command is built-in in both bash and csh.
echo
is an example of a command that is built into both bash and csh, but also exists externally as a utility.
As an example, using the command echo will run the version of the command that is built into bash, while
specifying /bin/echo or ./echo will ignore the built-in comamnd and instead run the designated utility.
Overriding can be used to run alternative versions of commands or to extend the built-in command to add
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 90 of 319
3/5/13 11:00 AM
additional features.
You can use the which command to locate a program in your path.
$ which echo
/bin/echo
$
You can use the whereis command to locate a program in your path.
$ whereis echo
/bin/echo
$
In csh and tcsh you can use the where command to locate a program in your path.
% where echo
/bin/echo
%
problems
You can use the type command to determine if a particular command is a built-in command or an external
utility. If the command is an external utility, you will also be told the path to the external command.
If something bad happens to your computer, if the shell is still loaded in memory and running, any of the
built-in commands will still work correctly, even if the entire file system (including all hard drives)
disappears or becomes unavailable for any reason.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 91 of 319
3/5/13 11:00 AM
Command External
!
No
%
No
.
No
:
No
{
No
}
No
alias
No**
alloc
No
bg
No**
bind
No
bindkey
No
break
No
breaksw
No
builtin
No
builtins
No
case
No
cd
No**
chdir
No
command
No**
complete
No
continue
No
default
No
dirs
No
do
No
done
No
echo
Yes
echotc
No
elif
No
else
No
end
No
endif
No
endsw
No
esac
No
eval
No
exec
No
exit
No
export
No
false
Yes
csh
No
Yes
No
Yes
No
No
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
No
bash
Yes
No
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
No
No
Yes
Yes
Yes
No
Yes
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 92 of 319
3/5/13 11:00 AM
fc
No**
No
Yes
fg
No**
No
No
No
No
No**
No
No
No
No
No
No
No
No
No**
Yes
No
No
No
Yes
No
No
Yes
Yes
No
No
No
Yes
No
Yes
No**
No
No
No
No
No
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
No
Yes
No
No
Yes
No
No
No
Yes
Yes
Yes
No
No
Yes
No
No
No
No
No
No
No
No
No
No
No
Yes
Yes
Yes
No
No
Yes
No
Yes
filetest
fi
for
foreach
getopts
glob
goto
hash
hashstat
history
hup
if
jobid
jobs
kill
limit
local
log
login
logout
ls-F
nice
nohup
notify
onintr
popd
printenv
pushd
pwd
read
readonly
rehash
repeat
return
sched
set
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 93 of 319
3/5/13 11:00 AM
setenv
settc
No
No
No
setvar
No
shift
No
source
No
stop
No
suspend
No
switch
No
telltc
No
test
Yes
then
No
time
Yes
times
No
trap
No
true
Yes
type
No
ulimit
No
umask
No**
unalias
No**
uncomplete No
unhash
No
unlimit
No
unset
No
unsetenv
No
until
No
wait
No**
where
No
which
Yes
while
No
setty
Yes
Yes
No
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
No
Yes
No
No
No
No
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
No
No
No
No
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
No
Yes
Yes
No
No
Yes
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 94 of 319
3/5/13 11:00 AM
ls
chapter 19
summary
This chapter looks at ls, a UNIX (and Linux) command.
ls
The ls command was described in the first UNIX book, UNIX Programmers Manual, by Ken Thompson
and Dennis Ritchie, published November 3, 1971.
Movies
Music
Pictures
Public
Send registration
Sites
PC-DOS equivalent
is the UNIX equivalent of the MS-DOS or PC-DOS command DIR. You can add the PC-DOS
equivalent to your shell session with the alias command. To make the change permanent, add the following
line to the .bashrc file in your home directory. Note that if you add this PC-DOS/MS-DOS equivalent, only
add the all upper case version, because the lower case type is an important UNIX command that you will
also need.
ls -la
list all
Type ls with the -A option to get a list of all entries other than . (single dot) and .. (double dot).
$ ls -A
Page 95 of 319
$ ls -F
Desktop/
Documents/
Downloads/
Library/
Movies/
$
3/5/13 11:00 AM
Music/
Pictures/
Public/
Send registration@
Sites/
file01.txt
file02.txt
names
numberfile.txt
testdir/
A slash / will be added after every pathname that is a directory. An asterisk * will be added after every file
that is executable (including scripts). An at sign @ will be displayed after each symbolic link. An equals sign
= will be displayed after each socket. A percent sign % will be displayed after each whiteout. A vertical bar |
will be displayed after each item than is a FIFO.
ls -F
hidden files
The -a option will give a list of all files, including hidden files.
$ ls -a
gotchas
Do not use the output of ls in a BASH for loop.
$ for i in $(ls *.mp3); do # Wrong!
$
command $i # Wrong!
$ done # Wrong!
$ for i in $(ls *.mp3) # Wrong!
$ for i in `ls *.mp3` # Wrong!
If any file name has spaces in it, then it will be word split. So, the MP3 for Alex Clairs Too Close
(number four song on his The Lateness of the Hour album) might be 04 Too Close. In that case, your
command would run on the files 04, Too, and Close, rather than 04 Too Close. Additional errors
likely to follow. Listen to the song Too Close for free at
http://www.thissideofsanity.com/musicbox/musicbox.php?mastersong=485 .
Double quote wont work either because that will cause the entire output of the ls command to be treated
as a single item. Your loop will run once on all of the file names conactenated together.
$ for i in "$(ls *.mp3)"; # Wrong!
The solution is to run your loop without even using ls, relying on BASHs filename expansion. Dont
forget to check for the possibility that there are no qualifying files in the current directory.
$ for i in *.mp3; do # Wrong!
$
[[ -f "$i" ]] || continue
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 96 of 319
3/5/13 11:00 AM
$
command "$i"
$ done
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 97 of 319
3/5/13 11:00 AM
cd
chapter 20
summary
This chapter looks at cd, a UNIX (and Linux) command.
cd
cd is a builtin command in bash and csh. There is also an external utility with the same name and
functionality.
is used to change the directory you are working in. You type the command cd followed by a space and
then the directory (folder) that you want to change to.
cd
The chdir (change directory) command, the predecessor of cd, was described in the first UNIX book,
UNIX Programmers Manual, by Ken Thompson and Dennis Ritchie, published November 3, 1971.
Music/
Pictures/
Public/
Send registration@
Sites/
file01.txt
file02.txt
names
numberfile.txt
testdir/
Your listing will be different than this one. Look for any name that has a slash ( / ) after it and use it as the
directory_name in the following example. If you created the testdir in the quick tour chapter, then use the
second example listed here.
$ cd directory_name
admins-power-mac-g5:directory_name admin$
If you created the testdir in the quick tour chapter, then use the following example:
$ cd testdir
admins-power-mac-g5:testdir admin$
Use the pwd command to confirm that you are now in your new directory.
$ pwd
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 98 of 319
3/5/13 11:00 AM
/Users/admin/testdir
admins-power-mac-g5:testdir admin$
Use the cd command without any additional arguments to return to your home directory from anywhere.
$ cd
admins-power-mac-g5:~ admin$
Use the pwd command to confirm that you are now back in your home directory.
$ pwd
/Users/admin
admins-power-mac-g5:~ admin$
If the HOME variable is set (which is normal), then you can use it to return to your home directory.
$ cd $HOME
admins-power-mac-g5:~ admin$
go one level up
Type cd ../ to go up one directory level. The following exampel starts in the testdir directory and goes up
one level to the home directory.
admins-power-mac-g5:testdir admin$ cd ../
changing to the home directory, one level up from the testdir directory
admins-power-mac-g5:~ admin$
You can type a series of ../ to go up multiple directories. cd ../../ will go up two levels. cd ../../../
will go up three levels. And so on.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
Page 99 of 319
3/5/13 11:00 AM
PC-DOS equivalent
cd .. is the UNIX equivalent of the MS-DOS or PC-DOS command CD... You can add the PC-DOS
equivalent to your shell session with the alias command. To make the change permanent, add the following
line to the .bashrc file in your home directory.
$ alias CD..="cd .."
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
cp
chapter 21
summary
This chapter looks at cp, a UNIX (and Linux) command.
cp
copy a file
Use the cp command to make a copy of a file. This example assumes you created the names file in the
quick tour chapter.
$ cp names saved_names
$
Movies
Music
Pictures
Public
Send registration
Sites
names
saved_names
In the above example, if the file save_names already existed, it will be replaced with a copy of names.
You can type cp -i to get confirmation before replacing a file. Enter n or just the RETURN key to stop the
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
copy and prevent an overwrite. Enter y to go ahead with the copy and replace the old file.
$ cp -i names saved_names
overwrite saved? (y/n [n]) n
not overwritten
$
force overwrites
Use the -f option to force the copy to overwrite any file with a matching name. This is the same as the
default action of the cp command.
$ cp names saved_names
PC-DOS equivalent
is the UNIX equivalent of the MS-DOS or PC-DOS command COPY. You can add the PC-DOS
equivalent to your shell session with the alias command. To make the change permanent, add the following
line to the .bashrc file in your home directory. Note that this version adds interactive questioning before
replacing a file, in a manner similar to PC-DOS. Note also that if you add this PC-DOS/MS-DOS equivalent,
only add the all upper case version, because the lower case type is an important UNIX command that you
will also need.
cp -i
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
mv
chapter 22
summary
This chapter looks at mv, a UNIX (and Linux) command.
mv
rename a file
Use the mv command to rename a file. This example assumes you created the names and saved-name files
in the quick tour chapter.
$ mv saved_named old_names
$
Notice that the shell is once again silent with success. You can use the ls command to confirm that the
rename really was made.
$ ls
Desktop
Documents
Downloads
Library
$
Movies
Music
Pictures
Public
Send registration
Sites
names
old_names
PC-DOS equivalent
is the UNIX equivalent of the MS-DOS or PC-DOS command REN. You can add the PC-DOS
equivalent to your shell session with the alias command. To make the change permanent, add the following
line to the .bashrc file in your home directory.
mv
$ alias REN="mv"
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
rm
chapter 23
summary
This chapter looks at rm, a UNIX (and Linux) command.
rm
rm
rm
was part of the original 1969 version of UNICS (the original name for UNIX).
delete a file
Use the rm (remove) command to delete a file. This example assumes you created the names saved_names
and old_names files in the quick tour chapter.
$ rm old_names
$
You can use the ls command to confirm that the file was really deleted.
$ ls
Desktop
Documents
Downloads
Library
$
Movies
Music
Pictures
Send registration
Sites
names
safety
Before using rm, especially rm with globbing (such as using wild cards), try the same glob with ls first to
make sure you will be removing the files you intend to remove.
For example, before running rm foo*.txt, run ls foo*.txt. Read the list and be sure that you are going
to delete the files you really intend to delete.
Some UNIX and Linux users modify the rm command by aliasing it with the interactive form, rm -i. This
changes the behavior of rm to always ask before deleting files.
$ alias rm="rm -i"
Unfortunately, this alias can cause some scripts to fail (possibly including system scripts that were
provided with your distribution).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
An alternative is to alias to a different, non-conflicting name. In this case, del might be appropriate.
$ alias del="rm -i"
PC-DOS equivalent
is the UNIX equivalent of the MS-DOS or PC-DOS command DEL. You can add the PC-DOS
equivalent to your shell session with the alias command. To make the change permanent, add the following
line to the .bashrc file in your home directory. Note that this version adds interactive questioning before
deleting a file, in a manner similar to PC-DOS.
rm -i
recursive
Type rm followed by the option -r followed by directory name to delete recursively. This means that the
directory and all of its subdirectories will be removed, even for non-empty direcories. This is a fast way to
remove directories and files in a single command.
$ rm -r directory-name
$
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
shred
chapter 24
summary
This chapter looks at shred, a Linux command.
shred
Files are normally deleted by removing their file table entries. The data remains out on the hard drive
(which is how file recovery programs can work).
Writing over the file actually eliminates the data so that nobody can ever read it.
This can take a while for large files or for many files.
Files deleted with shred can not be recovered (unless you previously stored them in a backup somewhere
else).
Be especially careful when using shred with any wildcard characters.
You should probably never run shred from root or superuser.
Mac OS X
Mac OS X offers secure empty trash from the graphic interface
(Finder menu, Secure Empty Trash menu item, which is directly under
regular Empty Trash).
Mac OS X also has the srm command, which is the secure equivalent
of regular rm.
$ srm -rfv -s filename
The -z option will overwrite with zeros. The -s option will overwrite
in a single pass (one pass) of random data. The -m option will perform a
Department of Defense seven-pass deletion. No options will result in a
35-pass file erase, which will take a long time.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
mkdir
chapter 25
summary
This chapter looks at mkdir, a UNIX (and Linux) command.
mkdir
make a directory
Use the mkdir command to make a new directory (folder).
$ mkdir testdir
admins-power-mac-g5:~ admin$
multiple directories
You can name multiple directories with the mkdir command. Simply list each of the new diretcories after
the mkdir with a space character between each directory name.
$ mkdir directory1 directory2 directory3
admins-power-mac-g5:~ admin$
This option is often used in shell scripts to lock down temporary directories.
use a path
You can give an entire path name to a specific directory, using either a relative or absolute path name to
create the directory anywhere int he file system.
$ mkdir directory1/directory2/directory3
admins-power-mac-g5:~ admin$
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
You can use the -p option to create directories along the path. You can therefore, create a series of parent
and child directories all at once.
If you use the -p option and the directory already exists, the mkdir command will continue on through
your path and create new directories as needed down to the last one you list.
$ mkdir -p directory1/directory2/directory3
admins-power-mac-g5:~ admin$
Intermediate directories are created with the permission bits of rwxrwxrwx (0777) as modified by the
current umask, plus the write and search permission for the owner.
The -v option is considered nonstandard and should not be used in shell scripts.
spaces in names
To create a directory with space in the directory name, you need to use quoting for the entire name so that
the shell treats it as a single name rather than a series of individual directory names separeted by spaces.
$ mkdir " directory name"
admins-power-mac-g5:~ admin$
While it is common to use spaces in file and directory names in graphic user interfaces (such as Macintosh,
OS/2, and Windows, as well as Gnome or KDE), this may cause failure with older scripts or programs. Some
programs may convert the spaces in a directory name into %20, such as converting " Name with spaces" into "
Name%20with%20spaces" . This might cause confusion or failure.
long options
The long options are:
-m
-p
-v
-Z
--mode=MODE
--parents
-verbose
--context=CONTEXT
--help
--version
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
history
The mkdir command appeared in Version 1 of AT&T UNIX. In early versions of UNIX, the mkdir
command had to be setuid root because the kernel did not yet have a mkdir syscall. The mkdir command
made a directory with the mknod syscall, followed by linking in the . and .. directories.
The mkdir syscall originated in 4.2 BSD and was added to System V in Release 3.0.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
alias
chapter 26
This chapter looks at alias, a UNIX (and Linux) command.
alias is used to create short names for long strings of commonly performed commands, scripts, and
functions, and their combinations.
is a builtin command in bash and csh. There is also an external utility with the same name and
functionality.
alias
example
You can use the alias command to modify the rm so that it always displays an interactive query before
deleting a file.
$ alias rm="rm -i"
Unfortunately, this alias can cause some scripts to fail (possibly including system scripts that were
provided with your distribution). Any scripts that rely on the unmodified version of an aliased rm are likely to
fail or produce strange results because of your alias.
A better alternative is to use an alias to a different, non-conflicting name. In this case, del might be
appropriate.
$ alias del="rm -i"
overriding aliases
If you have set an alias on a command or utility, you can always run the raw unmodified command or
utility by typing the absolute directory path to the command. For example, if you set an alias to have ls
always show hidden files, you can still run the regular ls by typing its full path name.
$ alias ls="ls -a" #modify the ls command
$ /bin/ls #run the raw ls command
Some system administrators always type out the complete path name for a command when using the root
or superuser account to help prevent mistakes.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
pipe
chapter 27
summary
This subchapter looks at pipes.
Pipes are most commonly used as a method to chain different utilities together, with the output of one
piped tot he input of the next.
history
Ken Thompson invented the pipe in 1972.
The pipe is a standard mechanism for allowing the output of one program or process to be used as the input
for another program or process.
Pipes allow the UNIX philosophy of having many small programs that each do one function very well and
then write scripts that combine these small utility programs to accomplish bigger tasks.
how to pipe
To pipe the output of one UNIX command or utility to the next, simply place the | (vertical bar character)
between the two processes:
$ cat file01.txt | sort | lp
The example obtains the contents of the designated file, sorts the contents, and then sends the result to the
printer.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
sysadmin
In the UNIX world, the system administrator is often called the sysadmin.
root/superuser
The root or superuser account has total authority to do anything on the system. This power is great for
fixing problems, but bad because one accidenttally mistyped character could be very destructive. Some
systems also have admin accounts of similar power.
Because of the potential for destructiveness, system administrators typically login with either a normal user
account or a limited admin account for every day work and then switch to superuser or root only when
absolutely necessary (and then immediately switch back).
The UNIX command for temporarily switching to root or superuser power is the sudo command, discussed
in the next chapter.
special powers
The root or superuser account has powers that mere mortal accounts dont have.
The root account has access to commands that effect the entire computer or system, such as the ability to
halt or shutdown the system.
The root account is not affected by read and write file access permissions. The root or superuser account
can create, remove, read, or write any file anywhere on the system.
Some commands have built-in restrictions that the root or superuser can ignore. For example, the system
administrator can change any users password without knowing the old password.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
sudo
chapter 29
summary
This chapter looks at sudo, a UNIX (and Linux) command.
sudo
The sudo command allows you to run a single command as another user, including at superuser or root
level from a normal account. You will be asked for the password before the command will actually run.
This keeps you firmly in a normal account (with less danger of catastrophic failures), while still giving
easy access to root or superuser power when really needed.
The sudo program was originally written by Bob Coggeshall and Cliff Spencer in 1980 at the Department
of Computer Science at SUNY/Buffalo.
To run a single command as superuser or root, type sudo followed by a command.
$ sudo command
On Mac OS X the sudo command will fail if your account has no password.
On Mac OS X the sudo commands password prompt will not display anything (not even bullets or
asterisks) while you type your password.
You will not be asked for a password if you use sudo from the root or superuser account. You will not be
asked for a password if you use sudo and the target user is the same as the invoking user.
Some systems have a timer set (usually five minutes). You can run additional sudo commands without a
password during the time period.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
other users
To run a command as another user, type sudo followed by the option -u followed by the user account
name followed by a command.
$ sudo -u username command
which password
On some systems, you will authenticate with your own password rather than with the root or superuser
password. The list of users authorized to run sudo are in the file /etc/sudoers (on Mac OS X,
/private/etc/sudoers).
unreadable directories
To view unreadable directories:
$ sudo ls /usr/local/protected
shutdown
To shutdown a server:
$ sudo -r +15 "quick reboot"
usage listing
To make a usage listing of the directories in the /home partition (note that this runs the commands in a subshell to make the cd and file redirection work):
$ sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
security
The system can be set up to send a mail to the root informing of unauthorized attempts at using sudo.
The system can be set up to log both successful and unsuccessful attempts to sudo.
Some programs (such as editors) allow a user to run commands via shell escapes, avoiding sudo checks.
You can use sudos noexec functionality to prevent shell escapes.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
su
chapter 30
summary
This chapter looks at su, a UNIX (and Linux) command.
su
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
who
chapter 31
summary
This chapter looks at who, a UNIX (and Linux) command.
The who command was described in the first UNIX book, UNIX Programmers Manual, by Ken Thompson
and Dennis Ritchie, published November 3, 1971.
The format is the login name of the user, followed by the users terminal port, followed by the month, day,
and time of login.
Aug 25 17:30
A related command without any spaces, whoami, lets you know which account you are currently logged in
with.
$ whoami
admin
ttys000
$
Aug 25 17:30
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
3/5/13 11:00 AM
absolute paths
It is common for a system administrator logged in to the root or superuser accunt to type out the absolute
path to a command or utility. This will skip any aliases. This will also skip over any commands in the users
defined search path. This guarantees that the correct command or utility will run.
everything is files
In UNIX, everything is a file, even hardware devices such as printers, hard drives, and other devices. Even
UNIX abstractions such as directories, pipes, and file redirection are treated as files.
Becuase everything is a file, the operating system can provide a common processing and communication
interface. This is essential to the UNIX approach of using lots of small programs or utilities that do one job
well and connecting these programs with shell scripts to do a wide variaety of activities.
man pages
Many forms of UNIX have a man page on filesystems.
$ man filesystems
If your system has this man page, you will find a general overview of UNIX file systems of all types,
including CDROMs, floppy disks, and tape drives.
diskless
Almost every UNIX system has a root directory and file system, which is stored on one or more hard
drives connected to the computer system.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
There are diskless nodes. These are computers that dont have their own local hard drive. Diskless nodes
run off a network server. Mac OS X makes it easy to set up a computer to run in this manner. This approach
is often used when an organization wants central control of all of the computers in the organization, such as a
computer lab at a school.
root directory
You can examine the contents of the root directory with the ls -F / command.
$ ls -F /
Applications/
Desktop DB
Desktop DF
Developer/
Library/
Network/
System/
Users/
Volumes/
bin/
cores/
dev/
etc@
home/
mach-Kernal
mach_kernel.ctfsys
net/
private/
sbin/
tmp@
usr/
var@
3/5/13 11:00 AM
FAQs
You can find a FAQ (Frequently Asked Questions) file for all UNIX variants. Find the appropriate FAQ
for your version of UNIX or Linux and look up the details for your system.
/etc
A key directory for new system administrators to learn is the /etc directory. The /etc directory contains
key system administration files.
Because the /etc files change system behavior and properties, a system administrator spends a lot of time
modifying and updating these files.
A new system administrator can learn a lot about UNIX by studying the files in the /etc directory. Do not
change these files until you have figured out what you are doing. This is not the place for random
experimentation.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
is the name of the system. It may contain the full domain. Not used on Mac OS X.
/etc/hosts
is the summary of the full host names. A system administrator will add to this standard file.
/etc/fstab
/etc/passwd
/etc/group
is the password file. It includes a number of items of basic information on user accounts.
/var
Another important directory for system administrators to know is the /var directory, which contains
configuration files for many system services.
For example, the /var/named file configures Domain Name Service and the /var/yp file configures
Network Information Service.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Access permissions are separate from invisibility. In MS-DOS, a hidden file can not be written to. In
UNIX, you can freely read and write and otherwise modify a hidden file.
In UNIX, file access is controlled by access permissions.
As a reminder from the ls chapter, the -a option will give a list of all files, including hidden files.
$ ls -a
Each user has a few important hidden files that configure their basic working environment when they
login. These include:
.cshrc
.login
.profile
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
major directories
chapter 33
summary
This chapter looks at some of the major directories (folders) on UNIX/Linux/Mac OS X.
directory listing
The following is a brief description of some of the major directories. Not all systems will have all of these
directories.
/ The root directory of the entire file system.
/Applications On Mac OS X, this is the location of the Macintosh programs.
/Applications/Utilities On Mac OS X, this is the location of the graphic user interface based utility
programs.
/bin A collection of binary files, better known as programs. These are the programs needed by the
operating system that normal users might use. Many of the standard system commands are stored here.
Contrast with /sbin below.
/boot or /kernel The files needed to boot or start your computer. Includes the bootstrap loader, the very
first thing loaded when your computer starts. On Linux, it usually includes the Linux kernel in the
compressed file vmlinuz.
/dev The devices connected to your computer (remember, everything, even hardware devices, is treated as
a file in UNIX or Linux). Examples are the keyboard, disks, and printers.
/etc System-wide configuration files, startup procedures, and shutdown procedures.
/home or /users The home directories for each user. Contains such things as user settings, customization
files, documents, data, mail, and caches. The contents of this directory should be preserved during operating
system updates or upgrades.
Every new user account starts with a few basic files such as .login, .cshrc, and .profile. A system
administrator may want to add additional customization such as an introductory README file.
/lib or /Library Shared library files and kernel modules.
/lost+found Files recovered during filesystem repair.
/mnt Mount points for removable media (floppy disks, CD-ROM, Zip drives, etc.), partitions for other
operating systems, network shares, and anything else temporarily mounted to the file system. Linux and
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
mount/export
The mount command will replace a local directory with a directory from another machine. Anyone viewing
the mounted directory will see the remote directory as if it were local.
The export command is used to make a directory available for other computers to mount it.
The /etc/exports file contains a list of directories to be exported.
mount
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
chmod
chapter 35
summary
This chapter looks at chmod, a UNIX (and Linux) command.
chmod
The chmod command was described in the first UNIX book, UNIX Programmers Manual, by Ken
Thompson and Dennis Ritchie, published November 3, 1971.
wide open
The chmod 777 filename command will set the permissions so that filename is wide open to everyone.
$ chmod 777 filename
The file owner, the file owners group, and other (or world) will all be able to read, write, delete, modify,
and execute (run) the file to their hearts content. This access includes anyone who gets into your system
through the internet.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
chown
chapter 36
summary
This chapter looks at chown, a UNIX (and Linux) command.
chown
The chown command was described in the first UNIX book, UNIX Programmers Manual, by Ken
Thompson and Dennis Ritchie, published November 3, 1971.
Of course, a system administrator can use root to freely change ownership of files and directories. This is a
powerful tool in the hands of a system administrator.
security leak
This command is often limited to only root (or superuser) because if a computer system or server enforces
limits on how much disk storage space each account is allowed, someone can set a file so they still can read
and write it (and possibly execute it, if applicable), then change ownership to anyone else. This gets the file
(or entire directories) out of their storage limits, but they can still make use of the files.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
3/5/13 11:00 AM
management tools
chapter 37
summary
This chapter looks at management tools for UNIX and Linux.
Every major version of UNIX and Linux includes several management tools. Some use a graphic interface,
while others are accessed through the command line. Some management tools will even provide both a
command line and a graphic interface.
Comparison chart
OS
Comprehensive
AIX
HPUX
GlancePlus, MeasureWare/Perfview,
Caliper
RAM
vmstat,
svmon
CPU
I/O
iostat,
vmstat, sar
filemon
Network
vmstat
top
iostat
netstat
iostat
netstat, lperf
iostat
iostat
iostat
netstat, lperf
netstat
netstat
vmstat
vmstat
vmstat
vmstat
top,
mpstat
top,mpstat
top
top
netstat, nfsstat
high availability
Some high availability tools for specific operating systems also have a Linux version.
Veritas for High Availability on Solaris also comes with a Linux client.
PowerHA (formerly known as HACMP) for IBMs AIX also is available in a Linux version.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
df
chapter 38
summary
This chapter looks at df, a UNIX (and Linux) command.
df
human readable
Use the -h or -H option to see space used in human readable format (such as kilobytes, megabytes,
gigabytes, etc.). Both options do the same thing.
$ df -h
Filesystem
/dev/disk0s10
devfs
fdesc
map -hosts
map auto_home
/dev/disk1s2
/dev/disk1s1
Drive
$
Size
149Gi
111Ki
1.0Ki
0Bi
0Bi
498Gi
434Gi
Used
117Gi
111Ki
1.0Ki
0Bi
0Bi
40Gi
81Gi
Avail Capacity
32Gi
79%
0Bi
100%
0Bi
100%
0Bi
100%
0Bi
100%
457Gi
9%
353Gi
19%
Mounted on
/
/dev
/dev
/net
/home
/Volumes/msdos
/Volumes/Mac FreeAgent GoFlex
type
Use the -T option to see the type of file system.
$ df -T
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
du
chapter 39
summary
This chapter looks at du, a UNIX (and Linux) command.
du
display usage
Use the -a option to see an entry for each file in the file hierarchy.
$ du -a
Note that if you run this from root, you will get a large report of every single file on all of the mounted
hard drives. best to run it from a subdirectory.
total
Use the -c option to see a grand total.
$ du -c
kilobytes
Use the -k option to see the results listed in kilobytes.
$ du -k
You can use the alias command to modify the du so that it always displays the file information in
kilobytes.
$ alias du=du -k
If you need to use the unmodified version of this now aliased command, simply type a slash ( \ ) in front
of the du command.
$ \du
A better alternative is to use an alternate spelling, such as duk for your alias. Any scripts that rely on the
unmodified version of an aliased du are likely to fail or produce strange results because of your alias.
$ alias duk=du -k
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
3/5/13 11:00 AM
processes
chapter 40
This chapter looks at UNIX (and Linux) processes.
The UNIX term process is pretty much the same as the terms job or task on other operating systems.
multi-tasking
UNIX is a multi-processing operating system. This means that it runs more than one task (or job or
process) at a time. On a multi-processor computer it is possible for UNIX to literally run multiple processes
at the exact same time. On a single processor computer different processes are swapped into the main CPU
(central processing unit) so fast that it gives the illusion that multiple processes are running simultaneously.
One of the reasons that multitasking works is that the processor runs much faster than input/output or mass
storage devices (and on modern computers often runs much faster than main memory). Whenever a process
has to stop for input, output, or mass storage, there is a convenient moment for the operating system to switch
to a different process that is ready to run rather than leave the CPU sitting idle waiting for the I/O to occur.
init
The first process to start running on a traditional UNIX computer is init. Some modern variations, such as
Linux, may have a few other processes run first, especially.if the computer or server supports multiple
operating systems.
starts a series of other processes (in UNIX, this is called spawning). Some of these processes only run
during boot-up, while others are intended to run as long as the computer is running.
init
By the time a human user can login to the system, many processes are running.
init
process ID
Every process on UNIX (or Linux) has a unique process identification number, called the process ID.
A system administrator uses the process IDs to control the processes.
kill
One useful command available for the system administrator is the kill command, which stops a process
and removes it from the system.
An ordinary user can only kill his or her own processes.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
A system administrator running as root (including using sudo) can use kill on any process on the entire
system.
See the chapter on kill for more information.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
ps
chapter 41
summary
This chapter looks at ps, a UNIX (and Linux) command.
ps
info on processes
Type ps followed by the option -a (for all). An optional pipe to more or less will provide one page of
info at a time.
$ ps -a |more
ps
ps
can be used to find processes that are stuck, which can then be killed.
monitor processes
ps -ax will provide information on most running processes. You can use the command to establish the
baseline performance for your server and to monitor errant processes.
$ ps -ax
full information
Type ps followed by the -ef options to see most of the available information on processes.
$ ps -ef |less
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
daemons
On Linux you use the following to get information on core processes and daemons:
$ /sbin/chkconfig --list
load balancing
Most of the daily work for a system administrator is making sure that system resources arent overloaded
so that everythign runs smoothly.
Sometimes a program will hog the CPU. This may be due to an infinite loop, repeatedly forking itself, or
other bug, or it may be due to the nature of the processing being done.
In either case, the system administrator can use the nice command to adjust the CPU priority of each
runnign process so that the entire system runs smoothly.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
kill
chapter 42
summary
This chapter looks at kill, a UNIX (and Linux) command.
kill
kill
is a builtin command in csh. There is also an external utility with the same name and functionality.
frozen process
Sometimes a process (particularly web browsers) will freeze up. The kill command can be used to rmove
the frozen program from the system.
If a user finds their display locked up because of a frozen program, he or she can login to another
computer, then login to the original system using rlogin, and then use the kill command to stop the
offending process using the specific process ID.
killall
is a related command. killall program_name will stop all processes with the program name, so
the more specific kill with a specific process ID is usually used first.
killall
process isolation
UNIX does a very good job of keeping processes isolated from each other, so that no rogue process can
attack or damage any other process.
Unlike Windows, a frozen or crashed program on UNIX or Linux shouldnt be able to bring the entire
operating system to a halt.
Most UNIX vendors carefully test their own system software and most of the system software has been
running and tested for decades, so those programs rarely cause problems.
Most bugs occur in third party software and in custom software developed for a particular installation.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
3/5/13 11:00 AM
nice
chapter 43
summary
This chapter looks at nice, a UNIX (and Linux) command.
load balancing
Most of the daily work for a system administrator is making sure that system resources arent overloaded
so that everythign runs smoothly.
Sometimes a program will hog the CPU. This may be due to an infinite loop, repeatedly forking itself, or
other bug, or it may be due to the nature of the processing being done.
In either case, the system administrator can use the nice command to adjust the CPU priority of each
runnign process so that the entire system runs smoothly.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
w
chapter 44
summary
This chapter looks at w, a UNIX (and Linux) command.
w
gives information about current activity on the system, including what each user is doing.
Not to be confused with who, which displays users, but not the processes they are running.
info
Type w:
$ w
does not provide information on background processes, which typically account for most of the server
usage.
w
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
uname
chapter 45
summary
This chapter looks at uname, a UNIX (and Linux) command.
uname
On a Linux machine you can find all of this same information in the appropriate files in the /proc
filesystem, but uname utility may be easier and faster to use.
basic use
Type the uname without any options to get the kernel name.
$ uname
Darwin
system
Use the -s option to get the operating system name.
$ uname -s
Darwin
release info
Use the -r option to get the operating system release information.
$ uname -r
9.8.0
machine
Use the -m option to get the machine hardware name.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
$ uname -m
Power Macintosh
When running on an Intel (or compatiable) processor, you may also get an indication as to whether it is a
32-bit or 64-bit system.
$ uname -m
x86_64
processor
Use the -p option to get the machine processor architecture type.
$ uname -p
powerpc
network node
Use the -n option to get the network node host name (node name).
$ uname -n
local
You can also use the hostname command to get the exact same answer.
all
Use the -a option to get all of the information available from this command.
$ uname -a
Darwin admins-power-mac-g5.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul
15 16:57:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh
nonstandard
There are a few additional nonstandard options that may be available. Even if available, they may produce
unknown as their output. because these are nonstandard options, you should avaoid using them in a script.
Use the -i option to get hardware platform information.
$ uname -i
x86_64
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
uptime
chapter 46
summary
This chapter looks at uptime, a UNIX (and Linux) command.
uptime
info
Type uptime:
$ uptime
20:03 up
$
tells you how long your server has been running. uptime also gives the average system load for the
last few minutes. Use uptime for a quick performance check. Collect daily data to watch for problems from
underpowered CPUs or memory management.
uptime
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
top
chapter 47
summary
This chapter looks at top, a UNIX (and Linux) command.
top
using top
Type top and ENTER or RETURN.
$ top
You will get updated reports (typically, once per second) on the active processes, load average, CPU
usage, shared libraries, and memory usage (regions, physical, and virtual).
Type q to stop the top program.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
lsof
chapter 48
This subchapter looks at lsof, a UNIX (and Linux) command.
lsof lists open files (and that includes devices, directories, pipes, nodes, sockets, and anything else that
UNIX treats as a file).
lsof
will give you information on any opened files (including all of the items UNIX treats as a file).
basic use
Type lsof all by itelf to get a list of all open files belonging to all active processes. The list was huge when
creating this example, so I have edited it to highlight some of the things listed.
$ lsof
COMMAND
PID
USER FD
TYPE
DEVICE
SIZE/OF
NODE NAME
loginwind 24 admin cwd
DIR
14,8
1564
2 /
loginwind 24 admin txt
REG
14,8
946736 1076582
/System/Library/CoreServices/loginwindow.app
/Contents/MacOS/loginwindow
loginwind 24 admin
0r
CHR
3,2
0t0 35264644 /dev/null
loginwind 24 admin
1
PIPE 0x224f3f0
16384
loginwind 24 admin
2
PIPE 0x224f3f0
16384
loginwind 24 admin
3u
unix 0x27766e8
0t0
->0x224cdd0
launchd
68 admin
3u KQUEUE
count=0,
state=0x1
launchd
68 admin
5u
systm 0x25f1264
0t0
[1:1:0]
launchd
68 admin
15
PIPE 0x224f6ac
16384
launchd
68 admin
19r
DIR
14,8
1122
248
/Library/Preferences
AirPort
84 admin cwd
DIR
14,8
1564
2 /
AirPort
84 admin txt
REG
14,8
573072 3265433
/System/Library/CoreServices
/AirPort Base Station Agent.app/Contents/MacOS/AirPort Base Station Agent
Spotlight 88 admin cwd
DIR
14,8
1564
2 /
Spotlight 88 admin txt
REG
14,8
708848 1067264
/System/Library/CoreServices
/Spotlight.app/Contents/MacOS/Spotlight
UserEvent 89 admin cwd
DIR
14,8
1564
2 /
Dock
90 admin cwd
DIR
14,8
1564
2 /
Dock
90 admin txt
REG
14,8
2384752 1046722
/System/Library/CoreServices
/Dock.app/Contents/MacOS/Dock
Dock
90 admin
4u KQUEUE
count=0,
state=0x2
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
/
/
/
/
/
The default is one file per line. The FD column gives the file descriptor and the TYPE column gives the
file type. The other columns should make sense.
Some of the common FD values are:
cwd = Current Working Directory
mem = memory mapped file
mmap = memory mapped device
rtd = root directory
txt = text file
NUMBER = file descriptor. The character after the number inidicates the mode in which the file is
opened. r = read, w = write, and u = both read and write. This may be followed by lock information.
asdf
Some of the common TYPE values are:
BLK = block special file
CHR = character special file
DIR = directory
FIFO = First In First Out special file
IPv4 = IPv4 socket
IPv6 = IPv6 socket
LINK = symbolic link file
PIPE = pipe
REG = regular file
unix = UNIX domain socket
NODE NAME
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
14,8
2402112 10720
14,8
2402112 10720
14,8
2402112 10720
14,8
2402112 10720
To list all the processes that have opened files in a particular directory and all of its child directories
(subdirectories), use the +D option. lsof will recurse through all subdirectories.
$ lsof +D /var/
COMMAND
PID USER
FD
TYPE DEVICE SIZE/OFF
NODE NAME
loginwind 24 admin txt
REG
14,8 149168128 1137272
/private/var/db/dyld/dyld_shared_cache_ppc
loginwind 24 admin
4u
REG
14,8
2512 3589022
/private/var/run/utmpx
launchd
64 admin txt
REG
14,8 149168128 1137272
/private/var/db/dyld/dyld_shared_cache_ppc
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
$ lsof -c Terminal
COMMAND PID USER
FD
Terminal 168 admin cwd
Terminal 168 admin txt
/usr/share/icu/icudt36b.dat
Terminal 168 admin
0r
Terminal 168 admin
1
Terminal 168 admin
2
TYPE
DIR
REG
DEVICE
14,8
14,8
CHR
3,2
PIPE 0x22374b4
PIPE 0x22374b4
SIZE/OFF
918
10244512
NODE NAME
547359 /Users/admin
1048543
To list all of the files opened by several specific users, use a comma delimited list.
$ lsof -u jack,jill
To list all of the files opened by every user other than a specific user, use the ^ character. You can use a
comma delimited list
$ lsof -u ^jack,jill
3/5/13 11:00 AM
$ lsof +D /home/
list by device
To list all open files on device /dev/hd4, type lsof /dev/hd4. (from the man pages)
$ lsof /dev/hd4
kill process
To kill the process that has /u/abe/foo open (by sending the signal SIGHUP), type kill -HUP `lsof -t
/u/abe/foo`. (from the man pages)
$ kill -HUP `lsof /u/abe/foo`
AND/OR
defaults to logical OR of all options. The following example (from the man pages) will list all of the files
open from all three listed processes and from both users.
lsof
Use the -a option to perform a logical AND on the user names, processes, etc. Note that you either OR the
entire line or AND the entire line. You can not mix AND and OR together in a single lsof command. The ^
negation on login name or user ID, process ID, or process group ID options are evaluated prior to other
selection criteria and therefore dont get included in AND or OR for lsof. Although the -a is legal in any
position, placing it between a pair of items does not cause just those two items to be ANDed, the entire line is
still ANDed.
The following AND example will produce a listing of only UNIX socket files that belong to processes
owned by the user foo.
$ lsof -a -U -ufoo
timed listings
You can gather information at specific time intervals. To list the files at descriptors 1 and 3 of every
process running the lsof command for login abe every 10 seconds, type lsof -c lsof -a -d 1 -d 3 -u
abe -r10. (from the man pages)
$ lsof -c lsof -a -d 1 -d 3 -u abe -r10
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Use the +r or -r options for timed repeats. The +r switch will stop when no open files that meet the
selected criteria are open. The -r will continue until interrupted by a signal. The number after the r is the
time in seconds for each delay.
Between each cycle, lsof will print a sequence of equal signs ( ======= ).
=======
internet connections
Because UNIX and Linux (and Mac OS X) treat internet connections as files, you can use the -i switch to
view all of your open internet connections.
$ lsof -i
COMMAND
PID USER
FD
TYPE
DEVICE SIZE/OFF NODE NAME
SystemUIS 93 admin
10u IPv4 0x2152f48
0t0 UDP *:*
firefox-b 127 admin
75u IPv4 0x43c5270
0t0 TCP
192.168.0.108:49816->63.141.192.121:http (CLOSE_WAIT)
Fetch
294 admin
23u IPv4 0x27ffe64
0t0 TCP
192.168.0.108:50539->reliant.websitewelcome.com:ftp (ESTABLISHED)
Fetch
294 admin
24u IPv4 0x2d2be64
0t0 TCP
192.168.0.108:50541->reliant.websitewelcome.com:36975 (LAST_ACK)
Fetch
294 admin
25u IPv4 0x444a66c
0t0 TCP
192.168.0.108:50542->reliant.websitewelcome.com:22271 (TIME_WAIT)
internet files
To list all open Internet, x.25 (HP-UX), and UNIX domain files, type lsof -i -U. (from the man pages)
$ lsof -i -U
IPv6 files
To list all open IPv6 network files (assuming your UNIX system supports IPv6), type lsof -i 6. (from the
man pages)
$ lsof -i 6
list by port
List all of the processes that are listening to a particular port by using colon ( : ) followed by the port
number(s).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
$ lsof -i:21
To list all files using any protocol on ports 513, 514, or 515 of host wonderland.cc.purdue.edu, type lsof
-i @wonderland.cc.purdue.edu:513-515. (from the man pages)
$ lsof -i @wonderland.cc.purdue.edu:513-515
socket files
To find an IP version 4 socket file by its associated numeric dot-form address, type lsof [email protected]. (from the man pages)
$ lsof [email protected]
To find an IP version 6 socket file by its associated numeric colon-form address, type lsof i@[0:1:2:3:4:5:6:7]. (from the man pages)
$ lsof -i@[0:1:2:3:4;5;6:7]
To find an IP version 6 socket file by its associated numeric colon-form address that has a run of zeros in it
(such as the loop-back address), type lsof -i@[::1]. (from the man pages)
$ lsof -i@[::1]
To find processes with open files on the NFS file system named /nfs/mount/point whose server is
inaccessible (assuming your mount table supplies the device number for /nfs/mount/point), type lsof -b
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
To do the preceding search with warning messages suppressed, type lsof -bw /nfs/mount/point. (from
the man pages)
$ lsof -bw /nfs/mount/point
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
free
chapter 49
summary
This chapter looks at free, a Linux command.
free
free displays the total amount of free and used physical memory and swap space in the system, as well as
the buffers and cache consumed by the kernel.
size
The default is to report the memory size in bytes. Use the -g option to display in Gigabytes. Use the -m
option to display in Megabytes. Use the -k option to display in Kilobytes. Use the -b option to display in
Bytes.
total
Use the -t option to view total memory.
low/high
Use the -l option to view low vs. high memory usage.
count
The default is to display the information once and then return to the normal shell. Use the -s n option
(where n is the number of times to display) to keep displaying the memory usage (until interrupted). Use the
-c n or --count=n options (where n is the number of times to display the memory statistics).
Mac OS X
Use the Activity Monitor for this purpose. From the command line, you can get similar results from
is a Mach-specific version of the UNIX command vmstat Also:
vm_stat. vm_stat
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
vmstat
chapter 50
summary
This chapter looks at vmstat, a UNIX (and Linux) command.
vmstat
usage
Type vmstat to see a list of virtual memory statistics. Especially useful in a virtulaized enivronment.
$ vmstat
Mac OS X
vm_stat
$ vm_stat
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
defaults
chapter 51
summary
This chapter looks at defaults, a Mac OS X command.
defaults
defaults options
Mac OS X programs use the defaults system to record user preferences and other information. Most of the
information is more easily accessed through the applications Preferencess panel, but some information is
normally inaccessible to the end user.
Note: Since applications do access the defaults system while theyre running, you shouldnt modify the
defaults of a running application.
All programs share the defaults in NSGlobalDomain. If the program doesnt have its own default, it uses
the value from the NSGlobalDomain.
screencapture defaults
The following methods use Terminal to change the default file format and location where the screenshot is
saved from the graphic user interface.
In Mac S X 10.4 (Tiger) or more recent, the default screencapture format can be changed in Terminal by
using the defaults command. In Mac S X 10.4 (Tiger), the new default does not take effect until you logout
and log back in (from the entire computer, not just from Terminal a full restart will also work) unless you
also use the killall command.
$ defaults write com.apple.screencapture type ImageFormat; killall
SystemUIServer
The ImageFormat can be png (Portable Network Graphic), pdf (Portable Document Format), tiff (Tagged
Image File Format), jpg or jpeg (Joint Photographic Experts Group), pict (Macintosh QuickDraw Picture),
bmp (Microsoft Windows Bitmap), gif (Graphics Interchange Format), psd (Adobe Photoshop Document),
sgi (Silicon Graphics File Format), or tga (Truevision Targe File Format).
JPGs are saved at quality 60%.
To change the default location where the screenshot file is saved (the default is Desktop), use the following
Terminal command (where PathName is the full path to a directory.
$ defaults write com.apple.screencapture location PathName; killall
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
SystemUIServer
The normal default location would be reset with the following command (where UserName is the current
accounts user name.
$ defaults write com.apple.screencapture location /Users/UserName/Desktop;
killall SystemUIServer
dock defaults
Use the following commands to change the 3D Dock of Mac OS X Leopard and later back to the 2D look.
The killall restarts the Dock so that the change takes effect right away.
$ defaults write com.apple.dock no-glass -boolean YES; killall Dock
Use the following commands to add a gradient behind an icon in a Dock Stack in Mac OS X:
$ defaults write com.apple.dock mouse-over-hilte-stack -boolean YES;
killall Dock
Use the following commands to add a small Expos button to the upper right of your Mac OS X screen.
Clicking on the Expos button will show all of the windows from the current application (same as the normal
F10 default) and option clicking the Expos button will show all windows from all programs (same as the
normal F9 default). This will work even if you reconfigure the F9 and F10 keys to do something else.
$ defaults write com.apple.dock wvous-floater -bool YES; killall Dock
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
login defaults
Use the following command to add a message to your Login window. Replace message with a short
message. Keep the message short. As always with the sudo command, type very carefully.
$ sudo defaults write /Library/Preferences/com.apple.loginwindow
LoginwindowText "message"
.DS_Store files
To prevent Mac OS X from creating .DS_Store files on network shares (and everywhere else), type:
$ defaults write com.apple.desktopservices DSDontWriteNetworkStores true
To restore Mac OS X from creating .DS_Store files on network shares (and everywhere else), type:
$ defaults write com.apple.desktopservices DSDontWriteNetworkStores false
3/5/13 11:00 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
init
chapter 52
summary
This chapter looks at init, a Linux command.
init
run levels
Linux has run levels (sometimes written as a single word, runlevel). The non-graphic mode is run level 3.
the graphic mode is run level 5. Sometimes a Linux server will only boot up to the non-graphic level. You
can use this command to temporarily get the graphic interface running (run level 5).
$ init 5
DESCRIPTION
System is halted
Single-user Mode
used for system maintenance
3
4
5
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
sendmail
chapter 53
summary
This chapter looks at sendmail, a UNIX/Linux utility.
sendmail
In 1975 the Sendmail email system was added to the BSD version of UNIX. Because email was built into
the operating system, email was the method UNIX used for sending notifications to the system administrator
of system status, reports, problems, etc.
set-up
Each version of UNIX has its own variation of sendmail, but the default installation almost always works
correctly without modification. A system administrator rarely needs to know how to set-up or modify
sendmail.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
ifconfig
chapter 54
summary
This chapter looks at ifconfig, a UNIX (and Linux) command.
ifconfig
Warning: ifconfig will not save changes on AIX after a reboot. On Linux, any changes made with
are saved on a reboot.
ifconfig
view configuration
Type ifconfig by itself to view how your network is configured.
$ ifconfig
static IP address
Use ifconfig interface IP-address to set the static IP address for a particular interface
$ ifconfig en0 100.1.1.1
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
arp
chapter 55
summary
This chapter looks at arp, a UNIX (and Linux) command.
arp
display all
Use the -a option to display all of the current ARP entries. Useful in conjunction with ifconfig and
route.
$
?
?
?
$
arp -a
(192.168.0.1) at 0:11:95:75:8:86 on en1 [ethernet]
(192.168.0.106) at 0:d:60:d2:55:3f on en1 [ethernet]
(192.168.0.255) at ff:ff:ff:ff:ff:ff on en1 [ethernet]
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
netstat
chapter 56
summary
This chapter looks at netstat, a UNIX (and Linux) command.
netstat
view connections
Type netstat to see the list of all sockets and server connections.
$ netstat
main info
The main information for webserver administration is in the first few lines, so you can pipe to head:
$ netstat | head
routing addresses
Use the -r option to display the network routing addresses.
$ netstat -r
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
route
chapter 57
summary
This chapter looks at route, a UNIX (and Linux) command.
route
view connections
Type route followed by the -v option to list the routing tables. This is close to the same information
reported by netstat -r.
$ route -v
routing commands
The route utility can used for add, flush, delete, change, get, or monitor.
The add command will add a route.
The flush command will remove all routes.
The delete command will delete a specific route.
The change command will change aspects of a route (such as its gateway).
The get command will lookup and display the route for any destination.
The monitor command will continuously report any changes to the routing infrmation base, routing lookup
misses, or suspected network partitionings.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
ping
chapter 58
summary
This chapter looks at ping, a UNIX (and Linux) command.
ping
test packets
ping
sends test packets to a specific server to see if the server responds properly.
will continue forever unless halted or you give a specific count limit.
$ ping -c 5 www.osdata.com
PING osdata.com (67.18.4.2): 56 data bytes
64 bytes from 192.168.0.1: icmp_seq=0 ttl=127
64 bytes from 192.168.0.1: icmp_seq=1 ttl=127
64 bytes from 192.168.0.1: icmp_seq=2 ttl=127
64 bytes from 192.168.0.1: icmp_seq=3 ttl=127
64 bytes from 192.168.0.1: icmp_seq=4 ttl=127
time=18.801 ms
time=9.918 ms
time=17.216 ms
time=6.748 ms
time=30.640 ms
--- 192.168.0.1 ping statistics --5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max/stddev = 6.748/16.665/30.640/8.295 ms
$
ping
will quickly either return a report or will say destination host unreachable on failure.
measuring
You can measure the dropped packet rate and the minimum, mean, maximum, and standard deviation of
round-trip times.
When using ping for testing, start by pinging local host to verify that the local network interface is up and
running. Then ping hosts and gateways further away.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
nslookup
chapter 59
summary
This chapter looks at nslookup, a UNIX (and Linux) command.
nslookup
information
Type nslookup followed by a doman name.
$ nslookup www.osdata.com
Server:
192.168.0.1
Address:
192.168.0.1#53
Non-authoritative answer:
www.osdata.com canonical name = osdata.com.
Name:
osdata.com
Address: 67.18.4.2
$
security
You can use nslookup to find the DNS information for a particular host IP in your server access logs.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
traceroute
chapter 60
summary
This chapter looks at traceroute, a UNIX (and Linux) command.
traceroute
entire route
Type traceroute followed by a doman name.
$ traceroute www.osdata.com
You can use traceroute to diagnose network problems. When some people can access your website and
other cant, then traceroute can help you find the break or error along the network path.
etiquette
puts a load on every server in the path to the selected host. Therefore, only use traceroute
when you need the diagnosis.
traceroute
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
cURL
chapter 61
summary
This chapter looks at cURL, a UNIX (and Linux) command line tool.
is used to interact with the internet. Linux also includes the similar wget command tool. You can
download wget for free using fink.
curl
cURL is a client-side command line tool and accompanying library for transferring data over the internet.
cURL supports a wide variety of internet protocols, including DICT, FILE, FTP, FTPS, Gopher, HTTP,
HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet,
and TFTP. The curl command is designed to work without user interaction or any kind of interactivity. curl
offers useful tricks like proxy support, user authentication, ftp upload, HTTP post, SSL (https:) connections,
cookies, file transfer resume, and more.
The ability to write scripts is essential to make a good computer system. Unixs capability to be extended
by shell scripts and various tools to run various automated commands and scripts is one reason why it has
succeeded so well.
As applications move to the web HTTP Scripting has become more valuable. Being able to
automatically extract information from the web, to fake users, to post or upload data to web servers are all
useful tasks.
Curl is not written to do everything for you. It makes the requests, it gets the data, it sends data and it
retrieves the information. While you can make repeated manual invokes, you probably will need to process
everything using some kind of script language (such as PHP, Python, Ruby, or Perl).
HTTP Protocol
HTTP is the protocol used to fetch data from web servers. It is a very simple protocol that is built upon
TCP/IP. The protocol also allows information to get sent to the server from the client using a few different
methods, as will be shown here.
HTTP is plain ASCII text lines being sent by the client to a server to request a particular action, and then
the server replies a few text lines before the actual requested content is sent to the client.
The client, curl, sends a HTTP request. The request contains a method (like GET, POST, HEAD etc), a
number of request headers and sometimes a request body. The HTTP server responds with a status line
(indicating if things went well), response headers and most often also a response body. The body part is the
plain data you requested, like the actual HTML or the image etc.
3/5/13 11:00 AM
Using curls option --verbose (-v as a short option) will display what kind of commands curl sends to the
server, as well as a few other informational texts.
--verbose is the single most useful option when it comes to debug or even understand the curl <- >server
interaction.
Sometimes even --verbose is not enough. Then --trace and --trace-ascii offer even more details as
they show EVERYTHING curl sends and receives. Use it like this:
$ curl --trace-ascii debugdump.txt http://www.example.com/
URL
The Uniform Resource Locator (URL) format is how you specify the address of a particular resource on
the Internet. You know these, youve seen URLs like http://curl.haxx.se or https://yourbank.com a million
times.
download a file
The simplest and most common request/operation made using HTTP is to get a URL. The URL could itself
refer to a web page, an image or a file. The client issues a GET request to the server and receives the
document it asked for.
You can use curl to download the content of a URL. The following command displays the HTML for
Google as the STDOUT (on your Terminal screen):
$ curl http://www.google.com
If you issue the above command line you get a web page returned in your terminal window. The entire
HTML document that that URL holds.
All HTTP replies contain a set of response headers that are normally hidden, use curls --include (-i)
option to display them as well as the rest of the document. You can also ask the remote server for ONLY the
headers by using the --head (-I) option (which will make curl issue a HEAD request).
redirect a download
You can redirect the results to file using the standard UNIX/Linux redirect. You will be given some status
information if you redirect.
$ curl http://www.google.com > google.html
% Total
% Received % Xferd Average
Speed
Time
Time
Time Current
Dload Upload
Total
Spent
Left Speed
100 10559
0 10559
0
0 26690
0 --:--:-- --:--:-- --:--:- 323k
You can use the -o (lower case o) to save the downloaded file with the name of your choice. You will see
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
progress meter information as the download progresses. In the example, the download was so fast that only
one status report was created.
$ curl -o google.303 www.google.com
% Total
% Received % Xferd Average
Speed
Time
Time
Time Current
Dload Upload
Total
Spent
Left Speed
100
219 100
219
0
0
800
0 --:--:-- --:--:-- --:--:-- 0
You can use -O (uppercase O) switch to use the filename in the URL as the filename used to store the
result
$ curl -O http://www.gnu.org/software/gettext/manual/gettext.html
When you use curl -O (uppercase O), it will save the content in the file named gettext.html itself in the
local machine.
Note: When curl has to write the data to the terminal, it disables the Progress Meter, to avoid confusion in
printing. We can use >|-o|-O options to move the result to a file.
You can also use wget to download files.
The command below will download both index.html and gettext.html and save it in the same name under
the current directory.
$ curl -O http://www.gnu.org/software/gettext/manual/html_node/index.html O http://www.gnu.org/software/gettext/manual/gettext.html
Please note that when we download multiple files from a same sever as shown above, curl will try to re-use
the connection.
3/5/13 11:00 AM
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.in/">here</A>
The above output says that the requested document is moved to http://www.google.co.in/.
We can insists curl to follow the redirection using -L option, as shown below. Now it will download the
google.co.ins html source code.
$ curl -L http://www.google.com
Use the -Z switch to set a limit on the maximum number of redirects allowed to prevent getting lost in
infinite loops or excessively long chains.
More on the use of this feature in the scripting section below.
The above command is limiting the data transfer to 1000 Bytes/second. curl may use higher transfer rate
for short span of time. But on an average, it will come around to 1000B/second.
The following was the progress meter for the above command. You can see that the current speed is near to
the 1000 Bytes.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
% Total
% Received % Xferd
1 1215k
1 1215k
1 1215k
1 13601
1 14601
1 15601
0
0
0
0
0
0
Average Speed
Time
Dload Upload
Total
957
0 0:21:40
960
0 0:21:36
962
0 0:21:34
Time
Spent
0:00:14
0:00:15
0:00:16
Time Current
Left Speed
0:21:26
999
0:21:21
999
0:21:18
999
The above command will download the yy.html only if it is modified later than the given date and time
$ curl -z -21-Dec-11 http://www.example.com/yy.html
The above command will download the yy.html, if it is modified before than the given date and time.
Please refer to man curl_getdate for the various syntax supported for the date expression
Note: By default curl uses Basic HTTP Authentication. We can specify other authentication method using
ntlm | digest.
More information on this topic in the scripting section later in this chapter.
The above command will download the xss.php file from the ftp server and save it in the local directory.
$ curl -u ftpuser:ftppass -O ftp://ftp_server/public_html/
Here, the given URL refers to a directory. So cURL will list all the files and directories under the given
URL
3/5/13 11:00 AM
cURL supports ranges to be given in the URL. When a range is given, files matching within the range will
be downloaded. It will be helpful to download packages from the FTP mirror sites.
$ curl
ftp://ftp.uk.debian.org/debian/pool/main/[a-z]/
The above command will list out all the packages from a-z ranges in the terminal.
The above command will upload the file named myfile.txt to the FTP server. You can also upload multiple
files at a same time using the range operations.
$ curl -u ftpuser:ftppass -T "{file1,file2}" ftp://ftp.testserver.com
Optionally we can use . to get the input from STDIN and transfer to the remote.
$ curl -u ftpuser:ftppass -T - ftp://ftp.testserver.com/myfile_1.txt
The above command will get the input from the user from Standard Input and save the contents in the ftp
server under the name myfile_1.txt.
You can provide one -T for each URL and the pair specifies what to upload where.
3/5/13 11:00 AM
PREF=ID=7c497a6b15cc092d:FF=0:TM=1334056719:LM=1334056719:S=UORpBwxFmTRkbXLj;
expires=Thu, 10-Apr-2014 11:18:39 GMT; path=/; domain=.google.co.in
.
.
If you need more detailed information then you can use the trace option. The trace option will enable a
full trace dump of all incoming/outgoing data to the given file
=> Send header, 169 bytes (0xa9)
0000: 47 45 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d 0a GET / HTTP/1.1..
0010: 55 73 65 72 2d 41 67 65 6e 74 3a 20 63 75 72 6c User-Agent: curl ..
0060: 2e 32 2e 33 2e 34 20 6c 69 62 69 64 6e 2f 31 2e .2.3.4 libidn/1.
0070: 31 35 20 6c 69 62 73 73 68 32 2f 31 2e
0080: 0d 0a 48 6f 73 74 3a 20 77 77 77 2e 67
0090: 6c 65 2e 63 6f 2e 69 6e 0d 0a 41 63 63
00a0: 3a 20 2a 2f 2a 0d 0a 0d 0a
== Info: HTTP 1.0, assume close after body
<= Recv header, 17 bytes (0x11)
0000: 48 54 54 50 2f 31 2e 30 20 32 30 30 20
0010: 0a
32 2e 36 15 libssh2/1.2.6
6f 6f 67 ..Host: www.goog
65 70 74 le.co.in..Accept
: */*....
4f 4b 0d HTTP/1.0 200 OK.
This verbose and trace option will come in handy when curl fails due to some reason and we dont know
why.
The above command will list the meaning for bash as follows
151 "Bash" gcide "The Collaborative International Dictionary of English v.0.48"
Bash \Bash\, v. t. [imp. & p. p. {Bashed}; p. pr. & vb. n.
{Bashing}.] [Perh. of imitative origin; or cf. Dan. baske to
strike, bask a blow, Sw. basa to beat, bas a beating.]
To strike heavily; to beat; to crush. [Prov. Eng. & Scot.]
--Hall Caine.
[1913 Webster]
Bash her open with a rock.
[Webster 1913 Suppl.]
--Kipling.
.
151 "Bash" gcide "The Collaborative International Dictionary of English v.0.48"
Bash \Bash\, n.
1. a forceful blow, especially one that does damage to its
target.
[PJC]
.
.
Now you can see that it uses The Collaborative International Dictionary of English. There are many
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Now in-order to find the actual meaning of Bash in computer we can search for bash in foldoc dictionary
as follows
$ curl dict://dict.org/d:bash:foldoc
For more details with regard to DICT, please read RFC2229 at http://tools.ietf.org/html/rfc2229
Once the above command is entered, it will wait for the user to provide the data to mail. Once youve
composed your message, type . (period) as the last line, which will send the email immediately.
Subject: Testing
This is a test mail
.
forms
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Forms are the general way a web site can present a HTML page with fields for the user to enter data in,
and then press some kind of OK or submit button to get that data sent to the server. The server then
typically uses the posted data to decide how to act. Like using the entered words to search in a database, or to
add the info in a bug track system, display the entered address on a map or using the info as a login-prompt
verifying that the user is allowed to see what it is about to see.
Of course there has to be some kind of program in the server end to receive the data you send. You cannot
just invent something out of the air.
GET
A GET-form uses the method GET, as specified in HTML like:
<form method="GET" action="junk.cgi">
<input type=text name="birthyear">
<input type=submit name=press value="OK">
</form>
In your favorite browser, this form will appear with a text box to fill in and a press-button labeled OK. If
you fill in 1905 and press the OK button, your browser will then create a new URL to get for you. The
URL will get junk.cgi?birthyear=1905&press=OK appended to the path part of the previous URL. In a
browser, this mini-form looks like:
OK
If the original form was seen on the page www.hotmail.com/when/birth.html, the second page youll get
will become www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK.
Most search engines work this way.
To make curl do the GET form post for you, just enter the expected created URL:
$ curl "http://www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK"
POST
The GET method makes all input field names get displayed in the URL field of your browser. Thats
generally a good thing when you want to be able to bookmark that page with your given data, but it is an
obvious disadvantage if you entered secret information in one of the fields or if there are a large amount of
fields creating a very long and unreadable URL.
The HTTP protocol then offers the POST method. This way the client sends the data separated from the
URL and thus you wont see any of it in the URL address field.
The form would look very similar to the previous one:
<form method="POST" action="junk.cgi">
<input type=text name="birthyear">
<input type=submit name=press value=" OK ">
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
</form>
And to use curl to post this form with the same data filled in as before, we could do it like:
$ curl --data
"birthyear=1905&press=%20OK%20"
http://www.example.com/when.cgi
This kind of POST will use the Content-Type application/x-www-form-urlencoded and is the most widely
used POST kind.
The data you send to the server MUST already be properly encoded, curl will not do that for you. For
example, if you want the data to contain a space, you need to replace that space with %20 etc. Failing to
comply with this will most likely cause your data to be received wrongly and messed up.
Recent curl versions can in fact url-encode POST data for you, like this:
$ curl --data-urlencode name=I am Daniel" http://www.example.com
To post this with curl, you wont have to think about if the fields are hidden or not. To curl theyre all the
same:
$ curl --data "birthyear=1905&press=OK&person=daniel" [URL]
3/5/13 11:00 AM
An easy way to get to see this, is to save the HTML page with the form on your local disk, modify the
method to a GET, and press the submit button (you could also change the action URL if you want to).
You will then clearly see the data get appended to the URL, separated with a ?-character as GET forms
are supposed to.
PUT
Perhaps best way to upload data to a HTTP server is to use PUT. Then again, this of course requires that
someone put a program or script on the server end that knows how to receive a HTTP PUT stream.
Put a file to a HTTP server with curl:
$ curl --upload-file uploadfile http://www.example.com/receive.cgi
HTTP Authentication
HTTP Authentication is the ability to tell the server your username and password so that it can verify that
youre allowed to do the request youre doing. The Basic authentication used in HTTP (which is the type curl
uses by default) is *plain* *text* based, which means it sends username and password only slightly
obfuscated, but still fully readable by anyone that sniffs on the network between you and the remote server.
To tell curl to use a user and password for authentication:
$ curl --user name:password http://www.example.com
The site might require a different authentication method (check the headers returned by the server), and
then --ntlm, --digest, --negotiate or even --anyauth might be options that suit you.
Sometimes your HTTP access is only available through the use of a HTTP proxy. This seems to be
especially common at various companies. A HTTP proxy may require its own user and password to allow the
client to get through to the Internet. To specify those with curl, run something like:
$ curl --proxy-user proxyuser:proxypassword www.example.com
If your proxy requires the authentication to be done using the NTLM method, use --proxy-ntlm, if it
requires Digest use --proxy-digest.
If you use any one these user+password options but leave out the password part, curl will prompt for the
password interactively.
Do note that when a program is run, its parameters might be possible to see when listing the running
processes of the system. Thus, other users may be able to watch your passwords if you pass them as plain
command line options. There are ways to circumvent this.
It is worth noting that while this is how HTTP Authentication works, very many web sites will not use this
concept when they provide logins etc. See the Web Login section below for more details on that.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Referer
A HTTP request may include a referer field (yes it is misspelled), which can be used to tell from which
URL the client got to this particular resource. Some programs/scripts check the referer field of requests to
verify that this wasnt arriving from an external site or an unknown page. While this is a stupid way to check
something so easily forged, many scripts still do it. Using curl, you can put anything you want in the refererfield and thus more easily be able to fool the server into serving your request.
Use curl to set the referer field with:
$ curl --referer http://www.example.com/example.html http://www.example.com
User Agent
Very similar to the referer field, all HTTP requests may set the User-Agent field. It names what user agent
(client) that is being used. Many applications use this information to decide how to display pages. Some web
programmers try to make different pages for users of different browsers to make them look the best possible
for their particular browsers. They usually also do different kinds of javascript, vbscript etc.
At times, you will see that getting a page with curl will not return the same page that you see when getting
the page with your browser. Then you know it is time to set the User Agent field to fool the server into
thinking youre one of those browsers.
To make curl look like Internet Explorer 5 on a Windows 2000 box:
$ curl --user-agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
[URL]
Or why not look like youre using Netscape 4.73 on an old Linux box:
$ curl --user-agent "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" [URL]
Redirects
When a resource is requested from a server, the reply from the server may include a hint about where the
browser should go next to find this page, or a new page keeping newly generated output. The header that tells
the browser to redirect is Location:.
Curl does not follow Location: headers by default, but will simply display such pages in the same manner
it display all HTTP replies. It does however feature an option that will make it attempt to follow the Location:
pointers.
To tell curl to follow a Location:
$ curl --location http://www.example.com
If you use curl to POST to a site that immediately redirects you to another page, you can safely use -location (-L) and --data/--form together. Curl will only use POST in the first request, and then revert to
GET in the following operations.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Cookies
The way the web browsers do client side state control is by using cookies. Cookies are just names with
associated contents. The cookies are sent to the client by the server. The server tells the client for what path
and host name it wants the cookie sent back, and it also sends an expiration date and a few more properties.
When a client communicates with a server with a name and path as previously specified in a received
cookie, the client sends back the cookies and their contents to the server, unless of course they are expired.
Many applications and servers use this method to connect a series of requests into a single logical session.
To be able to use curl in such occasions, we must be able to record and send back cookies the way the web
application expects them. The same way browsers deal with them.
The simplest way to send a few cookies to the server when getting a page with curl is to add them on the
command line like:
$ curl --cookie "name=Daniel" http://www.example.com
Cookies are sent as common HTTP headers. This is practical as it allows curl to record cookies simply by
recording headers. Record cookies with curl by using the --dump-header (-D) option like:
$ curl --dump-header headers_and_cookies http://www.example.com
(Take note that the --cookie-jar option described below is a better way to store cookies.)
Curl has a full blown cookie parsing engine built-in that comes to use if you want to reconnect to a server
and use cookies that were stored from a previous connection (or handicrafted manually to fool the server into
believing you had a previous connection). To use previously stored cookies, you run curl like:
$ curl --cookie stored_cookies_in_file http://www.example.com
Curls cookie engine gets enabled when you use the --cookie option. If you only want curl to
understand received cookies, use --cookie with a file that doesnt exist. Example, if you want to let curl
understand cookies from a page and follow a location (and thus possibly send back cookies it received), you
can invoke it like:
$ curl --cookie nada --location http://www.example.com
Curl has the ability to read and write cookie files that use the same file format that Netscape and Mozilla
do. It is a convenient way to share cookies between browsers and automatic scripts. The --cookie (-b) switch
automatically detects if a given file is such a cookie file and parses it, and by using the --cookie-jar (-c)
option youll make curl write a new cookie file at the end of an operation:
$ curl --cookie cookies.txt --cookie-jar newcookies.txt
http://www.example.com
HTTPS
There are a few ways to do secure HTTP transfers. The by far most common protocol for doing this is
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
what is generally known as HTTPS, HTTP over SSL. SSL encrypts all the data that is sent and received over
the network and thus makes it harder for attackers to spy on sensitive information.
SSL (or TLS as the latest version of the standard is called) offers a truckload of advanced features to allow
all those encryptions and key infrastructure mechanisms encrypted HTTP requires.
Curl supports encrypted fetches thanks to the freely available OpenSSL libraries. To get a page from a
HTTPS server, simply run curl like:
$ curl https://secure.example.com
Certificates
In the HTTPS world, you use certificates to validate that you are the one you claim to be, as an addition to
normal passwords. Curl supports client-side certificates. All certificates are locked with a pass phrase, which
you need to enter before the certificate can be used by curl. The pass phrase can be specified on the command
line or if not, entered interactively when curl queries for it. Use a certificate with curl on a HTTPS server
like:
$ curl --cert mycert.pem https://secure.example.com
curl also tries to verify that the server is who it claims to be, by verifying the servers certificate against a
locally stored CA cert bundle. Failing the verification will cause curl to deny the connection. You must then
use --insecure (-k) in case you want to tell curl to ignore that the server cant be verified.
More about server certificate verification and ca cert bundles can be read in the SSLCERTS document,
available online at: http://curl.haxx.se/docs/sslcerts.html
You can delete a default header by providing one without content. Like you can ruin the request by
chopping off the Host: header:
$ curl --header "Host:" http://www.example.com
You can add headers the same way. Your server may want a "Destination:" header, and you can add it:
$ curl --header "Destination: http://nowhere" http://example.com
Web Login
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
While not strictly just HTTP related, it still causes a lot of problems, so heres a quick run-down of how
the vast majority of all login forms work and how to login to them using curl.
It can also be noted that to do this properly in an automated fashion, you will most certainly need to script
things and do multiple curl invokes etc.
First, servers mostly use cookies to track the logged-in status of the client, so you will need to capture the
cookies you receive in the responses. Then, many sites also set a special cookie on the login page (to make
sure you got there through their login page) so you should make a habit of first getting the login-form page to
capture the cookies set there.
Some web-based login systems features various amounts of javascript, and sometimes they use such code
to set or modify cookie contents. Possibly they do that to prevent programmed logins. If reading the code
isnt enough to let you repeat the behavior manually, capturing the HTTP requests done by your browers and
analyzing the sent cookies is usually a working method to work out how to shortcut the javascript need.
In the actual <form> tag for the login, lots of sites fill-in random/session or otherwise secretly generated
hidden tags and you may need to first capture the HTML code for the login form and extract all the hidden
fields to be able to do a proper login POST. Remember that the contents need to be URL encoded when sent
in a normal POST.
Debug
Many times when you run curl on a site, youll notice that the site doesnt seem to respond the same way to
your curl requests as it does to your browsers.
You need to start making your curl requests more similar to your browsers requests:
Use the --trace-ascii option to store fully detailed logs of the requests for easier analyzing and
better understanding
Make sure you check for and use cookies when needed (both reading with --cookie and writing with -cookie-jar)
Set user-agent to one like a recent popular browser does
Set referer like it is set by the browser
If you use POST, make sure you send all the fields and in the same order as the browser does it.
A very good helper to make sure you do this right, is the LiveHTTPHeader tool that lets you view all
headers you send and receive with Mozilla/Firefox (even when using HTTPS).
A more raw approach is to capture the HTTP traffic on the network with tools such as ethereal or tcpdump
and check what headers that were sent and received by the browser. (HTTPS makes this technique
inefficient.)
switches
The following is a list of the switches for curl.
-a/--append
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
(FTP) When used in a ftp upload, this will tell curl to append to the target file instead of overwriting it. If
the file doesnt exist, it will be created.
If this option is used twice, the second one will disable append mode again.
-A/--user-agent
(HTTP) Specify the User-Agent string to send to the HTTP server. Some badly done CGIs fail if its not set
to Mozilla/4.0. To encode blanks in the string, surround the string with single quote marks. This can also be
set with the -H/--header flag of course.
If this option is set more than once, the last one will be the one that's used.
-b/--cookie
(HTTP) Pass the data to the HTTP server as a cookie. It is supposedly the data previously received from
the server in a "Set-Cookie:" line. The data should be in the format "NAME1=VALUE1;
NAME2=VALUE2". If no '=' character is used in the line, it is treated as a filename to use to read previously
stored cookie lines from, which should be used in this session if they match. Using this method also activates
the "cookie parser" which will make curl record incoming cookies too, which may be handy if you're using
this in combination with the -L/--location option. The file format of the file to read cookies from should be
plain HTTP headers or the Netscape/Mozilla cookie file format.
NOTE that the file specified with -b/--cookie is only used as input. No cookies will be stored in the file.
To store cookies, save the HTTP headers to a file using -D/--dump-header!
If this option is set more than once, the last one will be the one thats used.
-B/--use-ascii
Use ASCII transfer when getting an FTP file or LDAP info. For FTP, this can also be enforced by using an
URL that ends with ;type=A. This option causes data sent to stdout to be in text mode for win32 systems.
If this option is used twice, the second one will disable ASCII usage.
--ciphers
(SSL) Specifies which ciphers to use in the connection. The list of ciphers must be using valid ciphers.
Read up on SSL cipher list details on this URL: http://www.openssl.org/docs/apps/ciphers.html (Option
added in curl 7.9)
If this option is used severl times, the last one will override the others.
--connect-timeout
Maximum time in seconds that you allow the connection to the server to take. This only limits the
connection phase, once curl has connected this option is of no more use. See also the --max-time option.
If this option is used several times, the last one will be used.
-c/--cookie-jar
Specify to which file you want curl to write all cookies after a completed operation. Curl writes all cookies
previously read from a specified file as well as all cookies received from remote server(s). If no cookies are
known, no file will be written. The file will be written using the Netscape cookie file format. If you set the
file name to a single dash, -, the cookies will be written to stdout. (Option added in curl 7.9)
If this option is used several times, the last specfied file name will be used.
-C/--continue-at
Continue/Resume a previous file transfer at the given offset. The given offset is the exact number of bytes
that will be skipped counted from the beginning of the source file before it is transfered to the destination. If
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
used with uploads, the ftp server command SIZE will not be used by curl.
Use -C - to tell curl to automatically find out where/how to resume the transfer. It then uses the given
output/input files to figure that out.
If this option is used several times, the last one will be used.
--crlf
(FTP) Convert LF to CRLF in upload. Useful for MVS (OS/390).
If this option is used twice, the second will again disable crlf converting.
-d/--data
(HTTP) Sends the specified data in a POST request to the HTTP server, in a way that can emulate as if a
user has filled in a HTML form and pressed the submit button. Note that the data is sent exactly as specified
with no extra processing (with all newlines cut off). The data is expected to be url-encoded. This will cause
curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F.
If more than one -d/--data option is used on the same command line, the data pieces specified will be merged
together with a separating &-character. Thus, using -d name=daniel -d skill=lousy would generate a post
chunk that looks like name=daniel&skill=lousy.
If you start the data with the character @, the rest should be a file name to read the data from, or - if you
want curl to read the data from stdin. The contents of the file must already be url-encoded. Multiple files can
also be specified. Posting data from a file named foobar would thus be done with --data @foobar.
To post data purely binary, you should instead use the --data-binary option.
-d/--data is the same as --data-ascii.
If this option is used several times, the ones following the first will append data.
--data-ascii
(HTTP) This is an alias for the -d/--data option.
If this option is used several times, the ones following the first will append data.
--data-binary
(HTTP) This posts data in a similar manner as --data-ascii does, although when using this option the entire
context of the posted data is kept as-is. If you want to post a binary file without the strip-newlines feature of
the --data-ascii option, this is for you.
If this option is used several times, the ones following the first will append data.
--disable-epsv
(FTP) Tell curl to disable the use of the EPSV command when doing passive FTP downloads. Curl will
normally always first attempt to use EPSV before PASV, but with this option, it will not try using EPSV.
If this option is used several times, each occurrence will toggle this on/off.
-D/--dump-header
Write the protocol headers to the specified file.
This option is handy to use when you want to store the cookies that a HTTP site sends to you. The cookies
could then be read in a second curl invoke by using the -b/--cookie option!
When used on FTP, the ftp server response lines are considered being headers and thus are saved there.
If this option is used several times, the last one will be used.
-e/--referer
(HTTP) Sends the Referer Page information to the HTTP server. This can also be set with the -H/-file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
header flag of course. When used with -L/--location you can append ;auto to the referer URL to make curl
automatically set the previous URL when it follows a Location: header. The ;auto string can be used alone,
even if you dont set an initial referer.
If this option is used several times, the last one will be used.
--environment
(RISC OS ONLY) Sets a range of environment variables, using the names the -w option supports, to easier
allow extraction of useful information after having run curl.
If this option is used several times, each occurrence will toggle this on/off.
--egd-file
(HTTPS) Specify the path name to the Entropy Gathering Daemon socket. The socket is used to seed the
random engine for SSL connections. See also the --random-file option.
-E/--cert
(HTTPS) Tells curl to use the specified certificate file when getting a file with HTTPS. The certificate
must be in PEM format. If the optional password isnt specified, it will be queried for on the terminal. Note
that this certificate is the private key and the private certificate concatenated!
If this option is used several times, the last one will be used.
--cacert
(HTTPS) Tells curl to use the specified certificate file to verify the peer. The file may contain multiple CA
certificates. The certificate(s) must be in PEM format.
If this option is used several times, the last one will be used.
--capath
(HTTPS) Tells curl to use the specified certificate directory to verify the peer. The certificates must be in
PEM format, and the directory must have been processed using the c_rehash utility supplied with openssl.
Certificate directories are not supported under Windows (because c_rehash uses symbolink links to create
them). Using --capath can allow curl to make https connections much more efficiently than using --cacert if
the --cacert file contains many CA certificates.
If this option is used several times, the last one will be used.
-f/--fail
(HTTP) Fail silently (no output at all) on server errors. This is mostly done like this to better enable scripts
etc to better deal with failed attempts. In normal cases when a HTTP server fails to deliver a document, it
returns a HTML document stating so (which often also describes why and more). This flag will prevent curl
from outputting that and fail silently instead.
If this option is used twice, the second will again disable silent failure.
-F/--form
(HTTP) This lets curl emulate a filled in form in which a user has pressed the submit button. This causes
curl to POST data using the content-type multipart/form-data according to RFC1867. This enables uploading
of binary files etc. To force the content part to be be a file, prefix the file name with an @ sign. To just get
the content part from a file, prefix the file name with the character <. The difference between @ and < is then
that @ makes a file get attached in the post as a file upload, while the < makes a text field and just get the
contents for that text field from a file.
Example, to send your password file to the server, where password is the name of the form-field to
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
To read the files content from stdin insted of a file, use - where the file name shouldve been. This goes
for both @ and < constructs.
This option can be used multiple times.
-g/--globoff
This option switches off the URL globbing parser. When you set this option, you can specify URLs that
contain the characters {}[] without having them being interpreted by curl itself. Note that these characters are
not normal legal URL contents but they should be encoded according to the URI standard.
-G/--get
When used, this option will make all data specified with -d/--data or --data-binary to be used in a HTTP
GET request instead of the POST request that otherwise would be used. The data will be appended to the
URL with a ? separator. (Option added in curl 7.9)
If used in combination with -I, the POST data will instead be appended to the URL with a HEAD request.
If used multiple times, nothing special happens.
-h/--help
Usage help.
-H/--header
(HTTP) Extra header to use when getting a web page. You may specify any number of extra headers. Note
that if you should add a custom header that has the same name as one of the internal ones curl would use,
your externally set header will be used instead of the internal one. This allows you to make even trickier stuff
than curl would normally do. You should not replace internally set headers without knowing perfectly well
what youre doing. Replacing an internal header with one without content on the right side of the colon will
prevent that header from appearing.
This option can be used multiple times to add/replace/remove multiple headers.
-i/--include
(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date
of the document, HTTP-version and more...
If this option is used twice, the second will again disable header include.
--interface
Perform an operation using a specified interface. You can enter interface name, IP address or host name.
An example could look like:
$ curl --interface eth0:1 http://www.netscape.com/
If this option is used several times, the last one will be used.
-I/--head
(HTTP/FTP) Fetch the HTTP-header only! HTTP-servers feature the command HEAD which this uses to
get nothing but the header of a document. When used on a FTP file, curl displays the file size only.
If this option is used twice, the second will again disable header only.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
-j/--junk-session-cookies
(HTTP) When curl is told to read cookies from a given file, this option will make it discard all session
cookies. This will basicly have the same effect as if a new session is started. Typical browsers always
discard session cookies when theyre closed down. (Added in 7.9.7)
If this option is used several times, each occurrence will toggle this on/off.
--krb4
(FTP) Enable kerberos4 authentication and use. The level must be entered and should be one of clear,
safe, confidential or private. Should you use a level that is not one of these, private will instead be
used.
If this option is used several times, the last one will be used.
-K/--config
Specify which config file to read curl arguments from. The config file is a text file in which command line
arguments can be written which then will be used as if they were written on the actual command line. Options
and their parameters must be specified on the same config file line. If the parameter is to contain white
spaces, the parameter must be inclosed within quotes. If the first column of a config line is a # character,
the rest of the line will be treated as a comment.
Specify the filename as - to make curl read the file from stdin.
Note that to be able to specify a URL in the config file, you need to specify it using the --url option, and
not by simply writing the URL on its own line. So, it could look similar to this:
url = "http://curl.haxx.se/docs/"
This option can be used multiple times.
-l/--list-only
(FTP) When listing an FTP directory, this switch forces a name-only view. Especially useful if you want to
machine-parse the contents of an FTP directory since the normal directory view doesnt use a standard look
or format.
This option causes an FTP NLST command to be sent. Some FTP servers list only files in their response to
NLST; they do not include subdirectories and symbolic links.
If this option is used twice, the second will again disable list only.
-L/--location
(HTTP/HTTPS) If the server reports that the requested page has a different location (indicated with the
header line Location:) this flag will let curl attempt to reattempt the get on the new place. If used together
with -i or -I, headers from all requested pages will be shown. If this flag is used when making a HTTP POST,
curl will automatically switch to GET after the initial POST has been done.
If this option is used twice, the second will again disable location following.
-m/--max-time
Maximum time in seconds that you allow the whole operation to take. This is useful for preventing your
batch jobs from hanging for hours due to slow networks or links going down. This doesnt work fully in
win32 systems. See also the --connect-timeout option.
If this option is used several times, the last one will be used.
-M/--manual
Manual. Display the huge help text.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
-n/--netrc
Makes curl scan the .netrc file in the users home directory for login name and password. This is typically
used for ftp on unix. If used with http, curl will enable user authentication. See netrc(4) or ftp(1) for details
on the file format. Curl will not complain if that file hasnt the right permissions (it should not be world nor
group readable). The environment variable HOME is used to find the home directory.
A quick and very simple example of how to setup a .netrc to allow curl to ftp to the machine
host.domain.com with user name myself and password secret should look similar to:
machine host.domain.com login myself password secret
If this option is used twice, the second will again disable netrc usage.
-N/--no-buffer
Disables the buffering of the output stream. In normal work situations, curl will use a standard buffered
output stream that will have the effect that it will output the data in chunks, not necessarily exactly when the
data arrives. Using this option will disable that buffering.
If this option is used twice, the second will again switch on buffering.
-o/--output
Write output to instead of stdout. If you are using {} or [] to fetch multiple documents, you can use #
followed by a number in the specifier. That variable will be replaced with the current string for the URL
being fetched. Like in:
$ curl http://{one,two}.site.com -o "file_#1.txt"
You may use this option as many times as you have number of URLs.
-O/--remote-name
Write output to a local file named like the remote file we get. (Only the file part of the remote file is used,
the path is cut off.)
You may use this option as many times as you have number of URLs.
-p/--proxytunnel
When an HTTP proxy is used, this option will cause non-HTTP protocols to attempt to tunnel through the
proxy instead of merely using it to do HTTP-like operations. The tunnel approach is made with the HTTP
proxy CONNECT request and requires that the proxy allows direct connect to the remote port number curl
wants to tunnel through to.
If this option is used twice, the second will again disable proxy tunnel.
-P/--ftpport
(FTP) Reverses the initiator/listener roles when connecting with ftp. This switch makes Curl use the PORT
command instead of PASV. In practice, PORT tells the server to connect to the clients specified address and
port, while PASV asks the server for an ip address and port to connect to.
should be one of:
interface
i.e eth0 to specify which interfaces IP address you want to use (Unix only)
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
IP address
i.e 192.168.10.1 to specify exact IP number
host name
i.e my.host.domain to specify machine
(any single-letter string) to make it pick the machines default
If the -P/--ftpport option is used several times, the last one will be used.
-q
If used as the first parameter on the command line, the $HOME/.curlrc file will not be read and used as a
config file.
-Q/--quote
(FTP) Send an arbitrary command to the remote FTP server, by using the QUOTE command of the server.
Not all servers support this command, and the set of QUOTE commands are server specific! Quote
commands are sent BEFORE the transfer is taking place. To make commands take place after a successful
transfer, prefix them with a dash -.
You may specify any amount of commands to be run before and after the transfer. If the server returns
failure for one of the commands, the entire operation will be aborted.
This option can be used multiple times.
--random-file
(HTTPS) Specify the path name to file containing what will be considered as random data. The data is
used to seed the random engine for SSL connections. See also the --edg-file option.
-r/--range
(HTTP/FTP) Retrieve a byte range (i.e a partial document) from a HTTP/1.1 or FTP server. Ranges can be
specified in a number of ways.
0-499
specifies the first 500 bytes
500-999
specifies the second 500 bytes
-500
specifies the last 500 bytes
9500
specifies the bytes from offset 9500 and forward
0-0,-1
specifies the first and last byte only(*)(H)
500-700,600-799
specifies 300 bytes from offset 500(H)
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
100-199,500-599
specifies two separate 100 bytes ranges(*)(H)
(*) = NOTE that this will cause the server to reply with a multipart response!
You should also be aware that many HTTP/1.1 servers do not have this feature enabled, so that when you
attempt to get a range, youll instead get the whole document.
FTP range downloads only support the simple syntax start-stop (optionally with one of the numbers
omitted). It depends on the non-RFC command SIZE.
If this option is used several times, the last one will be used.
-R/--remote-time
When used, this will make libcurl attempt to figure out the timestamp of the remote file, and if that is
available make the local file get that same timestamp.
If this option is used twice, the second time disables this again.
-s/--silent
Silent mode. Dont show progress meter or error messages. Makes Curl mute.
If this option is used twice, the second will again disable mute.
-S/--show-error
When used with -s it makes curl show error message if it fails.
If this option is used twice, the second will again disable show error.
--stderr
Redirect all writes to stderr to the specified file instead. If the file name is a plain -, it is instead written
to stdout. This option has no point when youre using a shell with decent redirecting capabilities.
If this option is used several times, the last one will be used.
-t/--telnet-option
Pass options to the telnet protocol. Supported options are:
TTYPE= Sets the terminal type.
XDISPLOC= Sets the X display location.
NEW_ENV= Sets an environment variable.
-T/--upload-file
This transfers the specified local file to the remote URL. If there is no file part in the specified URL, Curl
will append the local file name. NOTE that you must use a trailing / on the last directory to really prove to
Curl that there is no file name or curl will think that your last directory name is the remote file name to use.
That will most likely cause the upload operation to fail. If this is used on a http(s) server, the PUT command
will be used.
Use the file name - (a single dash) to use stdin instead of a given file.
If this option is used several times, the last one will be used.
--trace
Enables a full trace dump of all incoming and outgoing data, including descriptive information, to the
given output file. Use - as filename to have the output sent to stdout.
If this option is used several times, the last one will be used. (Added in curl 7.9.7)
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
--trace-ascii
Enables a full trace dump of all incoming and outgoing data, including descriptive information, to the
given output file. Use - as filename to have the output sent to stdout.
This is very similar to --trace, but leaves out the hex part and only shows the ASCII part of the dump. It
makes smaller output that might be easier to read for untrained humans.
If this option is used several times, the last one will be used. (Added in curl 7.9.7)
-u/--user
Specify user and password to use when fetching. See README.curl for detailed examples of how to use
this. If no password is specified, curl will ask for it interactively.
If this option is used several times, the last one will be used.
-U/--proxy-user
Specify user and password to use for Proxy authentication. If no password is specified, curl will ask for it
interactively.
If this option is used several times, the last one will be used.
--url
Specify a URL to fetch. This option is mostly handy when you want to specify URL(s) in a config file.
This option may be used any number of times. To control where this URL is written, use the -o or the -O
options.
-v/--verbose
Makes the fetching more verbose/talkative. Mostly usable for debugging. Lines starting with > means
data sent by curl, < means data received by curl that is hidden in normal cases and lines starting with *
means additional info provided by curl.
If this option is used twice, the second will again disable verbose.
-V/--version
Displays the full version of curl, libcurl and other 3rd party libraries linked with the executable.
-w/--write-out
Defines what to display after a completed and successful operation. The format is a string that may contain
plain text mixed with any number of variables. The string can be specified as string, to get read from a
particular file you specify it @filename and to tell curl to read the format from stdin you write @-.
The variables present in the output format will be substituted by the value or text that curl thinks fit, as
described below. All variables are specified like %{variable_name} and to output a normal % you just write
them like %%. You can output a newline by using \n, a carriage return with \r and a tab space with \t.
NOTE: The %-character is a special character in the win32-environment, where all occurrences of % must
be doubled when using this option.
Available variables are at this point:
url_effective
The URL that was fetched last. This is mostly meaningful if youve told curl to follow
location: headers.
http_code
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
The numerical code that was found in the last retrieved HTTP(S) page.
time_total
The total time, in seconds, that the full operation lasted. The time will be displayed with
millisecond resolution.
time_namelookup
The time, in seconds, it took from the start until the name resolving was completed.
time_connect
The time, in seconds, it took from the start until the connect to the remote host (or proxy) was
completed.
time_pretransfer
The time, in seconds, it took from the start until the file transfer is just about to begin. This
includes all pre-transfer commands and negotiations that are specific to the particular protocol(s)
involved.
time_starttransfer
The time, in seconds, it took from the start until the first byte is just about to be transfered.
This includes time_pretransfer and also the time the server needs to calculate the result.
size_download
The total amount of bytes that were downloaded.
size_upload
The total amount of bytes that were uploaded.
size_header
The total amount of bytes of the downloaded headers.
size_request
The total amount of bytes that were sent in the HTTP request.
speed_download
The average download speed that curl measured for the complete download.
speed_upload
The average upload speed that curl measured for the complete upload.
content_type
The Content-Type of the requested document, if there was any. (Added in 7.9.5)
If this option is used several times, the last one will be used.
-x/--proxy
Use specified HTTP proxy. If the port number is not specified, it is assumed at port 1080.
Note that all operations that are performed over a HTTP proxy will transparantly be converted to HTTP. It
means that certain protocol specific operations might not be available. This is not the case if you can tunnel
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
References
RFC 2616 is a must to read if you want in-depth understanding of the HTTP protocol.
RFC 3986 explains the URL syntax.
RFC 2109 defines how cookies are supposed to work.
RFC 1867 defines the HTTP post upload format.
http://curl.haxx.se is the home of the cURL project.
PHP
The PHP manual entry on using CURL starts at http://www.php.net/manual/en/intro.curl.php
The following is the example from the PHP manual:
Once youve compiled PHP with cURL support, you can begin using the cURL functions. The basic idea
behind the cURL functions is that you initialize a cURL session using the curl_init(), then you can set all
your options for the transfer via the curl_setopt(), then you can execute the session with the curl_exec() and
then you finish off your session using the curl_close(). Here is an example that uses the cURL functions to
fetch the example.com homepage into a file:
<?php
$ch = curl_init("http://www.example.com/");
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
PHP functions
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
curl_close
Versions: (PHP 4 >= 4.0.2, PHP 5)
Purpose: curl_close Close a cURL session
Description: void curl_close ( resource $ch )
Closes a cURL session and frees all resources. The cURL handle, ch, is also deleted.
Parameters: ch
A cURL handle returned by curl_init().
Return Values: No value is returned.
curl_copy_handle
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Versions: (PHP 5)
Purpose: curl_copy_handle Copy a cURL handle along with all of its preferences
Description: resource curl_copy_handle ( resource $ch )
Copies a cURL handle keeping the same preferences.
Parameters: ch
A cURL handle returned by curl_init().
Return Values: Returns a new cURL handle.
curl_errno
Versions: (PHP 4 >= 4.0.3, PHP 5)
Purpose: curl_errno Return the last error number
Description: int curl_errno ( resource $ch )
Returns the error number for the last cURL operation.
Parameters: ch
A cURL handle returned by curl_init().
Return Values: Returns the error number or 0 (zero) if no error occurred.
curl_error
Versions: (PHP 4 >= 4.0.3, PHP 5)
Purpose: curl_error Return a string containing the last error for the current session
Description: string curl_error ( resource $ch )
< Returns a clear text error message for the last cURL operation.
Parameters: ch
A cURL handle returned by curl_init().
Return Values: Returns the error message or '' (the empty string) if no error occurred.
curl_exec
Versions: (PHP 4 >= 4.0.2, PHP 5)
Purpose: curl_exec Perform a cURL session
Description: mixed curl_exec ( resource $ch )
Execute the given cURL session.
This function should be called after initializing a cURL session and all the options for the session are set.
Parameters: ch
A cURL handle returned by curl_init().
Return Values: Returns TRUE on success or FALSE on failure. However, if the
CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.
curl_getinfo
Versions: (PHP 4 >= 4.0.4, PHP 5)
Purpose: curl_getinfo Get information regarding a specific transfer
Description: mixed curl_getinfo ( resource $ch [, int $opt = 0 ] )
Gets information about the last transfer.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Parameters: ch
A cURL handle returned by curl_init().
opt
This may be one of the following constants:
CURLINFO_EFFECTIVE_URL - Last effective URL
CURLINFO_HTTP_CODE - Last received HTTP code
CURLINFO_FILETIME - Remote time of the retrieved document, if -1 is returned the time of the
document is unknown
CURLINFO_TOTAL_TIME - Total transaction time in seconds for last transfer
CURLINFO_NAMELOOKUP_TIME - Time in seconds until name resolving was complete
CURLINFO_CONNECT_TIME - Time in seconds it took to establish the connection
CURLINFO_PRETRANSFER_TIME - Time in seconds from start until just before file transfer begins
CURLINFO_STARTTRANSFER_TIME - Time in seconds until the first byte is about to be
transferred
CURLINFO_REDIRECT_COUNT - Number of redirects
CURLINFO_REDIRECT_TIME - Time in seconds of all redirection steps before final transaction was
started
CURLINFO_SIZE_UPLOAD - Total number of bytes uploaded
CURLINFO_SIZE_DOWNLOAD - Total number of bytes downloaded
CURLINFO_SPEED_DOWNLOAD - Average download speed
CURLINFO_SPEED_UPLOAD - Average upload speed
CURLINFO_HEADER_SIZE - Total size of all headers received
CURLINFO_HEADER_OUT - The request string sent. For this to work, add the
CURLINFO_HEADER_OUT option to the handle by calling curl_setopt()
CURLINFO_REQUEST_SIZE - Total size of issued requests, currently only for HTTP requests
CURLINFO_SSL_VERIFYRESULT - Result of SSL certification verification requested by setting
CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD - content-length of download, read from ContentLength: field
CURLINFO_CONTENT_LENGTH_UPLOAD - Specified size of upload
CURLINFO_CONTENT_TYPE - Content-Type: of the requested document, NULL indicates server
did not send valid Content-Type: header
Return Values: If opt is given, returns its value as a string. Otherwise, returns an associative array with
the following elements (which correspond to opt), or FALSE on failure:
"url"
"content_type"
"http_code"
"header_size"
"request_size"
"filetime"
"ssl_verify_result"
"redirect_count"
"total_time"
"namelookup_time"
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
"connect_time"
"pretransfer_time"
"size_upload"
"size_download"
"speed_download"
"speed_upload"
"download_content_length"
"upload_content_length"
"starttransfer_time"
"redirect_time"
"certinfo"
"request_header" (This is only set if the CURLINFO_HEADER_OUT is set by a previous call to
curl_setopt())
Example:
<?php
// Create a curl handle
$ch = curl_init('http://www.yahoo.com/');
// Execute
curl_exec($ch);
// Check if any error occurred
if(!curl_errno($ch))
{
$info = curl_getinfo($ch);
echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' .
$info['url'];
}
// Close handle
curl_close($ch);
?>
Information gathered by this function is kept if the handle is re-used. This means that unless a statistic is
overridden internally by this function, the previous info is returned.
curl_init
Versions: (PHP 4 >= 4.0.2, PHP 5)
Purpose: curl_init Initialize a cURL session
Description: resource curl_init ([ string $url = NULL ] )
Initializes a new session and return a cURL handle for use with the curl_setopt(), curl_exec(), and
curl_close() functions.
Parameters: url If provided, the CURLOPT_URL option will be set to its value. You can manually set
this using the curl_setopt() function.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
Note:
The file protocol is disabled by cURL if open_basedir is set.
Return Values: Returns a cURL handle on success, FALSE on errors.
curl_multi_add_handle
Versions: (PHP 5)
Purpose: curl_multi_add_handle Add a normal cURL handle to a cURL multi handle
Description: int curl_multi_add_handle ( resource $mh , resource $ch )
Adds the ch handle to the multi handle mh
Parameters: mh
A cURL multi handle returned by curl_multi_init().
ch
A cURL handle returned by curl_init().
Return Values: Returns 0 on success, or one of the CURLM_XXX errors code.
curl_multi_close
Versions: (PHP 5)
Purpose: curl_multi_close Close a set of cURL handles
Description: void curl_multi_close ( resource $mh )
Closes a set of cURL handles.
Parameters: mh
A cURL multi handle returned by curl_multi_init().
Return Values: No value is returned.
curl_multi_exec
Versions: (PHP 5)
Purpose: curl_multi_exec Run the sub-connections of the current cURL handle
Description: int curl_multi_exec ( resource $mh , int &$still_running )
Processes each of the handles in the stack. This method can be called whether or not a handle needs to read
or write data.
Parameters: mh
A cURL multi handle returned by curl_multi_init().
still_running
A reference to a flag to tell whether the operations are still running.
Return Values: A cURL code defined in the cURL Predefined Constants.
Note:
This only returns errors regarding the whole multi stack. There might still have occurred problems on
individual transfers even when this function returns CURLM_OK.
curl_multi_getcontent
Versions: (PHP 5)
Purpose: curl_multi_getcontent Return the content of a cURL handle if
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
CURLOPT_RETURNTRANSFER is set
Description: string curl_multi_getcontent ( resource $ch )
If CURLOPT_RETURNTRANSFER is an option that is set for a specific handle, then this function will
return the content of that cURL handle in the form of a string.
Parameters: ch
A cURL handle returned by curl_init().
Return Values: Return the content of a cURL handle if CURLOPT_RETURNTRANSFER is set.
curl_multi_info_read
Versions: (PHP 5)
Purpose: curl_multi_info_read Get information about the current transfers
Description: array curl_multi_info_read ( resource $mh [, int &$msgs_in_queue = NULL ] )
Ask the multi handle if there are any messages or information from the individual transfers. Messages may
include information such as an error code from the transfer or just the fact that a transfer is completed.
Repeated calls to this function will return a new result each time, until a FALSE is returned as a signal that
there is no more to get at this point. The integer pointed to with msgs_in_queue will contain the number of
remaining messages after this function was called.
Warning
The data the returned resource points to will not survive calling curl_multi_remove_handle().
Parameters: mh
A cURL multi handle returned by curl_multi_init(). msgs_in_queue
Number of messages that are still in the queue
Return Values: On success, returns an associative array for the message, FALSE on failure.
Contents of the returned array:
Key:
Value:
msg
The CURLMSG_DONE constant. Other return values are currently not available.
result
One of the CURLE_* constants. If everything is OK, the CURLE_OK will be the result.
handle
Resource of type curl indicates the handle which it concerns.
curl_multi_init
Versions: (PHP 5)
Purpose: curl_multi_init Returns a new cURL multi handle
Description: resource curl_multi_init ( void )
Allows the processing of multiple cURL handles in parallel.
Parameters: This function has no parameters.
Return Values: Returns a cURL multi handle resource on success, FALSE on failure.
curl_multi_remove_handle
Versions: (PHP 5)
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
curl_multi_select
Versions: (PHP 5)
Purpose: curl_multi_select Wait for activity on any curl_multi connection
Description: int curl_multi_select ( resource $mh [, float $timeout = 1.0 ] )
Blocks until there is activity on any of the curl_multi connections.
Parameters: mh
A cURL multi handle returned by curl_multi_init().
timeout
Time, in seconds, to wait for a response.
Return Values: On success, returns the number of descriptors contained in the descriptor sets. On failure,
this function will return -1 on a select failure or timeout (from the underlying select system call).
curl_setopt_array
Versions: (PHP 5 >= 5.1.3)
Purpose: curl_setopt_array Set multiple options for a cURL transfer
Description: bool curl_setopt_array ( resource $ch , array $options )
Sets multiple options for a cURL session. This function is useful for setting a large amount of cURL
options without repetitively calling curl_setopt().
Parameters: ch
A cURL handle returned by curl_init().
options
An array specifying which options to set and their values. The keys should be valid curl_setopt() constants
or their integer equivalents.
Return Values: Returns TRUE if all options were successfully set. If an option could not be successfully
set, FALSE is immediately returned, ignoring any future options in the options array.
Notes: As with curl_setopt(), passing an array to CURLOPT_POST will encode the data as
multipart/form-data, while passing a URL-encoded string will encode the data as application/x-wwwform-urlencoded.
curl_setopt
Versions: (PHP 4 >= 4.0.2, PHP 5)
Purpose: curl_setopt Set an option for a cURL transfer
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
3/5/13 11:00 AM
TRUE to follow any "Location: " header that the server sends as part of the HTTP header (note this is
recursive, PHP will follow as many "Location: " headers that it is sent, unless CURLOPT_MAXREDIRS is
set).
CURLOPT_FORBID_REUSE
TRUE to force the connection to explicitly close when it has finished processing, and not be pooled for
reuse.
CURLOPT_FRESH_CONNECT
TRUE to force the use of a new connection instead of a cached one.
CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and
LPRT and use PORT only.
CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to
disable EPSV.
CURLOPT_FTP_CREATE_MISSING_DIRS
TRUE to create missing directories when an FTP operation encounters a path that currently doesn't exist.
CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it.
CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.
CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory.
CURLOPT_HEADER
TRUE to include the header in the output.
CURLINFO_HEADER_OUT
TRUE to track the handle's request string.
Available since PHP 5.1.3. The CURLINFO_ prefix is intentional.
CURLOPT_HTTPGET
TRUE to reset the HTTP request method to GET. Since GET is the default, this is only necessary if the
request method has been changed.
CURLOPT_HTTPPROXYTUNNEL
TRUE to tunnel through a given HTTP proxy.
CURLOPT_MUTE
TRUE to be completely silent with regards to the cURL functions.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
3/5/13 11:00 AM
3/5/13 11:00 AM
CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM.
CURLAUTH_ANYSAFE is an alias for CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE |
CURLAUTH_NTLM.
CURLOPT_INFILESIZE
The expected size, in bytes, of the file when uploading a file to a remote site. Note that using this option
will not stop libcurl from sending more data, as exactly what is sent depends on
CURLOPT_READFUNCTION.
CURLOPT_LOW_SPEED_LIMIT
The transfer speed, in bytes per second, that the transfer should be below during the count of
CURLOPT_LOW_SPEED_TIME seconds before PHP considers the transfer too slow and aborts.
CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer speed should be below CURLOPT_LOW_SPEED_LIMIT before PHP
considers the transfer too slow and aborts.
CURLOPT_MAXCONNECTS
The maximum amount of persistent connections that are allowed. When the limit is reached,
CURLOPT_CLOSEPOLICY is used to determine which connection to close.
CURLOPT_MAXREDIRS
The maximum amount of HTTP redirections to follow. Use this option alongside
CURLOPT_FOLLOWLOCATION.
CURLOPT_PORT
An alternative port number to connect to.
CURLOPT_PROTOCOLS
Bitmask of CURLPROTO_* values. If used, this bitmask limits what protocols libcurl may use in the
transfer. This allows you to have a libcurl built to support a wide range of protocols but still limit specific
transfers to only be allowed to use a subset of them. By default libcurl will accept all protocols it supports.
See also CURLOPT_REDIR_PROTOCOLS.
Valid protocol options are: CURLPROTO_HTTP, CURLPROTO_HTTPS, CURLPROTO_FTP,
CURLPROTO_FTPS, CURLPROTO_SCP, CURLPROTO_SFTP, CURLPROTO_TELNET,
CURLPROTO_LDAP, CURLPROTO_LDAPS, CURLPROTO_DICT, CURLPROTO_FILE,
CURLPROTO_TFTP, CURLPROTO_ALL
Added in cURL 7.19.4.
CURLOPT_PROXYAUTH
The HTTP authentication method(s) to use for the proxy connection. Use the same bitmasks as described
in CURLOPT_HTTPAUTH. For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM
are currently supported.
Added in cURL 7.10.7.
CURLOPT_PROXYPORT
The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:00 AM
CURLOPT_PROXYTYPE
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.
Added in cURL 7.10.
CURLOPT_REDIR_PROTOCOLS
Bitmask of CURLPROTO_* values. If used, this bitmask limits what protocols libcurl may use in a
transfer that it follows to in a redirect when CURLOPT_FOLLOWLOCATION is enabled. This allows you
to limit specific transfers to only be allowed to use a subset of protocols in redirections. By default libcurl
will allow all protocols except for FILE and SCP. This is a difference compared to pre-7.19.4 versions which
unconditionally would follow to all protocols supported. See also CURLOPT_PROTOCOLS for protocol
constant values.
Added in cURL 7.19.4.
CURLOPT_RESUME_FROM
The offset, in bytes, to resume a transfer from.
CURLOPT_SSL_VERIFYHOST
1 to check the existence of a common name in the SSL peer certificate. 2 to check the existence of a
common name and also verify that it matches the hostname provided. In production environments the value
of this option should be kept at
2 (default value).
Support for value 1 removed in cURL 7.28.1
CURLOPT_SSLVERSION
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases
this must be set manually.
CURLOPT_TIMECONDITION
How CURLOPT_TIMEVALUE is treated. Use CURL_TIMECOND_IFMODSINCE to return the page
only if it has been modified since the time specified in CURLOPT_TIMEVALUE. If it hasn't been modified,
a "304 Not Modified" header will be returned assuming CURLOPT_HEADER is TRUE. Use
CURL_TIMECOND_IFUNMODSINCE for the reverse effect. CURL_TIMECOND_IFMODSINCE is the
default.
CURLOPT_TIMEOUT
The maximum number of seconds to allow cURL functions to execute.
CURLOPT_TIMEOUT_MS
The maximum number of milliseconds to allow cURL functions to execute. If libcurl is built to use the
standard system name resolver, that portion of the connect will still use full-second resolution for timeouts
with a minimum timeout allowed of one second.
Added in cURL 7.16.2. Available since PHP 5.2.3.
CURLOPT_TIMEVALUE
The time in seconds since January 1st, 1970. The time will be used by CURLOPT_TIMECONDITION. By
default, CURL_TIMECOND_IFMODSINCE is used.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
CURLOPT_MAX_RECV_SPEED_LARGE
If a download exceeds this speed (counted in bytes per second) on cumulative average during the transfer,
the transfer will pause to keep the average rate less than or equal to the parameter value. Defaults to unlimited
speed.
Added in cURL 7.15.5. Available since PHP 5.4.0.
CURLOPT_MAX_SEND_SPEED_LARGE
If an upload exceeds this speed (counted in bytes per second) on cumulative average during the transfer,
the transfer will pause to keep the average rate less than or equal to the parameter value. Defaults to unlimited
speed.
Added in cURL 7.15.5. Available since PHP 5.4.0.
CURLOPT_SSH_AUTH_TYPES
A bitmask consisting of one or more of CURLSSH_AUTH_PUBLICKEY,
CURLSSH_AUTH_PASSWORD, CURLSSH_AUTH_HOST, CURLSSH_AUTH_KEYBOARD. Set to
CURLSSH_AUTH_ANY to let libcurl pick one.
Added in cURL 7.16.1.
value should be a string for the following values of the option parameter:
Option
Set value to
Notes
CURLOPT_CAINFO
The name of a file holding one or more certificates to verify the peer with. This only makes sense when
used in combination with CURLOPT_SSL_VERIFYPEER.
Requires absolute path.
CURLOPT_CAPATH
A directory that holds multiple CA certificates. Use this option alongside
CURLOPT_SSL_VERIFYPEER.
CURLOPT_COOKIE
The contents of the "Cookie: " header to be used in the HTTP request. Note that multiple cookies are
separated with a semicolon followed by a space (e.g., "fruit=apple; colour=red")
CURLOPT_COOKIEFILE The name of the file containing the cookie data. The cookie file can be in
Netscape format, or just plain HTTP-style headers dumped into a file. If the name is an empty string, no
cookies are loaded, but cookie handling is still enabled.
CURLOPT_COOKIEJAR
The name of a file to save all internal cookies to when the handle is closed, e.g. after a call to curl_close.
CURLOPT_CUSTOMREQUEST
A custom request method to use instead of "GET" or "HEAD" when doing a HTTP request. This is
useful for doing "DELETE" or other, more obscure HTTP requests. Valid values are things like "GET",
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
"POST", "CONNECT" and so on; i.e. Do not enter a whole HTTP request line here. For instance, entering
"GET /index.html HTTP/1.0\r\n\r\n" would be incorrect.
Note:
Don't do this without making sure the server supports the custom request method first.
CURLOPT_EGDSOCKET
Like CURLOPT_RANDOM_FILE, except a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODING
The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported
encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all
supported encoding types is sent.
Added in cURL 7.10.
CURLOPT_FTPPORT
The value which will be used to get the IP address to use for the FTP "POST" instruction. The "POST"
instruction tells the remote server to connect to our specified IP address. The string may be a plain IP address,
a hostname, a network interface name (under Unix), or just a plain '-' to use the systems default IP address.
CURLOPT_INTERFACE
The name of the outgoing network interface to use. This can be an interface name, an IP address or a host
name.
CURLOPT_KEYPASSWD
The password required to use the CURLOPT_SSLKEY or CURLOPT_SSH_PRIVATE_KEYFILE private
key.
Added in cURL 7.16.1.
CURLOPT_KRB4LEVEL
The KRB4 (Kerberos 4) security level. Any of the following values (in order from least to most powerful)
are valid: "clear", "safe", "confidential", "private".. If the string does not match one of these, "private" is
used. Setting this option to NULL will disable KRB4 security. Currently KRB4 security only works with FTP
transactions.
CURLOPT_POSTFIELDS
The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the
full path. The filetype can be explicitly specified by following the filename with the type in the format
';type=mimetype'. This parameter can either be passed as a urlencoded string like 'para1=val12=val2&...' or
as an array with the field name as key and field data as value. If value is an array, the Content-Type header
will be set to multipart/form-data. As of PHP 5.2.0, value must be an array if files are passed to this option
with the @ prefix.
CURLOPT_PROXY
The HTTP proxy to tunnel requests through.
CURLOPT_PROXYUSERPWD
A username and password formatted as "[username]:[password]" to use for the connection to the proxy.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
CURLOPT_RANDOM_FILE
A filename to be used to seed the random number generator for SSL.
CURLOPT_RANGE
Range(s) of data to retrieve in the format "X-Y" where X or Y are optional. HTTP transfers also support
several intervals, separated with commas in the format "X-Y,N-M".
CURLOPT_REFERER
The contents of the "Referer: " header to be used in a HTTP request.
CURLOPT_SSH_HOST_PUBLIC_KEY_MD5
A string containing 32 hexadecimal digits. The string should be the MD5 checksum of the remote host's
public key, and libcurl will reject the connection to the host unless the md5sums match. This option is only
for SCP and SFTP transfers.
Added in cURL 7.17.1.
CURLOPT_SSH_PUBLIC_KEYFILE
The file name for your public key. If not used, libcurl defaults to $HOME/.ssh/id_dsa.pub if the HOME
environment variable is set, and just "id_dsa.pub" in the current directory if HOME is not set.
Added in cURL 7.16.1.
CURLOPT_SSH_PRIVATE_KEYFILE
The file name for your private key. If not used, libcurl defaults to $HOME/.ssh/id_dsa if the HOME
environment variable is set, and just "id_dsa" in the current directory if HOME is not set. If the file is
password-protected, set the password with CURLOPT_KEYPASSWD.
Added in cURL 7.16.1.
CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT
The name of a file containing a PEM formatted certificate.
CURLOPT_SSLCERTPASSWD
The password required to use the CURLOPT_SSLCERT certificate.
CURLOPT_SSLCERTTYPE
The format of the certificate. Supported formats are "PEM" (default), "DER", and "ENG".
Added in cURL 7.9.3.
CURLOPT_SSLENGINE
The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.
CURLOPT_SSLENGINE_DEFAULT
The identifier for the crypto engine used for asymmetric crypto operations.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
CURLOPT_SSLKEY
The name of a file containing a private SSL key.
CURLOPT_SSLKEYPASSWD
The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.
Note:
Since this option contains a sensitive password, remember to keep the PHP script it is contained within
safe.
CURLOPT_SSLKEYTYPE
The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are "PEM"
(default), "DER", and "ENG".
CURLOPT_URL
The URL to fetch. This can also be set when initializing a session with curl_init().
CURLOPT_USERAGENT
The contents of the "User-Agent: " header to be used in a HTTP request.
CURLOPT_USERPWD
A username and password formatted as "[username]:[password]" to use for the connection.
value should be an array for the following values of the option parameter:
Option
Set value to
Notes
CURLOPT_HTTP200ALIASES
An array of HTTP 200 responses that will be treated as valid responses and not as errors.
Added in cURL 7.10.3.
CURLOPT_HTTPHEADER
An array of HTTP header fields to set, in the format array('Content-type: text/plain', 'Content-length: 100')
CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been performed.
CURLOPT_QUOTE
An array of FTP commands to execute on the server prior to the FTP request.
value should be a stream resource (using fopen(), for example) for the following values of the option
parameter:
Option
Set value to
CURLOPT_FILE
The file that the transfer should be written to. The default is STDOUT (the browser window).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
CURLOPT_INFILE
The file that the transfer should be read from when uploading.
CURLOPT_STDERR
An alternative location to output errors to instead of STDERR. CURLOPT_WRITEHEADER
The file that the header part of the transfer is written to.
value should be a string that is the name of a valid callback function for the following values of the option
parameter:
Option
Set value to
CURLOPT_HEADERFUNCTION
The name of a callback function where the callback function takes two parameters. The first is the cURL
resource, the second is a string with the header data to be written. The header data must be written when
using this callback function. Return the number of bytes written.
CURLOPT_PASSWDFUNCTION
The name of a callback function where the callback function takes three parameters. The first is the cURL
resource, the second is a string containing a password prompt, and the third is the maximum password length.
Return the string containing the password.
CURLOPT_PROGRESSFUNCTION
The name of a callback function where the callback function takes three parameters. The first is the cURL
resource, the second is a file-descriptor resource, and the third is length. Return the string containing the data.
CURLOPT_READFUNCTION
The name of a callback function where the callback function takes three parameters. The first is the cURL
resource, the second is a stream resource provided to cURL through the option CURLOPT_INFILE, and the
third is the maximum amount of data to be read. The callback function must return a string with a length
equal or smaller than the amount of data requested, typically by reading it from the passed stream resource. It
should return an empty string to signal EOF.
CURLOPT_WRITEFUNCTION
The name of a callback function where the callback function takes two parameters. The first is the cURL
resource, and the second is a string with the data to be written. The data must be saved by using this callback
function. It must return the exact number of bytes written or the transfer will be aborted with an error.
Return Values: Returns TRUE on success or FALSE on failure.
Notes: Passing an array to CURLOPT_POSTFIELDS will encode the data as multipart/form-data, while
passing a URL-encoded string will encode the data as application/x-www-form-urlencoded.
curl_version
Versions: (PHP 4 >= 4.0.2, PHP 5)
Purpose: curl_version Gets cURL version information
Description: array curl_version ([ int $age = CURLVERSION_NOW ] )
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
sysstat
chapter 62
summary
This chapter looks at sysstat, a server package.
package
sysstat
reports CPU statistics and input/output statistics for devices, partitions and network filesystems.
mpstat
pidstar
reports statistics for Linux tasks (processes) : I/O, CPU, memory, etc.
collects, reports and saves system activity information (CPU, memory, disks, interrupts, network
interfaces, TTY, kernel tables,etc.)
sar
sadc
collects and stores binary data in the system activity daily data file. It is a front end to sadc designed to
be run from cron.
sa1
sa2
writes a summarized daily activity report. It is a front end to sar designed to be run from cron.
sadf displays data collected by sar in multiple formats (CSV, XML, etc.) This is useful to load
performance data into a database, or import them in a spreadsheet to make graphs.
nfsiostat
cifsiostat
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
at
chapter 63
summary
This chapter looks at at, a UNIX (and Linux) command.
at
example
Type at midnight, followed by ENTER or RETURN.
$ at midnight
You may see the at> prompt (on Mac OS X, there is no prompt).
Type a single command, followed by ENTER or RETURN.
$ who > who.out
You will see a job number and the time it will run. This job will run all of the commands you entered.
removing an at job
Type atrm (for at remove), followed by the job number to remove an existing at job.
$ atrm 1
timing
You can name a specific time using the YYMMDDhhmm.SS format.
You can also specify noon, midnight, or teatime (4 p.m.).
If the time has already passed, the next day is assumed.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
3/5/13 11:01 AM
back ups
chapter 64
summary
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
tools
Your basic tools for back ups are tar, various compression schemes, and cron scripts.
tar stands for Tape ARchive, from back in the days when back ups were put on those large tape machines
you see in the old James Bond movies.
cron
is a system for scheduling jobs, including UNIX shell scripts, to run at specific times.
rule of thumb
People are always asking how often they should do their backups, looking for a regualr time period.
The rule of thumb on back-ups is to back up your data before you reach the point where you have too
much work to do to replace the data.
If you start typing an email and the system crashes, you are annoyed, but you can type the email over
again. On the other hand, if you lose all of your emails, you have a problem.
Hence, the simple rule of thumb to back up as soon as you are about to have too much data to create over
again.
Notice that this answer wasnt in the form of a specific time periood (such as daily or weekly).
The reality of any large scale system is that you will be using the cruder method of specific times, such as
daily, weekly, and monthly back ups.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
tar
chapter 65
summary
This chapter looks at tar, a UNIX (and Linux) command.
Use tar for making backups and for retrieving open source software from the internet.
This command is used to archive directories and extract directories from archives. The tar archives can be
used for back-up storage and for transfer to other machines.
tar
tar
Warning: tar does not work the exact same on all versions of UNIX and Linux. Test and confirm local
variations before relying on scripts moved from one platform to another.
create
Creating a new tar archive:
$ tar cvf archivename.tar dirname/
The c indicates create a new archive, the v indicates verbosely list file names, and the f indicates that the
following is the archive file name. The v option may be left out to avoid a long list.
Creating a new gzipped tar archive:
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
The z indicates the use of gzip compression. The file extensions .tgz and .tar.gz mean the same thing and
are interchangeable.
Creating a new bzip2 tar archive:
$ tar cvzj archivename.tar.bz2 dirname/
$ tar cvzj archivename.tbz dirname/
The j indicates the use of bzip2 compression. The file extensions .tbz and .tar.bz2 mean the same thing and
are interchangeable.
Bzip2 takes longer to compress and decompress than gzip, but also produces a smaller compressed file.
extract
Extracting from an existing tar archive:
$ tar xvf archivename.tar
The x indicates extract files from an archive, the v indicates verbosely list file names, and the f indicates
that the following is the archive file name. The v option may be left out to avoid a long list.
Extracting from a gzipped tar archive:
$ tar xvfz archivename.tgz
$ tar xvfz archivename.tar.gz
tarpipe
It is possible to tar a set of directories (and their files and them pipe the tar to an extraction at a new
location, making an exact copy of an entire set of directories (including special files) in a new location:
$ tar -c "$srcdir" | tar -C "$destdir" -xv
tarbomb
A malicious tar archive could overwrite existing files. The use of absolute paths can spread files anywhere,
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
including overwriting existing files (even system files) anywhere. The use of parent directory references can
also be used to overwrite existing files.
One can examine the tar archive without actually extracting from it.
The bsdtar program (the default tar on Mac OS X v10.6 or later) refuses to follow either absolute path or
parent-directory references.
viewing
Viewing an existing tar archive (without extracting) with any of the following:
$
$
$
$
tar
tar
tar
tar
tvf archivename.tar
-tf archivename.tar
tf archivename.tar
--list --file=archivename.tar
Viewing an existing gzipped tar archive (without extracting) with any of the following:
$ tar tvfz archivename.tar.gz
$ tar tvfz archivename.tgz
Viewing an existing bzipped tar archive (without extracting) with any of the following:
$ tar tvfj archivename.tar.bz2
$ tar tvfj archivename.tbz
less
You can pipe the output of a tar file to the less command.
You can directly use the less command to open a tar archive. Less will show you the names of the files, the
file sizes, the file permissions, the owner, and the group (the equivalent of ls -l).
$ less archivename.tar
You can extract a specific compressed file from a large tar archive.
$ tar xvf archivefile.tar.gz /complete/path/to/file
$ tar xvf archivefile.tar.bz2 /complete/path/to/file
3/5/13 11:01 AM
You can extract a specific single directory from a large tar archive.
$ tar xvf archivefile.tar /complete/path/to/dir/
You can extract a specific compressed directory from a large tar archive.
$ tar xvf archivefile.tar.gz /complete/path/to/dir/
$ tar xvf archivefile.tar.bz2 /complete/path/to/dir/
You can extract specific compressed directories from a large tar archive.
$ tar xvf archivefile.tar.gz /complete/path/to/dir1/ /complete/path/to/dir2/
$ tar xvf archivefile.tar.bz2 /complete/path/to/dir1/ /complete/path/to/dir2/
This does not work for adding a file or directory to a compressed archive. You will get the following error
message instead:
tar: Cannot update compressed archives
verifying files
You can verify a new archive file while creating is by using the -W option:
$ tar cvfW archivefile.tar dir/
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
If you see something similar to the following output, something has changed:
Verify 1/filename
1/filename: Mod time differs
1/filename: Size differs
If you just see the Verify line by itself, the file or directory is fine:
Verify 1/filename
For bzip2 compressed files, find the difference between the bzip2 archive and the file system:
$ tar dfj 1/filename.tbz
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
touch
chapter 66
summary
This chapter looks at touch, a UNIX (and Linux) command.
Use touch to change the date stamp on a file.
The most common use of touch is to force make to recompile a particular file (or group of files).
how to use
The simple form of touch changes a named files timestamp to the current date and time:
$ touch filename
multiple files
Use touch to change all of the files in a directory:
$ touch *
specific time
You can use touch to set a specific time by using the -t option. The following command sets a file to the
Solstice at the end of the Mayan calendar (11:12 a.m. December 21, 2012):
$ touch -t201212211112.00 filename
The format is YYYYMMDDhhmm.ss, YYYY = four digit year, MM - two digit month, DD = two digit day, hh
= two digit hour (24 hour clock), mm = two digit month, and ss = two digit second.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
find
chapter 67
summary
This chapter looks at find, a UNIX (and Linux) command.
find
find a file
You can use find to quickly find a specific file. The -x option (this is -xdev on older systems) limits the
search to only those directories on the existing filesystem.
$ find / -name filename -type d -x
Note that you may want to run this command from root or superuser.
The locate command is more recent.
gotchas
Do not use the output of find in a BASH for loop.
$ for i in $(find *.mp3); do # Wrong!
$
command $i # Wrong!
$ done # Wrong!
$ for i in $(find *.mp3) # Wrong!
$ for i in `find *.mp3` # Wrong!
If any file name has spaces in it, then it will be word split. So, the MP3 for Mumford & Sonss The Cave
(number two song on their Sigh No More album) might be 02 The Cave. In that case, your command
would run on the files 02, The, and Cave, rather than 02 The Cave. Additional errors likely to
follow. Listen to the song The Cave for free at http://www.thissideofsanity.com/musicbox/musicbox.php?
mastersong=48 .
Double quote wont work either because that will cause the entire output of the find command to be
treated as a single item. Your loop will run once on all of the file names conactenated together.
$ for i in "$(ls *.mp3)"; # Wrong!
The solution is to run your loop without even using find, relying on BASHs filename expansion. Dont
forget to check for the possibility that there are no qualifying files in the current directory.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
sed
chapter 68
summary
This chapter looks at sed, a UNIX (and Linux) command.
sed
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
awk
chapter 69
summary
This chapter looks at awk, a UNIX (and Linux) command.
is a programming language intended to serve a place between simple shell scripts and full
programming languages. It is Turing complete.
awk
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
screencapture
chapter 70
summary
This chapter looks at screencaptures, a Mac OS X-only command.
screencapture
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
changing defaults
The following methods use Terminal to change the default file format and location where the screenshot is
saved from the graphic user interface.
In Mac S X 10.4 (Tiger) or more recent, the default screencapture format can be changed in Terminal by
using the defaults command. In Mac S X 10.4 (Tiger), the new default does not take effect until you logout
and log back in(from the entire computer, not just from Terminal a full restart will also work) unless you
also use the killall command.
$ defaults write com.apple.screencapture type ImageFormat
$ killall SystemUIServer
The FileFormat can be png (Portable Network Graphic), pdf (Portable Document Format), tiff (Tagged
Image File Format), jpg or jpeg (Joint Photographic Experts Group), pict (Macintosh QuickDraw Picture),
bmp (Microsoft Windows Bitmap), gif (Graphics Interchange Format), psd (Adobe Photoshop Document),
sgi (Silicon Graphics File Format), or tga (Truevision Targe File Format).
JPGs are saved at quality 60%.
To change the default location where the screenshot file is saved (the default is Desktop), use the following
Terminal command (where pathname is the full path to a directory.:
$ defaults write com.apple.screencapture location PathName
$ killall SystemUIServer
The normal default location would be reset with the following command (where USername is the current
accounts user name.
$ defaults write com.apple.screencapture location /Users/UserName/Desktop
$ killall SystemUIServer
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
The basic use, which takes an immediate screenshot in the default format and stores it with the designated
filename (in this case Picture1) in the users home directory (not the desktop).
$ screencapture Picture1
Force the screenshot to go to the clipboard (the equivalent of the Command-Shift-Control- choices).
$ screencapture -c [files]
Capture the cursor as well as the screen. This applies only in non-interactive modes (such as a script).
$ screencapture -C [files]
Capture the screenshot interactively by either selection or window (the equivalent of Command-Shift-4).
Use the CONTROL key to cause the screenshot to go to the clipboard. Use the SPACE key to toggle between
mouse selection and window selection modes. Use the ESCAPE key to cancel the interactive screen shot.
$ screencapture -i [file]
Use the -m option to only capture the main monitor. This does not work if the -i option is also set.
$ screencapture -m [file]
3/5/13 11:01 AM
$ screencapture -M [files]
Use the -o option in window capture mode to only capture the window and to not capture the shadow of
the window.
$ screencapture - o [file]
After savng the screenshot, open the screen capture output in Preview.
$ screencapture -P [files]
Use the -S option in window capture mode to capture the screen rather than the window.
$ screencapture -S [files]
Set the format with the -t option. The Format can be png (Portable Network Graphic), pdf (Portable
Document Format), tiff (Tagged Image File Format), jpg or jpeg (Joint Photographic Experts Group), pict
(Macintosh QuickDraw Picture), bmp (Microsoft Windows Bitmap), gif (Graphics Interchange Format), psd
(Adobe Photoshop Document), sgi (Silicon Graphics File Format), or tga (Truevision Targe File Format)
$ screencapture -tFormat [files]
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
signals
chapter 71
summary
This chapter looks at UNIX and Linux signals.
The first chart shows the signals by name, with their explanation and their numbers by operating system.
The second chart shows the signals by number, with the corresponding name by operating system.
meaning
Used by abort
SIGALRM
14
14
14
terminate
process
SIGBUS
10
10
create core
image
36
17
20
18
discard signal
18
19
25
discard signal
create core
image
SIGFPE
create core
image
SIGFREEZE
SIGHUP
Hangup (POSIX)
34
1
terminate
process
SIGILL
create core
image
SIGINFO
29
terminate
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
process
SIGINT
terminate
process
SIGIO
29
23
22
discard signal
SIGIOT
6
create core
image
now called
SIGABRT
SIGKILL
Kill (POSIX)
(cant be caught or ignored)
terminate
process
SIGLOST
Resource lost
37
SIGLWP
33
SIGPIPE
13
13
13
terminate
process
SIGPOLL
SIGPROF
22
27
27
29
terminate
process
SIGPWR
30
SIGQUIT
19
3
create core
image
SIGRTMAX
SIGRTMIN
SIGSEGV
11
SIGSTKFLT
Stack fault
16
SIGSTOP
19
SIGSYS
SIGTERM
45
38
11
17
23
stop process
11
create core
image
12
12
create core
image
15
15
15
terminate
process
SIGTHAW
SIGTRAP
35
5
create core
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
image
SIGTSTP
SIGTTIN
SIGTTOU
SIGURG
20
21
22
23
18
24
stop process
21
26
stop process
22
27
stop process
16
21
discard signal
SIGUSR1
10
30
16
terminate
process
SIGUSR2
12
31
17
terminate
process
26
26
28
terminate
process
32
28
28
20
discard signal
SIGXCPU
24
24
30
terminate
process
SIGXFSZ
25
25
31
terminate
process
Linux
SIGHUP
Mac OS X
SIGHUP
Solaris
SIGHUP
SIGINT
SIGINT
SIGINT
3
4
SIGQUIT
SIGILL
SIGQUIT
SIGILL
SIGQUIT
SIGILL
5
6
SIGTRAP
SIGIOT
SIGTRAP
SIGABRT
SIGTRAP
SIGABRT
SIGBUS
SIGEMT
SIGEMT
8
9
SIGFPE
SIGKILL
SIGFPE
SIGKILL
SIGFPE
SIGKILL
10
SIGUSR1
SIGBUS
SIGBUS
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
11
12
SIGSEGV
SIGUSR2
SIGSEGV
SIGSYS
SIGSEGV
SIGSYS
13
14
SIGPIPE
SIGALRM
SIGPIPE
SIGALRM
SIGPIPE
SIGALRM
15
SIGTERM
SIGTERM
SIGTERM
16
17
SIGSTKFLT
SIGCHLD
SIGURG
SIGSTOP
SIGUSR1
SIGUSR2
18
19
SIGCONT
SIGSTOP
SIGTSTP
SIGCONT
SIGCHLD
SIGPWR
20
SIGTSTP
SIGCHLD
SIGWINCH
21
22
SIGTTIN
SIGTTOU
SIGTTIN
SIGTTOU
SIGURG
SIGIO
SIGPOLL
23
SIGURG
SIGIO
SIGSTOP
24
25
SIGXCPU
SIGXFSZ
SIGXCPU
SIGXFSZ
SIGTSTP
SIGCONT
26
27
SIGVTALRM SIGVTALRM
SIGPROF
SIGPROF
28
SIGWINCH
29
30
SIGIO
SIGPWR
31
32
SIGTTIN
SIGTTOU
SIGWINCH SIGVTALRM
SIGINFO
SIGUSR1
SIGPROF
SIGXCPU
SIGUSR2
SIGXFSZ
SIGWAITING
33
SIGLWP
34
35
SIGFREEZE
SIGTHAW
36
37
SIGCANCEL
SIGLOST
38
SIGRTMIN
45
SIGRTMAX
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
kernel modules
chapter 72
summary
This chapter looks at UNIX and Linux kernel modules.
Loadable Kernel Modules (LKM) go by many different names, including kernel loadable module (kld) in
FreeBSD and kernel extension (kext) in Mac OS X, as well as Kernel Loadable Modules (KLM) or Kernel
Modules (KMOD).
purpose
Loadable kernel modules allow the flexibility to add additional functionality to an operating system
without requiring recompiling and reloading the entire operating system. This same flexibility can be used to
choose between various options at start-up time.
Linux
Loadable Kernel Modules (LKMs) are loaded (and unloaded) by the modprobe command. Linux LKMs are
located in /lib/modules and have the file extension .ko (for kernel object). Prior to Linux version 2.6 they
were identified by the .o file extension.
Linux views LKMs as derived works of the kernel and allow symbols to be marked as only available to
GNU General Public License (GPL) modules. Loading a proprietary or non-GPL-compatible LKM will set a
taint flag in the running module.
LKMs run as part of the kernel, so they can corrupt kernel data structures and produce bugs.
FreeBSD
Kernel modules for FreeBSD are stored within /boot/kernel/ for modules distributed with the OS, or
usually /boot/modules/ for modules installed from FreeBSD ports or FreeBSD packages, or for proprietary
or otherwise binary-only modules. FreeBSD kernel modules usually have the extension .ko. Once the
machine has booted, they may be loaded with the kldload command, unloaded with kldunload, and listed
with kldstat. Modules can also be loaded from the loader before the kernel starts, either automatically
(through /boot/loader.conf) or by hand.
Mac OS X
Some loadable kernel modules in OS X can be loaded automatically. Loadable kernel modules can also be
loaded by the kextload command. They can be listed by the kextstat command. Loadable kernel modules
are located in application bundles with the extension .kext. Modules supplied with the operating system are
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
stored in the /System/Library/Extensions directory; modules supplied by third parties are in various other
directories.
binary compatibility
Linux does not provide a stable API or ABI for kernel modules. This means that there are differences in
internal structure and function between different kernel versions, which can cause compatibility problems. In
an attempt to combat those problems, symbol versioning data is placed within the .modinfo section of
loadable ELF modules. This versioning information can be compared with that of the running kernel before
loading a module; if the versions are incompatible, the module will not be loaded.
Other operating systems, such as Solaris, FreeBSD, Mac OS X, and Windows keep the kernel API and
ABI relatively stable, thus avoiding this problem. For example, FreeBSD kernel modules compiled against
kernel version 6.0 will work without recompilation on any other FreeBSD 6.x version, e.g. 6.4. However,
they are not compatible with other major versions and must be recompiled for use with FreeBSD 7.x, as API
and ABI compatibility is maintained only within a branch.
security
While loadable kernel modules are a convenient method of modifying the running kernel, this can be
abused by attackers on a compromised system to prevent detection of their processes or files, allowing them
to maintain control over the system. Many rootkits make use of LKMs in this way. Note that on most
operating systems modules do not help privilege elevation in any way, as elevated privilege is required to
load a LKM; they merely make it easier for the attacker to hide the break-in.
Linux allows disabling module loading via /proc/sys/kernel/modules_disabled. A initramfs system
may load specific modules needed for a machine at boot and then disable module loading. This makes the
security very similar to a monolithic kernel. If an attacker can change the initramfs, they can change the
kernel binary.
On Mac OS X, a loadable kernel module in a kernel extension bundle can be loaded by non-root users if
the OSBundleAllowUserLoad property is set to True in the bundles property list. However, if any of the files
in the bundle, including the executable code file, are not owned by root and group wheel, or are writable by
the group or other, the attempt to load the kernel loadable module will fail.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
LAMP
chapter 73
summary
This chapter looks at LAMP, which is the combination of Linux-Apache-MySQL-PHP (or Perl or Python).
These are all open source programs that provide the ability to have a working modern production web
server.
MAMP
The MAMP project achieves the same capabilities using Mac OS X instead of Linux. The MAMP package
can be downloaded and used for free without interfering with any similar built-in Mac OS X services. MAMP
is intended for creating a local duplicate of your production server environment so that you can freely test
new software before deploying it to your production servers.
MAMP can be found at http://www.mamp.info/en/index.html.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
gcc
The vast majority of open source software is written in the C programming language. The GNU foundation
C compiler, known as gcc, is the most commonly used C compiler.
Apples Mac OS X Developer Tools include a copy of gcc, but also include an Apple specific variation
that includes specialized features useful for development of Macintosh, iPhone, and iPad software.
Xcode
Xcode is an Apple integrated development environment. It includes the Instruments analysis tool, iOS
Simulator (useful for testing your software on the Mac before it is ready for deployment to real devices), and
the latest Mac OS X and iOS SDKs.
Fink
Fink (German for the bird finch) is an open source program that automates the process of downloading,
configuring, compiling, and installing hundreds of software packages from the original source code.
manual installation
There are two major methods for manually installing software from source: the standard method (used for
most Linux software) and the Perl method (used for Perl modules).
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
test bed
chapter 75
summary
This chapter looks at a test bed for writing this book.
At the time of this writing, this test bed does not yet exist. The author was asked to put together a list of
test bed requirements, emphasizing saving money as much as possible. Rather than keep this test bed as a
secret, it seems that it would be a good idea to share this information with the readers. It also makes sense to
share with the reader the process of installing each component of the test bed.
Thank you.
stages
There are five basic stages of deployment of the test bed.
1. initial main development computer This is a low cost used computer to get work started, as well as
the additional essential items to support that development.
2. initial server machines These are the first and most important machines for testing server deployment.
3. mobile computing These are the items needed for creating and testing mobile apps.
4. content creation These are the items needed for full content creation. These will be divided into
additional stages.
5. additional servers These are the additional desired test platforms for server and desktop testing.
3/5/13 11:01 AM
3/5/13 11:01 AM
FreeBSD computer
A computer set up with FreeBSD.
OpenVMS computer
An itanium computer set up with a hobbyist licensed copy of OpenVMS. Alternatively, an old Alpha or
old VAX can also be set up with a hobbyist licensed copy of OpenVMS. Given the lower cost for a used
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
machine, the Alpha version is probably the wisest, but if an Alpha or VAX is used, we will still need the
modern itanium version for the later step of additional servers.
Windows computer
Need to find someone willing to work in the horrid Windows environment who can check that the software
works correctly in that environment. Microsofts monopolistic approach may prevent deployment of systemindependent software.
mobile computing
These are the items needed for creating and testing mobile apps.
development computer
Hardware: This becomes the primary development computer (although the G5 development computer
will remain in use for testing and other purposes). This is a 15-inch MacBook Pro with Retina Display
Processor: 2.7 GHz Quad-core Intel Core 17
Memory: 16GB 1600MHz DDR3L SDRAM
Storage: Internal 768GB Flash Storage; External Promise Pegasus 12TB (6x2TB) R6 RAID System
Optical: External USB SuperDrive
Display: Internal: 15-inch Retina Display; external: Apple 30 inch Cinema HD Display
Keyboard: Backlit Keyboard (English) and Users Guide (English)
Software: Preinstalled from Apple: Keynote, Pages, Numbers
Accessories: Apple Thunderbolt to Gigabit Ethernet Adaptor; Mini DisplayPort to VGA Adaptor;
Apple Thunderbolt cable; Thunderbolt to FireWire 800 adaptor; Apple Mighty Mouse
Software: This is additional important software.
Tex-Edit Plus (new-shareware)
Fetch (new)
Apple Developer Tools (download free from Apple - you will have to apply and pay a fee to Apple)
Adobe CS6 Master Collection: Photoshop CS6 Extended; Illustrator CS6; InDesign CS6; Acrobat X
Pro; Flash Professional CS6; Flash Builder 4.6 Premium Edition; Dreamweaver CS6; Fireworks CS6;
Adobe Premiere Pro CS6; After Effects CS6; Adobe Audition CS6; SpeedGrade CS6; Prelude CS6;
Encore CS6; Bridge CS6; Media Encoder CS6
Apple Final Cut Pro X (with Apple Motion 5 and Apple Compressor 4) and Final Cut Pro 7 (only
available used)
Apple Logic Studio
Apple QuickTime 7 Pro for Mac OS X
Apple QuickTime MPEG-2 Playback Component for Mac OS X
Unsanity FruitMenu
Unsanity Labels X
Unsanity MenuMaster
Unsanity WindowShades
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
iPhone
An iPhone 5 and development system.
Android
An Android and development system.
iPad
An iPad and development system.
BlackBerry
A BlackBerry and development system.
Windows Phone
A Windows Phone 7 and development system.
Nokia
A Nokia and development system.
content creation
These are the items needed for full content creation. These will be divided into additional stages.
The content creation computer needs to be rented or leased, because a significant upgrade is expected early
2013 and that is when we need to purchase the long term content creation computer. In the meantime, we
need to purchase an external FireWire drive and a Thunderbolt converter. We will do our work from the
FireWire drive and then be easily able to plug it in to the new computer. Note that this main work drive is in
addition to working storage drive(s) and backup drive(s).
additional servers
These are the additional desired test platforms for server and desktop testing. There is no particular order
implied at this time, other than getting to Red hat Enterprise, Ubuntu, and Solaris as soon as possible. We
also want an IBM Power or Z system (even if it is an old one) with FORTRAN, PL/I, COBOL, and C
compilers, as well as IBMs server and system administration software.
3/5/13 11:01 AM
Solaris computer
An UltraSPARC computer set up with Solaris and Oracle Database.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
An IBM zEnterprise EC12 model HA1 computer running z/OS with Enterprise PL/I, FORTRAN,
Enterprise COBOL, and XL C/C++ compilers and APL interpreter. The HA1 with 101 processor units in 4
books, which include Central Processor (CP), Internal Coupling facility (ICF), Integrated facility for Linux
(IFL), Additional System Assist Processor (SAP), System z Application Assist Processor (zAAP), and
System z Intergrated Information Processor (zIIP) the exact mix of the 101 processors to be determined.
Water cooled option. 3040 GB of memory. zBX Model 003 attachment (with IBM POWER7 blade running
PowerVM Enterprise Edition, IBM POWER7 blade running AIX, IBM BladeCenter HX5 blade running Red
Hat Eterprise Linux, and IBM BladeCenter HX5 blade running SUSE Linux Enterprise Server, up to 112
blades). Trusted Key Entry (TKE) workstation. IBM Crypto Express 4S digital signature cryptography and
EAL 5+ certification. IBM zAware. IBM DB2 Amalytics Accelerator. IBM SmartCloud Enterprise+ for
System z. IBM System Storage DS8000. IBM TS1140 tape drives with encryption.
The zEnterprise EC12 is available in five hardware models: H20, H43, H66, H89, HA1A1. This includes the
capability to support over 100 configurable cores.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
command summaries
appendix A
command summaries
This subchapter provides a list of UNIX (Linux) command summaries.
a
a2ps
Fromat an ASCII file for printing on a PostScript printer [Linux]
alias
Create a command alias [builtin command in BASH]
apropos
Search Help manual pages (man -k)
apt-get
Search for and install software packages (Debian/Ubuntu)
aptitude Search for and install software packages (Debian/Ubuntu)
arp
Display and modify the Internet-to-Ethernet address translation tables
aspell
Spell Checker
at
Schedule a job
awk
Find and Replace text, database sort/validate/index
b
basename
bash
bc
bg
break
builtin
bzip2
cal
case
cat
cd
cfdisk
chgrp
chmod
chown
chroot
chkconfig
cksum
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
clear
cmp
comm
command
continue
cp
cron
crontab
csplit
cut
date
dc
dd
ddrescue
declare
defaults
df
dict
diff
diff3
dig
dir
dircolors
dirname
dirs
dmesg
du
echo
egrep
eject
enable
env
ethtool
eval
exec
exit
expect
expand
export
expr
false
fdformat
fdisk
Do nothing, unsuccessfully
Low-level format a floppy disk
Partition table manipulator for Linux
3/5/13 11:01 AM
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
fg
fgrep
file
find
fmt
fold
for
format
free
fsck
ftp
function
fuser
gawk
getopts
grep
groupadd
groupdel
groupmod
groups
gzip
hash
head
help
history
hostname
iconv
id
if
ifconfig
ifdown
ifup
import
init
install
jobs
join
jot
kill
killall
3/5/13 11:01 AM
k
l
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
less
let
ln
local
locate
logname
logout
look
lpc
lpr
lprint
lprintd
lprintq
lprm
ls
lsof
make
man
mkdir
mkfifo
mkisofs
mknod
mmv
more
mount
mtools
mtr
mv
mysql
3/5/13 11:01 AM
n
nano
Very simple editor
ncal>
Displays a calendar [alternative layout using cal]
netstat
Networking information
nice
Set the priority of a command or job
nl
Number lines and write files
nohup
Run a command immune to hangups
notify-send Send desktop notifications
nslookup Query Internet name servers interactively
o
open
op
passwd
paste
pathchk
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
ping
pkill
popd
pr
printcap
printenv
printf
ps
pushd
pwd
3/5/13 11:01 AM
q
quota
Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
r
ram
rcp
read
readarray
readonly
reboot
rename
renice
remsync
return
rev
rm
rmdir
route
rpm
rsync
s
screen
Multiplex terminal, run remote shells via SSH
screencapture Create screenshotts [Mac OS X]
scp
Secure copy (remote file copy)
sdiff
Merge two files interactively
sed
Stream Editor
select
Accept keyboard input
seq
Print numeric sequences
service
Run init scripts [System V]
set
Manipulate shell variables and functions
sftp
Secure File Transfer Program
shift
Shift positional parameters
shopt
Shell Options
shred
Secure delete
shutdown Shutdown or restart the system
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
sleep
slocate
sort
source
split
ssh
strace
su
sudo
sum
suspend
symlink
sync
sysstat
3/5/13 11:01 AM
t
tail
Output the last part of file
tar
Tape ARchiver
tee
Redirect output to multiple files
test
Evaluate a conditional expression
time
Measure program running time
times
User and system times
touch
Change file timestamps
top
List top processes running on the system
traceroute Trace Route to Host
trap
Run a command when a signal is set (Bourne)
tr
Translate, squeeze, and/or delete characters
troff
Format text for print
true
Do nothing, successfully
tsort
Topological sort
tty
Print filename of terminal on stdin
type
Describe a command [builtin command in BASH]
u
ulimit
umask
umount
unalias
uname
unexpand
uniq
units
unset
unshar
until
unzip
uptime
useradd
userdel
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
usermod
users
uuencode
uudecode
v
vdir
vi
vim
vmstat
w
wait
watch
wc
whatis
whereis
which
while
who
whoami
wget
write
xargs
xdg-open
yes
yum
3/5/13 11:01 AM
x
y
punctuation
.
!
#
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
history of computers
appendix B
Notes on the summary at the end of each year:
Year Year that items were introduced.
Operating Systems Operating systems introduced in that year.
Programming Languages Programming languages introduced. While only a few programming languages
are appropriate for operating system work (such as Ada, BLISS, C, FORTRAN, and PL/I, the programming
languages available with an operating system greatly influence the kinds of application programs available
for an operating system.
Computers Computers and processors introduced. While a few operating systems run on a wide variety of
computers (such as UNIX and Linux), most operating systems are closely or even intimately tied to their
primary computer hardware. Speed listings in parenthesis are in operations per second (OPS), floating point
operatins per second (FLOPS), or clock speed (Hz).
Software Software programs introduced. Some major application programs that became available. Often
the choice of operating system and computer was made by the need for specific programs or kinds of
programs.
Games Games introduced. It may seem strange to include games in the time line, but many of the
advances in computer hardware and software technologies first appeared in games. As one famous example,
the roots of UNIX were the porting of an early computer game to new hardware.
Technology Major technology advances.
antiquity
The earliest calculating machine was the abacus, believed to have been invented in Babylon around 2400
The abacus was used by many different cultures and civilizations, including the major advance known
as the Chinese abacus from the 2nd Century BCE.
BCE.
200s BCE
The Antikythera mechanism, discovered in a shipwreck in 1900, is an early mechanical analog computer
from between 150 BCE and 100 BCE. The Antikythera mechanism used a system of 37 gears to compute the
positions of the sun and the moon through the zodiac on the Egyptian calendar, and possibly also the fixed
stars and five planets known in antiquity (Mercury, Venus, Mars, Jupiter, and Saturn) for any time in the
future or past. The system of gears added and subtracted angular velocities to compute differentials. The
Antikythera mechanism could accurately predict eclipses and could draw up accurate astrological charts for
important leaders. It is likely that the Antikythera mechanism was based on an astrological computer created
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
100s BCE
The Chinese developed the South Pointing Chariot in 115 BCE. This device featured a differential gear,
later used in modern times to make analog computers in the mid-20th Century.
400s
The Indian grammarian Panini wrote the Ashtadhyayi in the 5th Century BCE. In this work he created 3,959
rules of grammar for Indias Sanskrit language. This important work is the oldest surviving linguistic book
and introduced the idea of metarules, transformations, and recursions, all of which have important
applications in computer science.
1400s
The Inca created digital computers using giant loom-like wooden structures that tied and untied knots in
rope. The knots were digital bits. These computers allowed the central government to keep track of the
agricultural and economic details of their far-flung empire. The Spanish conquered the Inca during fighting
that stretched from 1532 to 1572. The Spanish destroyed all but one of the Inca computers in the belief that
the only way the machines could provide the detailed information was if they were Satanic divination
devices. Archaeologists have long known that the Inca used knotted strings woven from cotton, llama wool,
or alpaca wool called khipu or quipus to record accounting and census information, and possibly calendar and
astronomical data and literature. In recent years archaeologists have figured out that the one remaining
device, although in ruins, was clearly a computer.
1800s
Charles Babbage created the difference engine and the analytical engine, often considered to be the first
modern computers. Augusta Ada King, the Countess of Lovelace, was the first modern computer
programmer.
In the 1800s, the first computers were programmable devices for controlling the weaving machines in the
factories of the Industrial Revolution. Created by Charles Babbage, these early computers used Punch cards
as data storage (the cards contained the control codes for the various patterns). These cards were very similiar
to the famous Hollerinth cards developed later. The first computer programmer was Lady Ada, for whom the
Ada programming language is named.
In 1822 Charles Babbage proposed a difference engine for automated calculating. In 1933 Babbage started
work on his Analytical Engine, a mechanical computer with all of the elements of a modern computer,
including control, arithmetic, and memory, but the technology of the day couldnt produce gears with enough
precision or reliability to make his computer possible. The Analytical Engine would have been programmed
with Jacquards punched cards. Babbage designed the Difference Engine No.2. Lady Ada Lovelace wrote a
program for the Analytical Engine that would have correctly calculated a sequence of Bernoulli numbers, but
was never able to test her program because the machine wasnt built.
George Boole introduced what is now called Boolean algebra in 1854. This branch of mathematics was
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
essential for creating the complex circuits in modern electronic digital computers.
1900s
In the 1900s, researchers started experimenting with both analog and digital computers using vacuum
tubes. Some of the most successful early computers were analog computers, capable of performing advanced
calculus problems rather quickly. But the real future of computing was digital rather than analog. Building on
the technology and math used for telephone and telegraph switching networks, researchers started building
the first electronic digital computers.
Leonardo Torres y Quevedo first proposed floating point arithmetic in Madrid in 1914. Konrad Zuse
independently proposed the same idea in Berlin in 1936 and built it into the hardware of his Zuse computer.
George Stibitz also indpendently proposed the idea in New Jersey in 1939.
The first modern computer was the German Zuse computer (Z3) in 1941. In 1944 Howard Aiken of
Harvard University created the Harvard Mark I and Mark II. The Mark I was primarily mechanical, while the
Mark II was primarily based on reed relays. Telephone and telegraph companies had been using reed relays
for the logic circuits needed for large scale switching networks.
The first modern electronic computer was the ENIAC in 1946, using 18,000 vacuum tubes. See below for
information on Von Neumanns important contributions.
The first solid-state (or transistor) computer was the TRADIC, built at Bell Laboratories in 1954. The
transistor had previously been invented at Bell Labs in 1948.
1938
Computers: Zuse Z1 (Germany, 1 OPS, first mechanical programmable binary computer, storage for a
total of 64 numbers stored as 22 bit floating point numbers with 7-bit exponent, 15-bit signifocana [one
implicit bit], and sign bit); Konrad Zuse called his floating point hardware semi-logarithmic notation and
included the ability to handle infinity and undefined.
1941
The first modern computer was the German Zuse computer (Z3) in 1941.
Computers: Atanasoff-Berry Computer; Zuse Z3 (Germany, 20 OPS, added floating point exceptions,
plus and minus infinity, and undefined)
1942
Computers: work started on Zuse Z4
1943
In 1943 Howard Aiken of Harvard University created the Harvard Mark I. The Mark I was primarily
mechanical.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1944
In 1944 Howard Aiken of Harvard University created the Harvard Mark II. While the Mark I was primarily
mechanical, the Mark II was primarily based on reed relays. Telephone and telegraph companies had been
using reed relays for the logic circuits needed for large scale switching networks.
Computers: Colossus 2 (U.K., single processor, 25 kOPS); Harvard Mark II and AT&T Bell Labortories
Model V (both relay computers) were the first American computers to include floating point hardware
1945
Plankalkl (Plan Calculus), created by Konrad Zuse for the Z3 computer in Nazi germany, may have been
the first programming language (other than assemblers). This was a surprisingly advanced programming
language, with many features that didnt appear again until the 1980s.
Programming Languages: Plankalkl
Computers: Zuse Z4 (relay based computer, first commercial computer)
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Von Neumann became an American citizen in 1933 to be eligible to help on top secret work during World
War II. There is a story that Oskar Morganstern coached von Neumann and Kurt Gdel on the U.S.
Constitution and American history while driving them to their immigration interview. Morganstern asked if
they had any questions, and Gdel replied that he had no questions, but had found some logical
inconsistencies in the Constitution that he wanted to ask the Immigration officers about. Morganstern
recommended that he not ask questions, but just answer them.
Von Neumann occassionally worked with Alan Turing in 1936 through 1938 when Turing was a graduate
student at Princeton. Von Neumann was exposed to the concepts of logical design and universal machine
proposed in Turings 1934 paper On Computable Numbers with an Application to the Entschiedungsproblem.
Von Neumann worked with such early computers as the Harvard Mark I,
ENIAC, EDVAC, and his own IAS computer.
Early research into computers involved doing the computations to create
tables, especially artillery firing tables. Von Neumann was convinced that
the future of computers involved applied mathematics to solve specific
problems rather than mere table generation. Von Neumann was the first
person to use computers for mathematical physics and economics, proving
the utility of a general purpose computer.
Von Neumann proposed the concept of stored programs in the 1945 paper First Draft of a Report on the
EDVAC. Influenced by the idea, Maurice Wilkes of the Cambridge University Mathematical Laboratory
designed and built the EDSAC, the worlds first operational, production, stored-program computer.
The first stored computer program ran on the Manchester Mark I [computer] on June 21, 1948.
Von Neumann foresaw the advantages of parallelism in computers, but because of construction limitations
of the time, he worked on sequential systems.
Von Neumann advocated the adoption of the bit as the measurement of computer memory and solved
many of the problems regarding obtaining reliable answers from unreliable computer components.
Interestingly, von Neumann was opposed to the idea of compilers. When shown the idea for FORTRAN in
1954, von Neumann asked Why would you want more than machine language?. Von Neumann had
graduate students hand assemble programs into binary code for the IAS machine. Donald Gillies, a student at
Princeton, created an assembler to do the work. Von Neumann was angry, claiming It is a waste of a
valuable scientific computing instrument to use it to do clerical work.
Von Neumann also did important work in set theory (including measure theory), the mathematical
foundation for quantum theory (including statistical mechanics), self-adjoint algebras of bounded linear
operators on a Hilbert space closed in weak operator topology, non-linear partial differential equations, and
automata theory (later applied to cmputers). His work in economics included his 1937 paper A Model of
General Economic Equilibrium on a multi-sectoral growth model and his 1944 book Theory of Games and
Economic Behavior (co-authored with Morgenstern) on game theory and uncertainty.
I leave the discussion of von Neumann with a couple of quotations:
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
If people do not believe that mathematics is simple, it is only because they do not realize how
complicated life is.
Anyone who considers arithmetical methods of producing random numbers is, of course, in a
state of sin.
bare hardware
In the earliest days of electronic digital computing, everything was done on the bare hardware. Very few
computers existed and those that did exist were experimental in nature. The researchers who were making the
first computers were also the programmers and the users. They worked directly on the bare hardware.
There was no operating system. The experimenters wrote their programs in machine or assembly language
and a running program had complete control of the entire computer. Often programs and data were entered by
hand through the use of toggle switches. Memory locations (both data and programs) could be read by
viewing a series of lights (one for each binary digit). Debugging consisted of a combination of fixing both the
software and hardware, rewriting the object code and changing the actual computer itself.
The lack of any operating system meant that only one person could use a computer at a time. Even in the
research lab, there were many researchers competing for limited computing time. The first solution was a
reservation system, with researchers signing up for specific time slots. The earliest billing systems charged
for the entire computer and all of its resources (regardless of whether used or not) and was based on outside
clock time, being billed from the scheduled start to scheduled end times.
The high cost of early computers meant that it was essential that the rare computers be used as efficiently
as possible. The reservation system was not particularly efficient. If a researcher finished work early, the
computer sat idle until the next time slot. If the researchers time ran out, the researcher might have to pack
up his or her work in an incomplete state at an awkward moment to make room for the next researcher. Even
when things were going well, a lot of the time the computer actually sat idle while the researcher studied the
results (or studied memory of a crashed program to figure out what went wrong). Simply loading the
programs and data took up some of the scheduled time.
computer operators
One solution to this problem was to have programmers prepare their work off-line on some input medium
(often on punched cards, paper tape, or magnetic tape) and then hand the work to a computer operator. The
computer operator would load up jobs in the order received (with priority overrides based on politics and
other factors). Each job still ran one at a time with complete control of the computer, but as soon as a job
finished, the operator would transfer the results to some output medium (punched tape, paper tape, magnetic
tape, or printed paper) and deliver the results to the appropriate programmer. If the program ran to
completion, the result would be some end data. If the program crashed, memory would be transferred to some
output medium for the programmer to study (because some of the early business computing systems used
magnetic core memory, these became known as core dumps).
The concept of computer operators dominated the mainframe era and continues today in large scale
operations with large numbers of servers.
3/5/13 11:01 AM
Soon after the first successes with digital computer experiments, computers moved out of the lab and into
practical use. The first practical application of these experimental digital computers was the generation of
artillery tables for the British and American armies. Much of the early research in computers was paid for by
the British and American militaries. Business and scientific applications followed.
As computer use increased, programmers noticed that they were duplicating the same efforts.
Every programmer was writing his or her own routines for I/O, such as reading input from a magnetic tape
or writing output to a line printer. It made sense to write a common device driver for each input or putput
device and then have every programmer share the same device drivers rather than each programmer writing
his or her own. Some programmers resisted the use of common device drivers in the belief that they could
write more efficient or faster or "better device drivers of their own.
Additionally each programmer was writing his or her own routines for fairly common and repeated
functionality, such as mathematics or string functions. Again, it made sense to share the work instead of
everyone repeatedly reinventing the wheel. These shared functions would be organized into libraries and
could be inserted into programs as needed. In the spirit of cooperation among early researchers, these library
functions were published and distributed for free, an early example of the power of the open source approach
to software development.
Computer manufacturers started to ship a standard library of device drivers and utility routines with their
computers. These libraries were often called a runtime library because programs connected up to the
routines in the library at run time (while the program was running) rather than being compiled as part of the
program. The commercialization of code libraries ended the widespread free sharing of software.
Manufacturers were pressured to add security to their I/O libraries in order to prevent tampering or loss of
data.
3/5/13 11:01 AM
Tear down would include unmounting tapes, drives, and other media.
The very expensive early computers sat idle during both set up and tear down.
This waste led to the introduction of less expensive I/O computers. While one I/O computer was being set
up or torn down, another I/O computer could be communicating a readied job with the main computer.
Some installations might have several different I/O computers connected to a single main computer to keep
the expensive main computer in use. This led to the concept of multiple I/O channels.
monitors
As computers spread from the research labs and military uses into the business world, the accountants
wanted to keep more accurate counts of time than mere wall clock time.
This led to the concept of the monitor. Routines were added to record the start and end times of work
using computer clock time. Routines were added to I/O library to keep track of which devices were used and
for how long.
With the development of the Input Output Control System, these time keeping routines were centralized.
You will notice that the word monitor appears in the name of some operating systems, such as FORTRAN
Monitor System. Even decades later many programmers still refer to the operating system as the monitor.
An important motivation for the creation of a monitor was more accurate billing. The monitor could keep
track of actual use of I/O devices and record runtime rather than clock time.
For accurate time keeping the monitor had to keep track of when a program stopped running, regardless of
whether it was a normal end of the program or some kind of abnormal termination (such as aa crash).
The monitor reported the end of a program run or error conditions to a computer operator, who could load
the next job waiting, rerun a job, or take other actions. The monitor also notified the computer operator of the
need to load or unload various I/O devices (such as changing tapes, loading paper into the printer, etc.).
1946
The first modern electronic computer was the ENIAC in 1946, using 18,000 vacuum tubes.
Computers: UPenn Eniac (5 kOPS); Colossus 2 (parallel processor, 50 kOPS)
Technology: electrostatic memory
1948
Computers: IBM SSEC; Manchester SSEM
Technology: random access memory; magnetic drums; transistor
1949
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Short Code created in 1949. This programming language was compiled into machine code by hand.
Programming Languages: Short Code
Computers: Manchester Mark 1
Technology: registers
1950s
Some operating systems from the 1950s include: FORTRAN Monitor System, General Motors Operating
System, Input Output System, SAGE, and SOS.
SAGE (Semi-Automatic Ground Environment), designed to monitor weapons systems, was the first real
time control system.
1951
Grace Hopper starts work on A-0.
Computers: Ferranti Mark 1 (first commercial computer); Leo I (frst business computer); UNIVAC I,
Whirlwind
1952
Autocode, a symbolic assembler for the Manchester Mark I computer, was created in 1952 by Alick E.
Glennie. Later used on other computers.
A-0 (also known as AT-3), the first compiler, was created in 1952 by Grace Murray Hopper. She later
created A-2, ARITH-MATIC, MATH-MATIC, and FLOW-MATIC, as well as being one of the leaders in
the development of COBOL.Grace Hopper was working for Remington Rand at the time. Rand released the
language as MATH-MATIC in 1957.
According to some sources, first work started on FORTRAN.
Programming Languages: Autocode; A-0; FORTRAN
Computers: UNIVAC 1101; IBM 701
Games: OXO (a graphic version of Tic-Tac-Toe created by A.S. Douglas on the EDSAC computer at the
University of Cambridge to demonstrate ideas on human-computer interaction)
1953
Computers: Strela
1954
The first solid-state (or transistor) computer was the TRADIC, built at Bell Laboratories in 1954. The
transistor had previously been invented at Bell Labs in 1948.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
FORTRAN (FORmula TRANslator) was created in 1954 by John Backus and other researchers at
International Business Machines (now IBM). Released in 1957. FORTRAN is the oldest programming
language still in common use. Identifiers were limited to six characters. Elegant representation of mathematic
expressions, as well as relatively easy input and output. FORTRAN was based on A-0.
Often referred to as a scientific language, FORTRAN was the first high-level language, using
the first compiler ever developed. Prior to the development of FORTRAN computer
programmers were required to program in machine/assembly code, which was an extremely
difficult and time consuming task, not to mention the dreadful chore of debugging the code. The
objective during its design was to create a programming language that would be: simple to learn,
suitable for a wide variety of applications, machine independent, and would allow complex
mathematical expressions to be stated similarly to regular algebraic notation. While still being
almost as efficient in execution as assembly language. Since FORTRAN was so much easier to
code, programmers were able to write programs 500% faster than before, while execution
efficiency was only reduced by 20%, this allowed them to focus more on the problem solving
aspects of a problem, and less on coding.
FORTRAN was so innovative not only because it was the first high-level language [still in
use], but also because of its compiler, which is credited as giving rise to the branch of computer
science now known as compiler theory. Several years after its release FORTRAN had developed
many different dialects, (due to special tweaking by programmers trying to make it better suit
their personal needs) making it very difficult to transfer programs from one machine to another.
Neal Ziring, The Language Guide, University of Michigan
Some of the more significant features of the language are listed below: Neal Ziring, The
Language Guide, University of Michigan
Simple to learn - when FORTRAN was design one of the objectives was to write a
language that was easy to learn and understand.
Machine Independent - allows for easy transportation of a program from one machine to
another.
More natural ways to express mathematical functions - FORTRAN permits even
severely complex mathematical functions to be expressed similarly to regular algebraic
notation.
Problem orientated language
Remains close to and exploits the available hardware
Efficient execution - there is only an approximate 20% decrease in efficiency as
compared to assembly/machine code.
Ability to control storage allocation -programmers were able to easily control the
allocation of storage (although this is considered to be a dangerous practice today, it was
quite important some time ago due to limited memory.
More freedom in code layout - unlike assembly/machine language, code does not need to
be laid out in rigidly defined columns, (though it still must remain within the parameters of
the FORTRAN source code form).
42. You can measure a programmers perspective by noting his attitude on the continuing
vitality of FORTRAN. Alan Perlis, Epigrams on Programming, ACMs SIGPLAN Notices
Volume 17, No. 9, September 1982, pages 7-13
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1955
Operating Systems: GMOS (General Motors OS for IBM 701)
Computers: Harwell CADET
batch systems
Batch systems automated the early approach of having human operators load one program at a time.
Instead of having a human operator load each program, software handled the scheduling of jobs. In addition
to programmers submitting their jobs, end users could submit requests to run specific programs with specific
data sets (usually stored in files or on cards). The operating system would schedule batches of related jobs.
Output (punched cards, magnetic tapes, printed material, etc.) would be returned to each user.
General Motors Operating System, created by General Motors Research Laboratories in early 1956 (or late
1955) for thieir IBM 701 mainframe is generally considered to be the first batch operating system and
possibly the first real operating system.
The operating system would read in a program and its data, run that program to completion (including
outputing data), and then load the next program in series as long as there were additional jobs available.
Batch operating systems used a Job Control Language (JCL) to give the operating system instructions.
These instructions included designation of which punched cards were data and which were programs,
indications of which compiler to use, which centralized utilities were to be run, which I/O devices might be
used, estimates of expected run time, and other details.
This type of batch operating system was known as a single stream batch processing system.
Examples of operating systems that were primarily batch-oriented include: BKY, BOS/360, BPS/360,
CAL, and Chios.
1956
Researchers at MIT begin experimenting with direct keyboard input into computers.
IPL (Information Processing Language) was created in 1956 by A. Newell, H. Simon, and J.C. Shaw. IPL
was a low level list processing language which implemented recursive programming.
Programming Languages: IPL
Operating Systems: GM-NAA I/O
Computers: IBM 305 RAMAC; MIT TX-0 (83 kOPS)
Technology: hard disk
1957
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
MATH-MATIC was released by the Rand Corporation in 1957. The language was derived from Grace
Murray Hoppers A-0.
FLOW-MATIC, also called B-0, was created in 1957 by Grace Murray Hopper.
The first commercial FORTRAN program was run at Westinghouse. The first compile run produced a
missing comma diagnostic. The second attempt was a success.
BESYS OS was created by Bell telephone Laboratories for internal use.
The U.S. government created the Advanced Research Project Group (ARPA) in esponse to the Soviet
Unions launching of Sputnik. ARPA was intended to develop key technology that was too risky for private
business to develop.
Programming Languages: FLOW-MATIC; MATH-MATIC
Operating Systems: BESYS OS
Computers: IBM 608
Technology: dot matrix printer
1958
FORTRAN II in 1958 introduces subroutines, functions, loops, and a primitive For loop.
IAL (International Algebraic Logic) started as the project later renamed ALGOL 58. The theoretical
definition of the language is published. No compiler.
LISP (LISt Processing) was created n 1958 and released in 1960 by John McCarthy of MIT. LISP is the
second oldest programming language still in common use. LISP was intended for writing artificial
intelligence programs.
Interest in artificial intelligence first surfaced in the mid 1950. Linguistics, psychology, and
mathematics were only some areas of application for AI. Linguists were concerned with natural
language processing, while psychologists were interested in modeling human information and
retrieval. Mathematicians were more interested in automating the theorem proving process. The
common need among all of these applications was a method to allow computers to process
symbolic data in lists.
IBM was one of the first companies interested in AI in the 1950s. At the same time, the
FORTRAN project was still going on. Because of the high cost associated with producing the
first FORTRAN compiler, they decided to include the list processing functionality into
FORTRAN. The FORTRAN List Processing Language (FLPL) was designed and implemented
as an extention to FORTRAN.
In 1958 John McCarthy took a summer position at the IBM Information Research
Department. He was hired to create a set of requirements for doing symbolic computation. The
first attempt at this was differentiation of algebraic expressions. This initial experiment produced
a list of of language requirements, most notably was recursion and conditional expressions. At
the time, not even FORTRAN (the only high-level language in existance) had these functions.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
It was at the 1956 Dartmouth Summer Research Project on Artificial Intelligence that John
McCarthy first developed the basics behind Lisp. His motivation was to develop a list processing
language for Artificial Intelligence. By 1965 the primary dialect of Lisp was created (version
1.5). By 1970 special-purpose computers known as Lisp Machines, were designed to run Lisp
programs. 1980 was the year that object-oriented concepts were integrated into the language. By
1986, the X3J13 group formed to produce a draft for ANSI Common Lisp standard. Finally in
1992, X3J13 group published the American National Standard for Common Lisp. Neal
Ziring, The Language Guide, University of Michigan
Some of the more significant features of the language are listed below: Neal Ziring, The
Language Guide, University of Michigan
Atoms & Lists - Lisp uses two different types of data structures, atoms and lists.
Atoms are similar to identifiers, but can also be numeric constants
Lists can be lists of atoms, lists, or any combination of the two
Functional Programming Style - all computation is performed by applying functions to
arguments. Variable declarations are rarely used.
Uniform Representation of Data and Code - example: the list (A B C D)
a list of four elements (interpreted as data)
is the application of the function named A to the three parameters B, C, and D
(interpreted as code)
Reliance on Recursion - a strong reliance on recursion has allowed Lisp to be successful
in many areas, including Artificial Intelligence.
Garbage Collection - Lisp has built-in garbage collection, so programmers do not need to
explicitly free dynamically allocated memory.
55. A LISP programmer knows the value of everything, but the cost of nothing. Alan
Perlis, Epigrams on Programming, ACMs SIGPLAN Notices Volume 17, No. 9, September
1982, pages 7-13
Programming Languages: FORTRAN II; IAL; LISP
Operating Systems: UMES
Computers: UNIVAC II; IBM AN/FSQ-7 (400 kOPS)
Games:Tennis For Two (developed by William Higinnotham using an osciliscope and an analog
computer)
Technology: integrated circuit
1959
COBOL (COmmon Business Oriented Language) was created in May 1959 by the Short Range
Committee of the U.S. Department of Defense (DoD). The CODASYL committee (COnference on DAta
SYstems Languages) worked from May 1959 to April 1960. Official ANSI standards included COBOL-68
(1968), COBOL-74 (1974), COBOL-85 (1985), and COBOL-2002 (2002). COBOL 97 (1997) introduced an
object oriented version of COBOL. COBOL programs are divided into four divisions: identification,
environment, data, and procedure. The divisions are further divided into sections. Introduced the RECORD
data structure. Emphasized a verbose style intended to make it easy for business managers to read programs.
Admiral Grace Hopper is recognized as the major contributor to the original COBOl language and as the
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
inventor of compilers.
LISP 1.5 released in 1959.
DYNAMO is a computer program for translating mathematical models from an easy-tounderstand notation into tabulated and plotted results. A model written in DYNAMO consists
of a number of algebraic relationships that relate the variables one to another. Although similar
to FORTRAN, it is easier to learn and understand. DYNAMO stands for DYNAmic MOdels. It
was written by Dr. Phyllis Fox and Alexander L. Pugh, III, and was completed in 1959. It grew
out of an earlier language called SIMPLE (for Simulation of Industrial Management Problems
with Lots of Equations), written in 1958 by Richard K. Bennett. Language Finger, Maureen
and Mike Mansfield Library, University of Montana.
ERMA (Electronic Recording Method of Accounting), a magnetic ink and computer readable font, was
created for the Bank of America.
Programming Languages: COBOL; DYNAMO; ERMA; LISP 1.5
Operating Systems: SHARE
Computers: IBM 1401
early 1960s
The early 1960s saw the introduction of time sharing and multi-processing.
Some operating systems from the early 1960s include: Admiral, B1, B2, B3, B4, Basic Executive System,
BOS/360, Compatible Timesharing System (CTSS), EXEC I, EXEC II, Honeywell Executive System, IBM
1410/1710 OS, IBSYS, Input Output Control System, Master Control Program, and SABRE.
The first major transaction processing system was SABRE (Semi-Automatic Business Related
Environment), developed by IBM and American Airlines.
multiprogramming
There is a huge difference in speed between I/O and running programs. In a single stream system, the
processor remains idle for much of the time as it waits for the I/O device to be ready to send or receive the
next piece of data.
The obvious solution was to load up multiple programs and their data and switch back and forth between
programs or jobs.
When one job idled to wait for input or output, the operating system could automatically switch to another
job that was ready.
system calls
The first operating system to introduce system calls was University of Machesters Atlas I Supervisor.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
time sharing
The operating system could have additional reasons to rotate through jobs, including giving higher or
lower priority to various jobs (and therefore a larger or smaller share of time and other resources). The
Compatible Timesharing System (CTSS), first dmonstrated in 1961, was one of the first attempts at
timesharing.
While most of the CTSS operating system was written in assembly language (all previous OSes were
written in assembly for efficiency), the scheduler was written in the programming language MAD in order to
allow safe and reliable experimentation with different scheduling algorithms. About half of the command
programs for CTSS were also written in MAD.
Timesharing is a more advanced version of multiprogramming that gives many users the illusion that they
each have complete control of the computer to themselves. The scheduler stops running programs based on a
slice of time, moves on to the next program, and eventually returns back to the beginning of the list of
programs. In little increments, each program gets their work done in a manner that appears to be
simultaneous to the end users.
mid 1960s
Some operating systems from the mid-1960s include: Atlas I Supervisor, DOS/360, Input Output Selector,
Master Control Program, and Multics.
The Atlas I Supervisor introduced spooling, interrupts, and virtual memory paging (16 pages) in 1962.
Segmentation was introduced on the Burroughs B5000. MITs Multics combined paging and segmentation.
The Compatible Timesharing System (CTSS) introduced email.
late 1960s
Some operating systems from the late-1960s include: BPS/360, CAL, CHIPPEWA, EXEC 3, EXEC 4,
EXEC 8, GECOS III, George 1, George 2, George 3, George 4, IDASYS, MASTER, Master Control
Program, OS/MFT, OS/MFT-II, OS/MVT, OS/PCP, and RCA DOS.
1960
ALGOL (ALGOrithmic Language) was released in 1960. Major releases in 1960 (ALGOL 60) and 1968
(ALGOL 68). ALGOL is the first block-structured labguage and is considered to be the first second
generation computer language. This was the first programming language that was designed to be machine
independent. ALGOL introduced such concepts as: block structure of code (marked by BEGIN and END),
scope of variables (local variables inside blocks), BNF (Backus Naur Form) notation for defining syntax,
dynamic arrays, reserved words, IF THEN ELSE, FOR, WHILE loop, the := symbol for assignment,
SWITCH with GOTOs, and user defined data types. ALGOL became the most popular programming
language in Europe in the mid- and late-1960s.
C.A.R. Hoare invents the Quicksortin 1960.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1961
The Compatible Timesharing System (CTSS), first dmonstrated in 1961, was one of the first attempts at
timesharing.
While most of the CTSS operating system was written in assembly language (all previous OSes were
written in assembly for efficiency), the scheduler was written in the programming language MAD in order to
allow safe and reliable experimentation with different scheduling algorithms. About half of the command
programs for CTSS were also written in MAD.
Operating Systems: CTSS, Burroughs MCP
Computers: IBM 7030 Stretch (1.2 MFLOPS)
1962
APL (A Programming Language) was published in the 1962 book A Programming Language by Kenneth
E. Iverson and a subset was first released in 1964. The language APL was based on a notation that Iverson
invented at Harvard University in 1957. APL was intended for mathematical work and used its own special
character set. Particularly good at matrix manipulation. In 1957 it introduced the array. APL used a special
character set and required special keyboards, displays, and printers (or printer heads).
FORTRAN IV is released in 1962.
Simula was created by Ole-Johan Dahl and Kristen Nygaard of the Norwegian Computing Center between
1962 and 1965. A compiler became available in 1964. Simula I and Simula 67 (1967) were the first objectoriented programming languages.
SNOBOL (StroNg Oriented symBOli Language) was created in 1962 by D.J. Farber, R.E. Griswold, and
F.P. Polensky at Bell Telephone Laboratories. Intended for processing strings, the language was the first to
use associative arrays, indexed by any type of key. Had features for pattern-matching, concatenation, and
alternation. Allowed running code stored in strings. Data types: integer, real, array, table, pattern, and user
defined types.
SpaceWarI, the first interactive computer game, was created by MIT students Slug Russel, Shag Graetz,
and Alan Kotok on DECs PDP-1.
The first operating system to introduce system calls was University of Machesters Atlas I Supervisor.
The Atlas I Supervisor introduced spooling, interrupts, and virtual memory paging (16 pages) in 1962.
Segmentation was introduced on the Burroughs B5000. MITs Multics combined paging and segmentation.
Operating Systems: GECOS
Programming Languages: APL; FORTRAN IV; Simula; SNOBOL
Computers: ATLAS, UNIVAC 1100/2200 (introduced two floating point formats, single precision and
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
double precision; single precision: 36 bits, 1-bit sign, 8-bit exponent, and 27-bit significand; double
precision: 36 bits, 1-bit sign, 11-bit exponent, and 60-bit significand), IBM 7094 (followed the UNIVAC,
also had single and double precision numbers)
Games: Spacewar! (created by group of M.I.T. students on the DEC PDP-1)
Technology: RAND Corporation proposes the internet
1963
Work on PL/I starts in 1963.
Data-Text was the original and most general problem-oriented computer language for
social scientists. It has the ability to handle very complicated data processing problems and
extremely intricate statistical analyses. It arose when FORTRAN proved inadequate for such
uses. Designed by Couch and others, it was first used in 1963/64, then extensively revised in
1971. The Data-Text System was originally programmed in FAP, later in FORTRAN, and finally
its own language was developed. Language Finger, Maureen and Mike Mansfield Library,
University of Montana.
Sketchpad, an interactive real time computer drawing system, was created in 1963 by Ivan Sutherland as
his doctoral thesis at MIT. The system used a light pen to draw and manipulate geometric figures on a
computer screen.
ASCII (American Standard Code for Information Interchange) was introduced in 1963.
Programming Languages: Data-Text
Computers: DEC PDP-6
Software: Sketchpad
Technology: mouse
1964
BASIC (Beginners All-purpose Symbolic Instruction Code) was designed as a teaching language in 1963
by John George Kemeny and Thomas Eugene Kurtz of Dartmouth College. BASIC was intended to make it
easy to learn programming. The first BASIC program was run at 4 a.m. May 1, 1964.
PL/I (Programming Language One) was created in 1964 at IBMs Hursley Laboratories in the United
Kingdom. PL/I was intended to combine the scientific abilities of FORTRAN with the business capabilities
of COBOL, plus additional facilities for systems programming. Also borrows from ALGOL 60. Originally
called NPL, or New Programming Language. Introduces storage classes (automatic, static, controlled, and
based), exception processing (On conditions), Select When Otherwise conditional structure, and several
variations of the DO loop. Numerous data types, including control over precision.
RPG (Report Program Generator) was created in 1964 by IBM. Intended for creating commercial and
business reports.
APL\360 implemented in 1964.
Bell Telephone Laboratories determines that it needs a new operating system to replace its 1957 BESYS
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1965
Multics The Massachusetts Institute of Technology (MIT), AT&T Bell Labs, and General Electric
attempted to create an experimental operating system called Multics for the GE-645 mainframe computer.
AT&T intended to offer subscription-based computing services over the phone lines, an idea similar to the
modern cloud approach to computing.
While the Multics project had many innovations that went on to become standard approaches for operating
systems, the project was too complex for the time.
SNOBOL 3 was released in 1965.
Attribute grammars were created in 1965 by Donald Knuth.
Operating Systems: OS/360; Multics
Programming Languages: SNOBOL 3
Technology: time-sharing; fuzzy logic; packet switching; bulletin board system (BBS); email
1966
ALGOL W was created in 1966 by Niklaus Wirth. ALGOL W included RECORDs, dynamic data
structures, CASE, passing parameters by value, and precedence of operators.
Euler was created in 1966 by Niklaus Wirth.
FORTRAN 66 was released in 1966. The language was rarely used.
ISWIM (If You See What I Mean) was described in 1966 in Peter J. Landins article The Next 700
Programming Languages in the Communications of the ACM. ISWIM, the first purely functional language,
influenced functional programming languages. The first language to use lazy evaluation.
LISP 2 was released in 1966.
Programming Languages: ALGOL W; Euler; FORTRAN 66; ISWIM
Computers: BESM-6
1967
Logo was created in 1967 (work started in 1966) by Seymour Papert. Intended as a programming language
for children. Started as a drawing program. Based on moving a turtle on the computer screen.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Simula 67 was created by Ole-Johan Dahl and Kristen Nygaard of the Norwegian Computing Center in
1967. Introduced classes, methods, inheriteance, and objects that are instances of classes.
SNOBOL 4 (StroNg Oriented symBOli Language) was released in 1967.
CPL (Combined Programming Language) was created in 1967 at Cambridge and London Universities.
Combined ALGOL 60 and functional language. Used polymorphic testing structures. Included the ANY type,
lists, and arrays.
Operating Systems: ITS; CP/CMS; WAITS
Programming Languages: CPL; Logo; Simula 67; SNOBOL 4
1968
In 1968 a group of scientists and engineers from Mitre Corporation (Bedford, Massachusetts) created
Viatron Computer company and an intelligent data terminal using an 8-bit LSI microprocessor from PMOS
technology.
ALGOL 68 in 1968 introduced the =+ token to combine assignment and add, UNION, and CASTing of
types. It included the IF THEN ELIF FI structure, CASE structure, and user-defined operators.
Forth was created by Charles H. Moore in 1968. Stack based language. The name Forth was a reference
to Moores claim that he had created a fourth generation programming language.
ALTRAN, a variant of FORTRAN, was released.
ANSI version of COBOL defined.
Edsger Dijkstra wrote a letter to the Communications of the ACM claiming that the use of GOTO was
harmful.
Programming Languages: ALTRAN; ALGOL 68; Forth
Computers: DEC PDP-10
Technology: microprocessor; interactive computing (including mouse, windows, hypertext, and fullscreen
word processing)
1969
In 1969 Viatron created the 2140, the first 4-bit LSI microprocessor. At the time MOS was used only for a
small number of calculators and there simply wasnt enough worldwide manufacturing capacity to build these
computers in quantity.
UNIX was created at AT&T Bell Telephone Laboratories (now an independent corporation known as
Lucent Technologies) by a group that included Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas
McIlroy, Michael Lesk and Joe Ossanna.
This group of researchers, the last of the AT&T employees involved in Multics, decided to attempt the
goals of Multics on a much more simple scale.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Unix was originally called UNICS, for Uniplexed Information and Computing Service, a play on words
variation of Multics, Multiplexed Information and Computing Service (uni- means one, multi- means
many).
What we wanted to preserve was not just a good environment in which to do programming, but a system
around which a fellowship could form. We knew from experience that the essence of communal computing,
as supplied by remote-access, time-shared machines, is not just to type programs into a terminal instead of a
keypunch, but to encourage close communication, according to Dennis Ritchie.
UNIX was originally intended as a programmers workbench. The original version was a single-user
system. As UNIX spread through the academic community, more general purpose tools were added, turning
UNIX into a general purpose operating system.
While Ken Thompson still had access to the Multics environment, he wrote simulations on Multics for
UNIXs file and paging system.
Ken Thompson and Dennis Ritchie led a team
of Bell Labs researchers (the team included Rudd
Canaday) working on the PDP-7 to develop a
hierarchial file system, computer processes,
device files, a command-line interpreter, and a
few small utility programs.
This version of UNIX was written in the B
language.
At the time, AT&T was prohibited from
selling computers or software, but was allowed to
develop its own software and computers for
internal use. AT&Ts consent decree with the
U.S. Justice Department on monopoly charges was interpretted as allowing AT&T to release UNIX as an
open source operating system for academic use. Ken Thompson, one of the originators of UNIX, took UNIX
to the University of California, Berkeley, where students quickly started making improvements and
modifications, leading to the world famous Berkeley Software Distribution (BSD) form of UNIX.
UNIX quickly spread throughout the academic world, as it solved the problem of keeping track of many
(sometimes dozens) of proprietary operating systems on university computers. With UNIX all of the
computers from many different manufacturers could run the same operating system and share the same
programs (recompiled on each processor).
BCPL (Basic CPL) was created in 1969 in England. Intended as a simplified version of CPL, includes the
control structures For, Loop, If Then, While, Until Repeat, Repeat While, and Switch Case.
BCPL was an early computer language. It provided for comments between slashes. The name
is condensed from Basic CPL; CPL was jointly designed by the universities of Cambridge and
London. Officially, the C stood first for Cambridge, then later for Combined. -Unofficially it was generally accepted as standing for Christopher Strachey, who was the main
impetus behind the language. Language Finger, Maureen and Mike Mansfield Library,
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
University of Montana.
B (derived from BCPL) developed in 1969 by Ken Thompson of Bell Telephone Laboratories for use in
systems programming for UNIX. This was the parent language of C.
SmallTalk was created in 1969 at Xerox PARC by a team led by Alan Kay, Adele Goldberg, Ted Kaehler,
and Scott Wallace. Fully object oriented programming language that introduces a graphic environment with
windows and a mouse.
RS-232-C standard for serial communication introduced in 1969.
Space Travel Ken Thompson ported the Space Travel computer game from Multics to a Digital
Equipment Corporation (DEC) PDP-7 he found at Bell Labs.
ARPA creates ARPAnet, the forerunner of the Internet (originally hosted by UCLA, UC Santa Barbara,
University of Utah, and Stanford Research Institute).
Operating Systems: ACP; TENEX/TOPS-20; work started on Unix (initially called UNICS)
Programming Languages: B, BCPL; SmallTalk
Computers: CDC 7600 (36 MFLOPS)
Games: Space Travel (written by Jeremy Ben for Multics; when AT&T pulled out of the Multics project,
J. Ben ported the program to FORTRAN running on GECOS on the GE 635; then ported by J. Ben and
Dennis Ritchie in PDP-7 assembly language; the process of porting the game to the PDP-7 computer was the
beginning of Unix)
Technology: ARPANET (military/academic precursor to the Internet); RS-232; networking; laser printer
(invented by Gary Starkweather at Xerox)
early 1970s
Some operating systems from the early-1970s include: BKY, Chios, DOS/VS, Master Control Program,
OS/VS1, and UNIX.
mid 1970s
Some operating systems from the mid-1970s include: CP/M, Master Control Program.
late 1970s
Some operating systems from the late-1970s include: EMAS 2900, General Comprehensive OS, VMS
(later renamed OpenVMS), OS/MVS.
1970
Prolog (PROgramming LOGic) was created in 1972 in France by Alan Colmerauer with Philippe Roussel.
Introduces Logic Programming.
Pascal (named for French religious fanatic and mathematician Blaise Pascal) was created in 1970 by
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Niklaus Wirth on a CDC 6000-series computer. Work started in 1968. Pascl was intended as a teaching
language to replace BASIC, but quickly developed into a general purpose programming language. Programs
compiled to a platform-independent intermediate P-code. The compiler for pascal was written in Pascal, an
influential first in language design.
Forth used to write the program to control the Kitt Peaks telescope.
BLISS was a systems programming language developed by W.A. Wulf, D.B. Russell, and A.N.
Habermann at Carnegie Mellon University in 1970. BLISS was a very popular systems programming
language until the rise of C. The original compiler was noted for its optimizing of code. Most of the utilities
for DECs VMS operating system were written in BLISS-32. BLISS was a typeless language based on
expressions rather than statements. Expressions produced values, and possibly caused other actions, such as
modification of storage, transfer of control, or looping. BLISS had powerful macro facilities, conditional
execution of statements, subroutines, built-in string functions, arrays, and some automatic data conversions.
BLISS lacked I/O instructions on the assumption that systems I/O would actually be built in the language.
UNIX In 1970 Dennis Ritchie and Ken Thompson traded the promise to add text processing capabilities to
UNIX for the use of a Digital Equipment Corporation (DEC) PDP-11/20. The initial version of UNIX, a text
editor, and a text formatting program called roff were all written in PDP-11/20 assembly language.
UNIX was renamed from the original name UNICS. The author of the name change is lost to history.
ROFF Soon afterwards roff evolved into troff with full typesetting capability. The UNIX Programmers
Manual was published on November 3, 1971. The first commercial UNIX system was installed in early 1962
at the New York Telephone Co. Systems Development Center under the direction of Dan Gielan. Neil
Groundwater build an Operational Support System in PDP-11/20 assembly language.
Operating Systems: Unix; RT-11; RSTS-11
Programming Languages: BLISS; Pascal; Prolog
Computers: Datapoint 2200; DEC PDP-11
Software: ROFF
Technology: dynamic RAM; flight data processor
1971
Manufacturers saw the benefit of MOS, starting with Intels 1971 release of the 4-bit 4004 as the first
commercially available microprocessor.
UNIX shell This first UNIX command shell, called the Thompson shell and abbreviated sh, was written by
Ken Thompson at AT&Ts Bell Labs, was much more simple than the famous UNIX shells that came along
later. The Thompson shell was distributed with Versions 1 through 6 of UNIX, from 1971 to 1975.
The first UNIX book, UNIX Programmers Manual, by Ken Thompson and Dennis Ritchie, was published
in 1971 and included 60 commands.
Computers: Intel 4004 (four-bit microprocessor)
Software: UNIX shell
Games: Computer Space (first commercial vidoe game)
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1972
In 1972 Rockwell released the PPS-4 microprocessor, Fairchild released the PPS-25 microprocessor, and
Intel released the 8-bit 8008 microprocessor. All used PMOS.
C was developed from 1969-1972 by Dennis Ritchie and Ken Thompson of Bell Telephone Laboratories
for use in systems programming for UNIX. C was based on the earlier programming language B.
UNIX In 1972 work started on converting UNIX to C. The UNIX kernel was originally written in
assembly language, but by 1973 it had been almost completely converted to the C language. At the time it
was common belief that operating systems must be written in assembly in order to perform at reasonable
speeds. This made Unix the worlds first portable operating system, capable of being easily ported (moved) to
any hardware. This was a major advantage for Unix and led to its widespread use in the multi-platform
environments of colleges and universities. Writing UNIX in C allowed for easy portability to new hardware,
which in turn led to the UNIX operating system being used on a wide variety of computers.
In 1972, the pipe concept was invented.
Pong, the first arcade video game, was introduced by Nolan Bushnell in 1972. His company was called
Atari.
Operating Systems: VM/CMS; UNIX rewritten in C
Programming Languages: C
Computers: Intel 8008 (microprocessor); Rockwell PPS-4 (microprocessor); Fairchild PPS-25
(microprocessor)
Games: Pong; Magnavox Odysssey (first home video game console)
Technology: game console (Magnavox Odyssey); first scientific calculator (HP); first 32-bit
minicomputer; first arcade video game
1973
In 1973 National released the IMP microprocessor using PMOS.
In 1973 Intel released the faster NMOS 8080 8-bit microprocessor, the first in a long series of
microprocessors that led to the current Pentium.
ML (Meta Language) was created in 1973 by R. Milner of the University of Edinburgh. Functional
language implemented in LISP.
Actor is a mathematical model for concurrent computation first published bby Hewitt in 1973.
Actor is an object-oriented programming language. It was developed by the Whitewater
Group in Evanston, Ill. Language Finger, Maureen and Mike Mansfield Library, University
of Montana.
UNIX The UNIX kernal was rewritten in the C programming language.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1974
In 1974 Motorola released the 6800, which included two accumulators, index registers, and memorymapped I/O. Monolithic Memories introduced bit-slice microprocessing.
SQL (Standard Query Language) was designed by Donald D. Chamberlin and Raymond F. Boyce of IBM
in 1974.
AWK (first letters of the three inventors) was designed by Aho, Weinberger, and Kerninghan in 1974.
Word processing language based on regular expressions.
Alphard (named for the brightest star in Hydra) was designed by William Wulf, Mary Shaw, and Ralph
London of Carnegie-Mellon University in 1974. A Pascal-like language intended for data abstraction and
verification. Make use of the form, which combined a specification and an implementation, to give the
programmer control over the impolementation of abstract data types.
Alphard is a computer language designed to support the abstraction and verification
techniques required by modern programming methodology. Alphards constructs allow a
programmer to isolate an abstraction, specifying its behavior publicly while localizing
knowledge about its implementation. It originated from studies at both Carnegie-Mellon
University and the Information Sciences Institute. Language Finger, Maureen and Mike
Mansfield Library, University of Montana.
CLU began to be developed in 1974; a second version was designed in 1977. It consists of a
group of modules. One of the primary goals in its development was to provide clusters which
permit user-defined types to be treated similarly to built-in types. Language Finger, Maureen
and Mike Mansfield Library, University of Montana.
BSD Work on UNIX at University of California, Berkeley, the initial version of BSD UNIX.
Operating Systems: MVS, BSD UNIX
Programming Languages: Alphard; AWK; CLU; SQL
Computers: Intel 8080 (microprocessor); Motorola 6800 (microprocessor); CDC STAR-100 (100
MFLOPS)
Technology: Telenet (first commercial version of ARPANET)
1975
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
In 1975 Texas Instruments introduced a 4-bit slice microprocessor and Fairchild introduced the F-8
microprocessor.
Scheme, based on LISP, was created by Guy Lewis Steele Jr. and Gerald Jay Sussman at MIT in 1975.
Tiny BASIC created by Dr. Wong in 1975 runs on Intel 8080 and Zilog Z80 computers.
RATFOR (RATional FORtran) created by Brian Kernigan in 1975. Used as a precompiler for FORTRAN.
RATFOR allows C-like control structures in FORTRAN.
TENEX shell (also known as the TOPS shell) was created by Ken Greer by September 1975 and merged
into the C shell in December 1983. Ken Greer based the shell on the TENEX operating system (hence, the t
in tsch).
UNIX Fifth Edition licensed to universities for free.
Programming Languages: RATFOR; Scheme; TENEX shell; Tiny BASIC
Computers: Altair 880 (first personal computer); Fairchild F-8 (microprocessor); MOS Technology 6502
(microprocessor); Burroughs ILLIAC IV (150 MFLOPS)
Technology: single board computer; laser printer (commercial release by IBM)
1976
Design System Language, a forerunner of PostScript, is created in 1976. The Forth-like language handles
three dimensional databases.
SASL (Saint Andrews Static Language) is created by D. Turner in 1976. Intended for teaching functional
programming. Based on ISWIM. Unlimited data structures.
CP/M, an operating system for microcomputers, was created by Gary Kildall in 1976.
PWB shell The PWB shell or Mashey shell, abbreviated sh, was a variation of the Thompson shell that
had been augmented by John Mashey and others at Bell Labs. The Mashey shell was distributed with the
Programmers Workbench UNIX in 1976.
Operating Systems: CP/M
Programming Languages: Design System language; SASIL
Computers: Zilog Z-80 (microprocessor); Cray 1 (250 MFLOPS); Apple I
Software: PWB shell
Technology: inkjet printer; Alan Kays Xerox NoteTaker developed at Xerox PARC
1977
Icon, based on SNOBOL, was created in 1977 by faculty, staff, and students at the University of Arizona
under the direction of Ralph E. Griswold. Icon uses some programming structures similar to pascal and C.
Structured types include list, set, and table (dictionary).
OPS5 was created by Charles Forgy in 1977.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
FP was presented by John Backus in his 1977 Turing Award lecture Can Programming be Liberated From
the von Neumann Style? A Functional Style and its Algebra of Programs.
Modula (MODUlar LAnguage) was created by Niklaus Wirth, who started work in 1977. Modula-2 was
released in 1979.
Bourne shell The Bourne shell, created by Stephen Bourne at AT&Ts Bell Labs as a scripting language,
was released in 1977 as the default shell in the Version 7 Unix release distributed to colleges and universities.
It gained popularity with the publication of The UNIX Programming Environment by Brian W. Kernighan
and Rob Pike. The book was the first commercially published tutorial on shell programming.
BSD UNIX The University of California, Berkeley, released the Berkeley Software Distribution (BSD)
version of UNIX, based on the 6th edition of AT&T UNIX.
Programming Languages: Bourne shell; FP; Icon; Modula; OPS5
Computers: DEC VAX-11; Apple II; TRS-80; Commodore PET; Cray 1A
Games: Atari 2600 (first popular home video game consle)
1978
CSP was created in 1978 by C.A.R. Hoare.
C.A.R. Hoare wrote a paper in 1978 about parallel computing in which he included a
fragment of a language. Later, this fragment came to be known as CSP. In it, process
specifications lead to process creation and coordination. The name stands for Communicating
Sequential Processes. Later, the separate computer language Occam was based on CSP.
Language Finger, Maureen and Mike Mansfield Library, University of Montana.
C Shell The C shell, abbreviated csh, was created by Bill Joy, a graduate student at the University of
California, Berkeley. With additional work by Michael Ubell, Eric Allman, Mike OBrien, and Jim Kulp, it
was released in the 2BSD release of BSD Unix in 1978.
It became common to use the C shell for everyday interactive computing and to use the Bourne shell for
script programming.
UNIX The System V flavor of UNIX started.
Operating Systems: Apple DOS 3.1; VMS (later renamed OpenVMS)
Programming Languages: C shell; CSP
Computers: Intel 8086 (microprocessor)
Games: Space Invaders (arcade game using raster graphics; so popular in Japan that the government has to
quadruple its supply of Yen)
Technology: LaserDisc
1979
Modula-2 was released in 1979. Created by Niklaus Wirth, who started work in 1977.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
VisiCalc (VISIble CALculator) was created for the Apple II personal computer in 1979 by Harvard MBA
candidate Daniel Bricklin and programmer Robert Frankston.
REXX (REstructured eXtended eXecutor) was designed by Michael Cowlishaw of IBM UK Laboratories.
REXX was both an interpretted procedural language and a macro language. As a maco language, REXX can
be used in application software.
Work started on C with Classes, the language that eventually became C++.
Programming Languages: C with Classes; Modula-2; REXX
Computers: Motorola MC68000 (microprocessor); Intel 8088 (microprocessor)
Software: VisiCalc
Games: Lunar Lander (arcade video game, first to use vector graphics); Asteroids (vector arcade game);
Galaxian (raster arcade game, color screen); first Multi-USer Dungeon (MUD, written by Roy Trubshaw , a
student at Essex University, forrunner of modern massively multiplayer games); Warrior (first head-to-head
arcade fighting game)
Technology: first spreadsheet (VisiCalc); object oriented programming; compact disk; Usenet discussion
groups
1980s
Some operating systems from the 1980s include: AmigaOS, DOS/VSE, HP-UX, Macintosh, MS-DOS, and
ULTRIX.
The 1980s saw the commercial release of the graphic user interface, most famously the Apple Macintosh,
Commodore Amiga, and Atari ST, followed by MITs X Window System (X11) and Microsofts Windows.
1980
dBASE II was created in 1980 by Wayne Ratliff at the Jet Propulsion Laboratories in Pasadena,
California. The original version of the language was called Vulcan. Note that the first version of dBASE was
called dBASE II.
SmallTalk-80 released.
Operating Systems: OS-9
Computers: Commodore VIC-20; ZX80; Apple III
Software: dBASE II
Games: Battlezone (vector arcade video game, dual joystick controller and periscope-like viewer);
Berzerk (raster arcade video game, used primative speech synthesis); Centipede (raster arcade video game,
used trackball controller); Missile Command (raster arcade video game, used trackball controller); Defender
(raster arcade video game); Pac-Man (raster arcade video game); Phoenix (raster arcade video game, use of
musical score); Rally-X (raster arcade video game, first game to have a bonus round); Star Castle (vector
arcade video game, color provided by transparent plastic screen overlay); Tempest (vector arcade video
game, first color vector game); Wizard of Wor (raster arcade video game)
1981
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1982
ANSI C The American National Standards Institute (ANSI) formed a technical subcommittee, X3J11, to
create a standard for the C language and its run-time libraries.
InterPress, the forerunner of PostScript, was created in 1982 by John Warnock and Martin Newell at
Xerox PARC.
Operating Systems: SunOS
Programming Languages: ANSI C; InterPress
Computers: Cray X-MP; BBC Micro; Commodore C64 (first home computer with a dedicated sound
chip); Compaq Portable; ZX Spectrum; Atari 5200; Intel 80286 (microprocessor)
Games: BurgerTime (raster arcade video game); Dig Dug (raster arcade video game); Donkey Kong
Junior (raster arcade video game); Joust (raster arcade video game); Moon Patrol (raster arcade video game,
first game with parallax scrolling); Pole Position (raster arcade video game); Q*bert (raster arcade video
game); Robotron 2084 (raster arcade video game, dual joystick); Time Pilot (raster arcade video game); Tron
(raster arcade video game); Xevious (raster arcade video game, first game promoted with a TV commercial);
Zaxxon (raster arcade video game, first game to use axonometric projection)
Technology: MIDI; RISC; IBM PC compatibles
1983
Ada was first released in 1983 (ADA 83), with major releases in 1995 (ADA 95) and 2005 (ADA 2005).
Ada was created by the U.S. Department of Defense (DoD), originally intended for embedded systems and
later intended for all military computing purposes. Ada is named for Augusta Ada King, the Countess of
Lovelace, the first computer programmer inmodern times.
Concurrent Prolog was created in 1983 by Shapiro.
Parlog was created in 1983 by Clark and Gregory.
C++ was developed in 1983 by Bjarne Stroustrup at Bell Telephone Laboratories to extend C for object
oriented programming.
Turbo Pascal, a popular Pascal compiler, was released.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
The University of California at Berkeley released a version of UNIX that included TCP/IP.
tcsh The improved C shell, abbreviated tcsh, created by Ken Greer, was merged into the C shell in
December 1983. Ken Greer based the shell on the TENEX operating system (hence, the t in tsch). Mike
Ellis, Paul Placeway, and Christos Zoulas made major contributions to tcsh.
Korn shell The Korn shell, abbreviated ksh, was created by David Korn at AT&Ts Bell Labs and
announced at USENIX on July 14, 1983. Mike Veach and Pat Sullivan were also early contributors. The
Korn shell added C shell features to the Bourne shell.
In 1983, Richard Stallman founded the GNU project, which eventually provided the tools to go with Linux
for a complete operating system. The GNU project intended to create a complete open source UNIX-like
operating system, with GNU Hurd as the kernel. Richard Stallman created the GNU General Public License
(GPL).
Operating Systems: Lisa OS
Programming Languages: Ada; C++; Concurrent Prolog; Korn shell; Parlog; tcsh; Turbo Pascal
Computers: Apple IIe; Lisa; IBM XT; IBM PC Jr; ARM (microprocessor); Cray X-MP/4 (941 MFLOPS)
Games: Dragons Lair (raster arcade video game, first video game to use laserdisc video; note that the
gambling device Quarterhorse used the laserdisc first); Elevator Action (raster arcade video game); Gyruss
(raster arcade video game, used the musical score Toccata and Fugue in D minor by Bach); Mappy (raster
arcade video game, side scrolling); Mario Bros. (raster arcade video game); Spy Hunter (raster arcade video
game, musical score Peter Gunn); Star Wars (vector arcade video game, digitized samples from the movie of
actors voices); Tapper (raster arcade video game); Lode Runner (Apple ][E); Journey (arcade video game
includes tape of the song Separate Ways leading to licensed music in video games)
Technology: math coprocessor; PC harddisk
1984
Objective C, an extension of C inspired by SmallTalk, was created in 1984 by Brad Cox. Used to write
NextStep, the operating system of the Next computer.
Standard ML, based on ML, was created in 1984 by R. Milner of the University of Edinburgh.
PostScript was created in 1984 by John Warnock and Chuck Geschke at Adobe.
When the AT&T broke up in 1984 into Baby Bells (the regional companies operating local phone
service) and the central company (which had the long distance business and Bell Labs), the U.S. government
allowed them to start selling computers and computer software. UNIX broke into the System V (sys-five) and
Berkeley Software Distribution (BSD) versions. System V was the for pay version and BSD was the free
open source version.
AT&T gave academia a specific deadline to stop using encumbered code (that is, any of AT&Ts source
code anywhere in their versions of UNIX). This led to the development of free open source projects such as
FreeBSD, NetBSD, and OpenBSD, as well as commercial operating systems based on the BSD code.
Meanwhile, AT&T developed its own version of UNIX, called System V. Although AT&T eventually sold
off UNIX, this also spawned a group of commercial operating systems known as Sys V UNIXes.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
UNIX quickly swept through the commercial world, pushing aside almost all proprietary mainframe
operating systems. Only IBMs MVS and DECs OpenVMS survived the UNIX onslaught.
Some of the famous official UNIX versions include Solaris, HP-UX, Sequent, AIX, and Darwin. Darwin is
the UNIX kernel for Apples OS X, AppleTV, and iOS (used in the iPhone, iPad, and iPod).
The BSD variant started at the University of California, Berkeley, and includes FreeBSD, NetBSD,
OpenBSD, and DragonFly BSD.
Most modern versions of UNIX combine ideas and elements from both Sys-V and BSD.
Other UNIX-like operating systems include MINIX and Linux.
In 1984, Jim Gettys of Project Athena and Bob Scheifler of the MIT Laboratory for Computer Science
collaborated on a platform-independent graphcis system to link together heterogeneous multi-vendor systems.
Project Athena was a joint project between Digital Equipment Corporation (DEC), IBM, and MIT. X version
1 was released in May 1984.
Operating Systems: GNU project started; MacOS 1, X Window System (X11)
Programming Languages: Objective C; PostScript; Standard ML
Computers: Apple Macintosh; IBM AT; Apple IIc; MIPS R2000 (microprocessor); M-13 (U.S.S.R., 2.4
GFLOPS); Cray XMP-22
Software: Apple MacWrite; Apple MacPaint
Games: 1942 (raster arcade video game); Paperboy (raster arcade video game, unusual controllers, high
resolution display); Punch-Out (raster arcade video game, digitized voice, dual monitors)
Technology: WYSIWYG word processing; LaserJet printer; DNS (Domain Name Server); IDE interface
1985
Paradox was created in 1985 as a competitor to the dBASE family of relational data base languages.
PageMaker was created for the Apple Macintosh in 1985 by Aldus.
The Intel 80386 was the first Intel x86 microprocessor with a 32-bit instruction set and an MMU with
paging.
Operating Systems: GEM; AmigaOS; AtariOS; WIndows 1.0; Mac OS 2
Programming Languages: Paradox
Computers: Cray-2/8 (3.9 GFLOPS); Atari ST; Commodore Amiga; Apple Macintosh XL; Intel 80386
(microprocessor); Sun SPARC (microprocessor)
Software: Apple Macintosh Office; Aldus PageMaker (Macintosh only)
Games: Super Mario Bros.; Tetris (puzzle game; invented by Russian mathematician Alexey Pajitnov to
test equipment that was going to be used for artificial intelligence and speech recognition research);
Excitebike (first game with battery backup for saving and loading game play)
Technology: desktop publishing; EGA video card; CD-ROM; expanded memory (for IBM-PC
compatibles; Apple LaserWriter
1986
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Eiffel (named for Gustave Eiffel, designer of the Eiffel Tower) was released in 1986 by Bertrand Meyer.
Work started on September 14, 1985.
Eiffel is a computer language in the public domain. Its evolution is controlled by Nonprofit
International Consortium for Eiffel (NICE), but it is open to any interested party. It is intended to
treat software construction as a serious engineering enterprise, and therefore is named for the
French architect, Gustave Eiffel. It aims to help specify, design, implement, and change quality
software. Language Finger, Maureen and Mike Mansfield Library, University of Montana.
GAP (Groups, Algorithms, and Programming) was developed in 1986 by Johannes Meier, Werner Nickel,
Alice Niemeter, Martin Schnert, and others. Intended to program mathematical algorithms.
CLP(R) was developed in 1986.
In 1986, Maurice J. Bach of AT&T Bell Labs published The Design of the UNIX Operating System, which
described the System V Release 2 kernel, as well as some new features from release 3 and BSD.
Operating Systems: Mach; AIX; GS-OS; HP-UX; Mac OS 3
Programming Languages: CLP(R); Eiffel; GAP
Computers: Apple IIGS; Apple Macintosh Plus; Amstrad 1512; ARM2 (microprocessor); Cray XMP-48
Software: Apple Macintosh Programmers Workshop
Games: Metroid (one of first games to have password to save game proogress; first female protagonist in
video games, non-linear game play; RPG)
Technology: SCSI
1987
CAML (Categorical Abstract Machine Language) was created by Suarez, Weiss, and Maury in 1987.
Perl (Practical Extracting and Report Language) was created by Larry Wall in 1987. Intended to replace
the Unix shell, Sed, and Awk. Used in CGI scripts.
HyperCard was created by William Atkinson in 1987. HyperTalk was the scripting language built into
HyperCard.
Thomas and John Knoll created the program Display, which eventually became PhotoShop. The program
ran on the Apple Macintosh.
Adobe released the first version of Illustrator, running on the Apple Macintosh.
Minix Andrew S. Tanenbaum released MINIX, a simplified version of UNIX intended for academic
instruction.
Operating Systems: IRIX; Minix; OS/2; Windows 2.0; MDOS (Myarc Disk Operating System); Mac OS
4; Mac OS 5
Programming Languages: CAML; HyperTalk; Perl
Computers: Apple Macintosh II; Apple Macintosh SE; Acorn Archimedes; Connection Machine (first
massive parallel computer); IBM PS/2; Commodore Amiga 500; Nintendo Entertainment System
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Software: Apple Hypercard; Apple MultiFinder; Adobe Illustrator (Macintosh only; later ported to NeXT,
Silicon Graphics IRIX, Sun Solaris, and Microsoft Windows); Display (which eventually became ImagePro
and then Photoshop; Macintosh only); QuarkXPress (Macintosh only)
Games: Final Fantasy (fantasy RPG); The Legend of Zelda (first free form adventure game); Gran
Turismo (auto racing); Mike Tysons Punch Out (boxing sports game)
Technology: massive parallel computing; VGA video card; sound card for IBM-PC compatibles; Apple
Desktop Bus (ADB)
1988
CLOS, an object oriented version of LISP, was developed in 1988.
Mathematica was developed by Stephen Wolfram.
Oberon was created in 1986 by Niklaus Wirth.
Refined version of Design becomes ImagePro for the Apple Macintosh.
Operating Systems: OS/400; Mac OS 6
Programming Languages: CLOS; Mathematica; Oberon
Computers: Cray Y-MP; Apple IIc Plus
Software: ImagePro (which eventually became Photoshop; Macintosh only)
Games: Super Mario Bros. 2; Super Mario Bros 3 (Japanese release); Contra (side-scrolling shooter); Joh
Madden Football (football sports game)
Technology: optical chip; EISA bus
1989
ANSI C The American National Standards Institute (ANSI) completed the official ANSI C, called the
American National Standard X3.159-1989.
HTML was developed in 1989.
Miranda (named for a character by Shakespeare) was created in 1989 by D. Turner. Based on SASL and
ML. Lazy evaluation and embedded pattern matching.
Standard Interchange Languagewas developed in 1989.
BASH, which stands for Bourne Again SHell, was created by Brian Fox for the Free Software Foundation
and first released on June 7, 1989. bash combined features from the Bourne shell, the C shell, and the Korn
shell. bash is now the primary shell in both Linux and Mac OS X.
Operating Systems: NeXtStep; RISC OS; SCO UNIX
Programming Languages: ANSI C; BASH; HTML; Miranda; Standard Interchage Language
Computers: Intel 80486 (microprocessor); ETA10-G/8 (10.3 GFLOPS)
Software: Microsoft Office; first (pre-Adobe) version of Photoshop (Macintosh only)
Games: Sim; SimCity; Warlords (four-player shooter)
Technology: ATA interface, World Wide Web
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1990s
Some operating systems from the 1990s include: BeOS, BSDi, FreeBSD, NeXT, OS/2, Windows 95,
Windows 98, and Windows NT.
1990
Haskell was developed in 1990.
Tim Berners-Lee of the European CERN laboratory created the World Wide Web on a NeXT computer.
Z shell The Z shell, abbreviated zsh, was written by Paul Flastad in 1990 when he was a student at
Princton University.
In February of 1990, Adobe released the first version of the program PhotoShop (for the Apple
Macintosh). Version 2.0 of Photoshop, code named Fast Eddy, ships in the fall of 1990. Version
1.07 toolbar to right and original icons designed by John Knoll below.
1991
Python (named for Monty Python Flying Circus) was created in 1991 by Guido van Rossum. A scripting
language with dynamic types intended as a replacement for Perl.
Pov-Ray (Persistence of Vision) was created in 1991 by D.B.A. Collins and others. A language for
describing 3D images.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1992
Dylan was created in 1992 by Apple Computer and others. Dylan was originally intended for use with the
Apple Newton, but wasnt finished in time.
Oak, the forerunner of Java, was developed at Sun Microsystems.
In 1992 Unix System Laboratories sued Berkeley Software Design, Inc and the Regents of the University
of California to try to stop the distribution of BSD UNIX. The case was settled out of court in 1993 after the
judge expressed doubt over the validity of USLs intellectual property.
Operating Systems: Solaris; Windows 3.1; OS/2 2.0; SLS Linux; Tru64 UNIX
Programming Languages: Dylan; Oak
Computers: Cray C90 (1 GFLOP)
Games: Wolfenstein 3D (ffirst fully 3D rendered game engine); Mortal Kombat; NHLPA 93 (multiplayer
hockey sports game); Dune II (first real-time strategy game)
1993
Vendors such as Sun, IBM, DEC, SCO, and HP modified Unix to differentiate their products.
This splintered Unix to a degree, though not quite as much as is usually perceived. Necessity
being the mother of invention, programmers have created development tools that help them work
around the differences between Unix flavors. As a result, there is a large body of software based
on source code that will automatically configure itself to compile on most Unix platforms,
including Intel-based Unix.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Regardless, Microsoft would leverage the perception that Unix is splintered beyond hope, and
present Windows NT as a more consistent multi-platform alternative. Nicholas Petreley,
The new Unix alters NTs orbit, NC World
AppleScript, a scripting language for the Macintosh operating system and its application
softweare, was released by Apple Computers.
Version 2.5.1 of Photoshop released in 1993. It was one of the first programs to run native on a
PowerPC chip. First release of Windows version of Photoshop in April 1993. Toolbar for Photoshop
2.5.1 to the right.
Operating Systems: Windows NT 3.1; Stackware Linux; Debian GNU/Linux; Newton
Programming Languages: AppleScript
Computers: Cray EL90; Cray T3D; Apple Newton; Apple Macintosh TV; Intel Pentium
(microprocessor, 66MHz); Thinking Machines CM-5/1024 (59.7 GFLOPS); Fujitsu Numerical
Wind Tunnel (Japan, 124.50 GFLOPS); Intel Paragon XP/S 140 (143.40 GFLOPS)
Games: Myst (first puzzle-based computer adventure game; CD-ROM game for Macintosh);
Doom (made the first person shooter genre popular, pioneering work in immersive 3D graphics,
networked multiplayer gaming, and support for customized additions and modifications; also
proved that shareware distribution could work for game distribution); U.S. Senator Joseph
Lieberman holds Congressional hearings and attempts to outlaw violent games
Technology: MP3
1994
Work continued on Java with a version designed for the internet.
Version 3.0 of Photoshop released in 1994. It included Layers.
Operating Systems: Red Hat Linux
Programming Languages: Java
Computers: Cray J90; Apple Power Macintosh; Sony PlayStation; Fujitsu Numerical Wind Tunnel
(Japan, 170.40 GFLOPS)
Games: Super Metroid (RPG)
Technology: DNA computing
1995
Java (named for coffee) was created by James Gosling and others at Sun Microsystems and released for
applets in 1995. Original work started in 1991 as an interactive language under the name Oak. Rewritten for
the internet in 1994.
JavaScript (originally called LiveScript) was created by Brendan Elch at Netscape in 1995. A scripting
language for web pages.
PHP (PHP Hypertext Processor) was created by Rasmus Lerdorf in 1995.
Ruby was created in 1995 by Yukihiro Matsumoto. Alternative to Perl and Python.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1996
UML (Unified Modeling Language) was created by Grady Booch, Jim Rumbaugh, and Ivar Jacobson in
1996 by combining the three modeling languages of each of the authors.
Version 4.0 of Photoshop released in 1996. It included a controversial change in the key commands.
Operating Systems: MkLinux
Programming Languages: UML
Computers: Hitachi SR2201/1024 (Japan, 220.4 GFLOPS); Hitachi/Tsukuba CP=PACS/2048 (Japan,
368.2 GFLOPS)
Games: Tomb Raider and Lara Croft, Pokmon; Quake (first person shooter using new 3D rendering on
daughter boards); Super Mario 64 (3D rendering)
Technology: USB
1997
REBOL (Relative Expression Based Object language) was created by Carl SassenRath in 1997. Extensible
scripting language for internet and distributed computing. Has 45 types that use the same operators.
ECMAScript (named for the European standards group E.C.M.A.) was created in 1997.
Alloy, a structural modelling language, was developed at M.I.T.
Rhapsody The first developer version of Mac OS X released.on August 31, 1997.
To date, the most widely used desktop version of UNIX is Apples Mac OS X, combining the ground
breaking object oriented NeXT with some of the user interface of the Macintosh.
Operating Systems: Mac OS 8; Rhapsody
Programming Languages: Alley; ECMAScript; REBOL
Computers: AMD K6 (microprocessor); Intel Pentium II (microprocessor); PalmPilot; Intel ASCI
Red/9152 (1.338 TFLOPS)
Software: AOL Instant Messenger
Games: Final fantasy VII; Goldeneye 007 (one of the few successful movie to game transitions; based on
1995 James Bond movie Goldeneye); Castlevania: Symphony of the Night (2D fantasy RPG)
Technology: web blogging
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
1998
Version 5.0 of Photoshop released in 1998. It included the History palette.
Operating Systems: Windows 98
Computers: Apple iMac; Apple iMac G3; Intel Xeon (microprocessor)
Games: The Legend of Zelda: Ocarina of Time (fantasy RPG); Metal Gear Solid; Crash Bandicoot:
Warped
1999
Mac OS X Mac OS X Server 1.0, intended as a server operating system and not for general
desktop use, and Mac OS X Developer Preview were released on March 16, 1999.
Version 5.5 of Photoshop released in 1999. It was the first web ready version of Photoshop.
Toolbar for Photoshop 5.5 to the right.
Operating Systems: Mac OS 9; Mac OS X Server
Computers: PowerMac; AMD Athlon (microprocessor); Intel Pentium III (microprocessor);
BlackBerry; Apple iBook; TiVo; Intel ASCI Red/9632 (2.3796 TFLOPS)
2000s
Some operating systems from the 2000s include: Mac OS X, Syllable, Windows 2000, Windows
Server 2003, Windows ME, and Windows XP.
2000
D, designed by Walter Bright, is an object-oriented language based on C++, Java, Eiffel, and
Python.
C# was created by Anders Hajlsberg of Microsoft in 2000. The main language of Microsofts
.NET.
RELAX (REgular LAnguage description for XML) was designed by Murata Makoto.
Mac OS X The Public Beta version of Mac OS X was released on September 13, 2000.
Operating Systems: Mac OS 9; Windows ME; Windows 2000
Programming Languages: C#; D; RELAX
Computers: Intel Pentium 4 (microprocessor, over 1 GHz); Sony PlayStation 2; IBM ASCI White (7.226
TFLOPS)
Games: Tony Hawks Pro Skater 2 (skateboarding sports game); Madden NFL 2001 (football sports
game)
Technology: USB flash drive
2001
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
AspectJ (Aspect for Java) was created at the Palo Alto Research Center in 2001.
Scriptol (Scriptwriter Oriented Language) was created by Dennis G. Sureau in 2001. New control
structuress include for in, while let, and scan by. Variables and literals are objects. Supports XML as data
structure.
Mac OS X 10.0 Mac OS X 10.0 Cheetah was released on March 24, 2001.
Mac OS X 10.1 Mac OS X 10.1 Puma was released on September 25, 2001. It included DVD playback.
Operating Systems: Mac OS X 10.0 Cheetah; Mac OS X 10.1 Puma; Windows XP; z/OS
Programming Languages: AspectJ; Scriptol
Computers: Nintendo GameCube; Apple iPod; Intel Itanium (microprocessor); Xbox
Games: Halo
Technology: blade server
2002
Mac OS X 10.2 Mac OS X 10.2 Jaguar was released on August 24, 2002. It included the Quartz
Extreme graphics engine, a system-wide repository for contact information in the Address Book,
and an instant messaging client iChat.
Operating Systems: Mac OS X 10.2 Jaguar
Computers: Apple eMac; Apple iMac G4; Apple XServe; NEC Earth Simulator (Japan, 35.86 TFLOPS)
2003
Mac OS X 10.3 Mac OS X 10.3 Panther was released on October 24, 2003. It included a brushed
metal look, fast user switching, Expos (a Window manager), Filevault, Safari web browser, iChat
AV (which added videoconferencing), imporved PDF rendering, and better Microsoft Windows
interoperability.
Operating Systems: Windows Server 2003; Mac OS X 10.3 Panther
Computers: PowerPC G5; AMD Athlon 64 (microprocessor); Intel Pentium M (microprocessor)
Games: Final Fantasy Crystal Chronicles
2004
Scala was created February 2004 by Ecole Polytechnique Federale de Lausanne. Object oriented language
that implements Python features in a Java syntax.
Programming Languages: Scala
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
Computers: Apple iPod Mini; Apple iMac G5; Sony PlayStation Portable; IBM Blue Gene/L (70.72
TFLOPS)
Games: Fable
Technology: DualDisc; PCI Express; USB FlashCard
2005
Job Submission Description Language.
Mac OS X 10.4 Mac OS X 10.4 Tiger was released on April 29, 2005. It included Spotlight (a
find routine), Dashboard, Smart Folders, updated Mail program with Smart mailboxes, QuickTime
7, Safari 2, Automator, VoiceOver, Core Image, and Core Video.
Operating Systems: Mac OS X 10.4 Tiger
Programming Languages: Job Submission Description Language
Computers: IBM System z9; Apple iPod Nano; Apple Mac Mini; Intel Pentium D (microprocessor); Sun
UltraSPARC IV (microprocessor); Xbox 360
Games: Lego Star Wars
2006
Computers: Apple Intel-based iMac; Intel Core 2 (microprocessor); Sony PlayStation 3
Technology: Blu-Ray Disc
2007
Mac OS X 10.5 Mac OS X 10.5 Leopard was released on October 26, 2007. It included an
updated Finder, Time Machine, Spaces, Boot Camp, full support for 64-bit applications, new features
in Mail and iChat, and new security features.
Operating Systems: Apple iOS (for iPhone); Mac OS X 10.5 Leopard; Windows Vista
Computers: AMD K10 (microprocessor), Apple TV; Apple iPhone; Apple iPod Touch; Amazon Kindle
2008
Operating Systems: Google Android
Computers: Android Dev Phone 1; BlackBerry Storm; Intel Atom (microprocessor); MacBook Air; IBM
RoadRunner (1.026 PFLOPS); Dhruva (India, 6 TFLOPS)
2009
Mac OS X 10.6 Mac OS X 10.6 Snow Leopard was released on August 28, 2009. it included the
SquirrelFish javaScript interpreter, a rewrite of Finder in the Cocoa API, faster Time Machine
backups, more reliable disk ejects, a more powerful version on Preview, a faster version of Safari,
Microsoft Exchange Server support for Mail, iCal, and Address Book, QuickTime X, Grand Central Dispatch
for using multi-core processors, and OpenCL support.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
2010
Computers: Apple iPad; IBM z196 (microprocessor); Apple iPhone 4; Kobo eReader; HTC Evo 4G
2011
Mac OS X 10.7 Mac OS X 10.7 Lion was released on July 20, 2011. it included Launchpad,
auto-hiding scrollbars, and Mission Control.
Operating Systems: Mac OS X 10.7 Lion
2012
Mac OS X 10.8 Mac OS X 10.8 Mountain Lion was released on July 25, 2012. It included Game
Center, Notification Center, iCloud support, and more Chinese features.
Operating Systems: Mac OS X 10.8 Mountain Lion, Windows 8
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
critical reasoning
appendix C
summary
This appendix looks at critical reasoning.
This is the beginning of the much-promised appendix on critical reasoning. At the moment I am attempting
to get the basic structure laid down. This presentation will be too fast paced to be useful to a student, but will
help organize the themes that must be discussed to adequately present the material.
Students who want to learn this material can use this as an outline. Look up the appropriate topics in
Wikipedia and you will find a brief discussion on each topic. Wikipedia isnt organized for teaching, but
using this appendix as a study outline and Wikipedia for information should allow you to cobble together
your own lessons.
3/5/13 11:01 AM
classifications
summary
This chapter looks at classifications.
Classifying is the act of placing things into groups.
A famous example is the Dewey Decimal Classification used by some libraries.
3/5/13 11:01 AM
Fido is a referent in the concept of dogs. Cats and dogs are referents in the concept of mammals. Mammals
and reptiles are referents in the concept of animals.
rules of classification
There are two basic rules for good classifications:
(1) A set of classifications must be used according to a consistent principle that is mutually exclusive and
jointly exhaustive.
(2) Classifications must be made on essential attributes.
mutually exclusive
Mutually exclusive means that any particular species can only be in a single genus.
Green characters and Muppets are not mutually exclusive, because Kermit the Frog qualifies for both
genuses.
jointly exhaustive
Jointly exhaustive means that all of the species taken together (jointly) will make up the complete
(exhaustive) set of the genus.
The species felines (cats) and canines (dogs) are not jointly exhaustive for the genus mammals, because
there are still many additional creatures that qualify as mammals, but arent felines or canines.
consistent principle
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
essential attributes
It is important that the choice of rule for classification be based on an essential attribute.
Organizing books by the colors of the covers would create a bizarre library, while organizing books by
subject (such as the Dewey Decimal Classification) creates a library that is easy to use.
This is because the subject matter (or author) is an essential characteristic of a book, while the color of the
cover isnt. The color of the cover can change from printing to printing.
levels of organization
The levels of ogranization need to make sense.
As an example, the Dewey Decimal Classification is made up of ten classes. Each class is divided into ten
divisions. Each division is divided into ten sections.
Class 0 is Computer science, information & general works. Division 00 is Computer science, information
& general works. Section 004 is Data processing & computer science, 005 is Computer programming,
programs & data, and 006 is Special computer methods.
000 Computer science, information & general works
000 Computer science, information & general works
000 Computer science, knowledge & general works
001 Knowledge
002 The book (i.e. Meta writings about books)
003 Systems
004 Data processing & computer science
005 Computer programming, programs & data
006 Special computer methods
007 (Unassigned)
008 (Unassigned)
009 (Unassigned)
010 Bibliographies
020 Library & information sciences
030 Encyclopedias & books of facts
040 Biographies
050 magazines, journals & serials
060 Associaitons, organizations & museums
070 News media, journalism & publishing
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
outlines
The outlines that you were taught in school are an example of a proper organization of classifications.
Outlines developed specifically because they are useful tools for organizing a well-reasoned argument,
presentation, or essay.
I. first main topic
A. first subtopic
i. first inner topic
a. first innermost topic
b. second innermost topic
ii. second inner topic
a. first innermost topic
b. second innermost topic
B. second subtopic
i. first inner topic
a. first innermost topic
b. second innermost topic
ii. second inner topic
a. first innermost topic
b. second innermost topic
C. third subtopic
i. first inner topic
a. first innermost topic
b. second innermost topic
ii. second inner topic
a. first innermost topic
b. second innermost topic
II. second main topic
A. first subtopic
i. first inner topic
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
elements
In Western antiquity, the ancient Egyptians and the Greeks developed the idea of four or five basic
elements: fire, water, air, earth, and spirit. The Chinese developed the five basic elements of wood, fire, earth,
metal, and water.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
The Western elements represented the basic underlying principles of natures: three states of matter (earth =
solid, water = liquid, and air = gas) and energy (fire = energy). The spirit or soul was sometimes included as a
fifth element.
In modern Western civilization the word element was purposely reused to describe the fundamental
chemical elements that make up matter.
definition
summary
This chapter looks at definitions.
The first rule of philosophy is to define your terms. The reason is to create clarity and make sure that
everyone is discussing the same thing.
Churchill
There is a famous example from World War II. In American use, the term table means to put a matter
aside. In the rest of the English-speaking world, the term table means to begin discussion on a matter.
Winston Churchill describes how this became a source of confusion during World War II in his book The
Second World War, Volume 3: The Grand Alliance.
The enjoyment of a common language was of course a supreme advantage in all British and
American discussions. The British Staff prepared a paper which they wished to raise as a
matter of urgency, and informed their American colleagues that they wished to table it. To the
American Staff tabling a paper meant putting it away in a drawer and forgetting it. A long and
even acrimonious argument ensued before both parties realized that they were agreed on the
merits and wanted the same thing.
dictionaries
Why not just use a dictionary?
Dictionaries serve a different purpose. The definitions in dictionaries are about words. The definitions in
philosophy are about concepts.
Even though we have a different purpose for definition in critical reasoning, a dictionary definition can be
a good starting point for coming up with a useful philosophical definition.
A Websters style dictionary (there are many different brands, not one single version) attempts to record
how the common person uses the language. The first was Noah Websters 1928 edition of the American
Dictionary of the English Language.
An authorative dictionary attempts to record expert use of the language (such as the works of great
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
writers). Originally authorative dictionaries recorded how the king or queen wanted the language to be used.
The famous example is the Oxford English Dictionary, which is printed on behalf of British royalty.
A lexicon is a specialized dictionary that records the words and phrases for a particular use, such as a law
or science dictionary. The famous example is Blacks Law Dictionary.
boundaries
One of the most important aspects of a good definition is setting boundaries. A definition divides the
universe into that which fits the definition and that which doesnt fit the definition.
It is generallly easy to deal with cases that are clearly within a definition and cases that are clearly outside
of a definition. The problem is dealing well with the cases that are near the borders. In computer science,
these are sometimes called the corner cases.
clarity
The basic function of a definition in critical reasoning is to be clear. Our goal is to avoid confusion.
Working towards great clarity in definitions actually helps us better understand the topics we are thinking
about.
In the last half century or so there has been a lot of work on how language and words powerfully control
our thoughts and even what we are able to think of.
summary
A good definition should summarize the concept.
3/5/13 11:01 AM
A classic test of a good definition for critical reasoning is that it includes a genus and a differentia.
The genus lets us know the class of concepts.
The differentia (difference) lets us know how this particular concept difefrs from other similar concepts.
In normal speech it is common to leave the genus implied. For good critical reasoning, it is important to
actually state the genus.
In some cases the genus is essential for distinguishing between multiple meanings of a word.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
warning
At the time this paragraph was written the www.osdata.com was hosted on HostGator and at the time this
paragraph was written HostGator tech support used the last four digits of a credit card as their security
method for identifying the account holder. This is a well-known security flaw. The security hole was made
famous when a hacker used this hole at Apple and Amazon to get Mat Honans account information and wipe
out his hard drive. Both Apple and Amazon quickly changed their security procedures, but for some reason
HostGator (at the time this was written) hasnt bothered to change their security procedures. See
http://www.wired.com/gadgetlab/2012/08/apple-amazon-mat-honan-hacking/ for details.
For this reason, there is the distinct possibility that the forthfunctions file might have been hacked. Please
take the time to read through it and make sure it looks correct and doesnt have any suspicious or malicious
code inserted. I have a distinctive programming style, so something written by someone else might stand out
even if you dont understand what I have written. Of course, it is better if you understand the code and can
spot things that look wrong.
I apologize for this security hole, but my website is hosted for free for me and I have no control over the
hosting company chosen. The person providing me with the free hosting doesnt believe me that this is a
security flaw. This is one of the many hassles of poverty.
basic approach
This supplementary material describes a method for creating Forth-like routines for use in the BASH shell.
The data and return stacks will be stored using a pair of shell variables, one of which is an array and the
other is an ordinary scalar variable.
The Forth-like routines will be created as shell functions.
Everything will be stored in a shell function file that can be loaded manually or loaded as part of the
normal shell start-up.
Eventually I intend to write two sets of C source code, one that people can compile into their own copy of
the official BASH source code and one that is part of an entirely new open source shell project that doesnt
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
have the GNU infecting license. This alternative shell will be designed so that it can run on bare metal,
allowing it to be used to deploy embedded systems.
stacks
Forth uses two stacks: the main data stack and the return stack.
For the purposes of the BASH shell, we will implement both stacks with a combination of a top of stack
pointer variable and an array for the stack. The top of stack pointer will hold the array index of the top of the
stack. The stack will build up from the array indexed as one. An empty stack is indicated by having the top of
stack pointer variable point to the zero index of the stack array variable. The bottom of the stack will actually
be the one index of the stack array variable.
$
$
$
$
$
export DataStackPointer=0
declare -a DataStack; export DataStack
export ReturnStackPointer=0
declare -a ReturnStack; export ReturnStack
Thats it for the required variables! And, yes, those could all be placed on one line, but I spread them over
four lines for additional clarity.
One very important difference between the real Forth stacks and the Forth-like function stacks is that the
real Forth stacks deal with binary data and the Forth-like function stacks deal with character strings. Each
item on a real Forth stack is a binary number (or binary bit string). Even characters are stored by their binary
representation. Every item on a Forth-like function stack is a character string. Numbers are stored by their
character string representation. And an individual item on a Forth-like stack can be a character string of
arbitrary length, even an entire book.
functions
These are the functions for a Forth-like working environment. Not all of these functions exist in a real
Forth. Most of these functions are have modifications from standard Forth. Many standard Forth functions
are missing.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
In particular, this approach treats the stack as a stack of objects. No matter how much memory space an
object takes up, it only takes up a single stack slot. In a real Forth, data is stored on the stack as raw binary
strings, characters, or numbers and the programmer is responsble for keeping track of how much memory
every item actually uses.
stack functions
The double number versions of Forth stack functions are purposely left out. Our stack elements are
variable size objects and can be any size number, as well as strings or characters.
ShowDataStack
The ShowDataStack function shows the current contents of the data stack in the order of top of stack to
bottom of stack. This function is built for debugging purposes, but I am making it available for anyone to use.
$ ShowDataStack ()
>{
>
echo "stack size of " $DataStackPointer;
>
if [ "$DataStackPointer" -gt "0" ] ; then
>
loopcounter=$DataStackPointer
>
while [ $loopcounter -gt 0 ] ;
>
do
>
echo ${DataStack["$loopcounter"]}
>
let "loopcounter=$loopcounter - 1"
>
done
>
else
>
echo "the stack is empty"
>
fi
>
unset loopcounter #clear out variable
>} # end ShowDataStack
$
push
The push function pushes a single object onto the data stack. Forth doesnt have this word because simply
typing a number is sufficient to push the number onto the stack. This function will be used by other functions
to manipulate the data stack.
NOTE: This function does not yet have error checking. Need to check for exactly one item to push.
$ push ()
>{
>
let "DataStackPointer=$DataStackPointer + 1"; #preincrement
>
DataStack["$DataStackPointer"]="$1"; #push data item on top of stack
>} # end push
$
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
It is very important to notice that the item to be pushed onto the stack comes after the Forth-like function
which is very different than the normal order for Forth. This variation appears again in other Forth-like
functions and is done to work within the limits of the expectations of the BASH shell.
push,
Note that push will fail inside a series of piped commands or any other situation with a subshell.
pop
The pop function pops a single object from the data stack. Forth has a different function for this
functionality, but this function is intended for internal use by other functions to manipulate the data stack.
NOTE: This function does not yet have error checking. Need to check for empty stack.
$ pop ()
>{
>
let "DataStackPointer=$DataStackPointer - 1" #postdecrement
>} # end pop
$
popout
The popout function pops a single object from the data stack and prints it out for use in a pipe. Forth has a
different function for this functionality, but this function is intended for internal use by other functions to
manipulate the data stack.
Note that the value is printed without a new line character, so it might seem to disappear into the
beginning of the prompt.
Use the DOT function to pop and print with a new line.
NOTE: This function does not yet have error checking. Need to check for empty stack.
$ popout ()
>{
>
printf ${DataStack["$DataStackPointer"]} #pop data item from top of
stack and print
>
let "DataStackPointer=$DataStackPointer - 1" #postdecrement
>} # end popout
$
directory stack
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
You may have noticed that the C shell and BASH include the pushd, popd, and dirs command to
manipulate a stack of directories.
In case you never noticed these commands or have forgotten what they do, a quick summary:
allows the user or a script to push the current working directory onto a stack of directories and
change to a new named directory. The command acts slightly differently if you leave out a directory name.
We wont discuss that case because it takes us on a tangent from our current discussion.
pushd
You can simulate the normal use of the shell command pushd (named directory) with the Forth-like
function push and shell command cd.
$ push `pwd`; cd testdir
$
You have to explicitly place the current working directory onto the stack (using pwd and backticks) and
you have to issue a second command to actually change the directory. Dont worry about the extra steps,
because you will continue to use pushd for its intended purpose. We are showing the value of Forth through
analogy to something you already use to save time and effort.
popd
allows the user or a script to pop the directory stack and change to that directory.
You can simulate the normal use of the shell command popd with the Forth-like function pop and shell
command cd.
$ cd `pop`
$
Notice that we used the results of the pop function as the parameter for the shell command cd.
dirs
allows the user or a script to see all of the directories on the directory stack.
You can simulate the normal use of the shell command dirs with the Forth-like function ShowDataStack.
$ ShowDataStack
stack size of 1
/Users/admin
$
3/5/13 11:01 AM
arithmetic computations
Both Forth and the Forth-like functions work on much more than just directories.
A common use of Forth is computations.
Many of the scientific and engineering calculators (which used to be stand-alone devices, but are now
commonly apps) use a system called Reverse Polish Notation or RPN
An RPN calculator is a very powerful and efficient way of performing calculations.
For ordinary calculations, such as adding a series of numbers, RPN only saves a single keystroke. Thats
not enough to justify learning an entirely different method of calculating.
But when the calculations start to become complicated, RPN really shines.
With standard algebraic notation, you suddenly have to start typing a whole bunch of open and close
parenthesis and figure out all of your grouping and keep track of how many layers of parenthesis are
currently still open so that at the end of your calculation all of the open and close parenthesis balance out.
Anyone who has done any C programming knows about this hassle.
With RPN, there are no parenthesis. Once you learn to think in RPN, any arbitrarily complex algebraic
computation has a straight-forward and simple RPN expression!
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
You dramatically save typing, you avoid the headache of balancing nested parenthesis, and you have
confidence in the correctness of your straight-forward expression.
Well, both Forth and the Forth-like functions use the RPN system for computing.
You bring the power of scientific and engineering calculators to the BASH shell. Well, actually, you will
need to write a few additional functions of your own to have all of the features of your favorite scientific or
engineering calculator, but you have all of the tools available to finish out that task.
This means that you can use RPN calculations in all of your shell scripts.
strings
Both Forth and the Forth-like functions can also do manipulations of characters and character strings.
The Forth-like functions store all information as character strings, even numbers. This is different than real
Forth, but has its own advantages and disadvantages.
BASH and all of the other shells work with streams of characters. Storing everything (even numbers) on a
special string-oriented stack allows our Forth-like functions to play nice with the BASH shell.
This allows us to combine all of the power of the BASH shell with much of the power of Forth.
3/5/13 11:01 AM
With that introduction to the power of Forth and Forth-like functions, lets take a look at the actual Forthlike functions.
DUP
The DUP function is nearly the same functionality as the Forth word DUP (the difference is that this function
works with character strings). The top item on the stack is duplicated, increasing the size of the stack by one.
NOTE: This function does not yet have error checking. Need to check for empty stack.
$ DUP ()
>{
>
temporary=${DataStack["$DataStackPointer"]} #make temporary copy of
data item from top of stack
>
let "DataStackPointer=$DataStackPointer + 1" #preincrement
>
DataStack["$DataStackPointer"]=$temporary #store duplicate
>
unset temporary #clear out variable
>} # end DUP
$
qDUP
The qDUP function is nearly the same functionality as the Forth word ?DUP (the difference is that this
function works with character strings). The top item on the stack is duplicated only if it is non-zero,
increasing the size of the stack by one if the item on the top of the stack is non-zero.
NOTE: This function does not yet have error checking. Need to check for empty stack and non-number
object on top of stack.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
$ qDUP ()
>{
>
if [ ${DataStack["$DataStackPointer"]} -eq 0 ] ; then #test for zero
string on top of stack
>
return 0 #if zero, take no action, return OK
>
fi
>
temporary=${DataStack["$DataStackPointer"]} #make temporary copy of
data item from top of stack
>
let "DataStackPointer=$DataStackPointer + 1" #preincrement
>
DataStack["$DataStackPointer"]=$temporary #store duplicate
>
unset temporary #clear out variable
>} # end qDUP
$
OVER
The OVER function is nearly the same functionality as the Forth word OVER (the difference is that this
function works with character strings). The second item down from the top of the stack is duplicated,
increasing the size of the stack by one.
This function uses all caps, OVER, to prevent conflict with the already existing over UNIX tool for pretty
printing and scrolling source code on a terminal.
NOTE: This function does not yet have error checking. Need to check for empty stack or stack with only
one item in it.
$ OVER ()
>{
>
let "TemporaryPointer=$DataStackPointer - 1" #create pointer down one
from top of stack
>
temporary=${DataStack["$TemporaryPointer"]} #make temporary copy of
data item one down in stack
>
let "DataStackPointer=$DataStackPointer + 1" #preincrement
>
DataStack["$DataStackPointer"]=$temporary #store duplicate
>
unset temporary #clear out variable
>
unset TemporaryPointer #clear out variable
>} # end OVER
$
PICK
The PICK function is nearly the same functionality as the Forth word PICK (the difference is that this
function works with character strings). The nth item down from the top of the stack is duplicated, increasing
the size of the stack by one.
NOTE: This function does not yet have error checking. Need to check that a number was entered. Need to
check for stack that is deep enough.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
$ PICK ()
>{
>
let "TemporaryPointer=$DataStackPointer - $1" #create pointer down one
from top of stack
>
temporary=${DataStack["$TemporaryPointer"]} #make temporary copy of
data item one down in stack
>
let "DataStackPointer=$DataStackPointer + 1" #preincrement
>
DataStack["$DataStackPointer"]=$temporary #store duplicate
>
unset temporary #clear out variable
>
unset TemporaryPointer #clear out variable
>} # end PICK
$
The PICK function and the Forth word PICK should rarely be used. If you find yourself using this word
often, then you should refactor your code to be more simple.
DROP
The DROP function is nearly the same functionality as the Forth word DROP (the difference is that this
function works with character strings). Pops a single object from the top of the data stack.
NOTE: This function does not yet have error checking. Need to check for empty stack.
$ DROP ()
>{
>
let "DataStackPointer=$DataStackPointer - 1" #postdecrement
>} # end DROP
$
SWAP
The SWAP function is nearly the same functionality as the Forth word SWAP (the difference is that this
function works with character strings). The item on the top of the stack is swapped with the item one down
from the top of the stack.
NOTE: This function does not yet have error checking. Need to check that the stack has at least two items.
$ SWAP ()
>{
>
let "TemporaryPointer=$DataStackPointer - 1" #create pointer down one
from top of stack
>
temporary=${DataStack["$TemporaryPointer"]} #make temporary copy of
data item one down in stack
>
DataStack["$TemporaryPointer"]=${DataStack["$DataStackPointer"]} #move
the top item to 2nd location down
>
DataStack["$DataStackPointer"]=$temporary #put former 2nd down on top
of stack
>
unset temporary #clear out variable
>
unset TemporaryPointer #clear out variable
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
ROT
The ROT function is nearly the same functionality as the Forth word ROT (the difference is that this function
works with character strings). Rotate third item to top of stack.
NOTE: This function does not yet have error checking. Need to check that the stack has at least three
items.
$ ROT ()
>{
>
let "TemporaryPointer=$DataStackPointer - 2" #create pointer down two
from top of stack
>
let "SecondPointer=$DataStackPointer - 1" #create pointer down one
from top of stack
>
temporary=${DataStack["$TemporaryPointer"]} #make temporary copy of
data item one down in stack
>
DataStack["$TemporaryPointer"]=${DataStack["$SecondPointer"]} #move
the 2nd down item to 3rd location down
>
DataStack["$SecondPointer"]=${DataStack["$DataStackPointer"]} #move
the top item to 2nd location down
>
DataStack["$DataStackPointer"]=$temporary #put former 3rd down on top
of stack
>
unset temporary #clear out variable
>
unset TemporaryPointer #clear out variable
>
unset SecondPointer #clear out variable
>} # end ROT
$
ROLL
The ROLL function is nearly the same functionality as the Forth word ROLL (the difference is that this
function works with character strings). Rotates the nth object to the top of the stack.
NOTE: This function does not yet have error checking. Need to check for no user input.
$ ROLL ()
>{
>
if [ $DataStackPointer -gt "$1" ] ; then #check to make sure enough
items on stack
>
let "DestinationPointer=$DataStackPointer - $1"
>
SavedItem=${DataStack["$DestinationPointer"]} #save old item
>
let "SourcePointer =$DestinationPointer + 1"
>
LoopCounter=$1
>
while [ $LoopCounter -gt 0 ] ; #move data loop
>
do
>
DataStack["$DestinationPointer"]=${DataStack["$SourcePointer"]}
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
#move data
>
let "DestinationPointer=$DestinationPointer + 1" #post
increment
>
let "SourcePointer=$SourcePointer + 1" #post increment
>
let "LoopCounter=$LoopCounter - 1"
>
done
>
DataStack["$DataStackPointer"]=$SavedItem
>
unset LoopCounter #clear out variable
>
unset SavedItem #clear out variable
>
unset SourcePointer #clear out variable
>
unset DestinationPointer #clear out variable
>
fi # end if good input
>} # end ROLL
$
The ROLL function and the Forth word ROLL should rarely be used. If you find yourself using this word
often, then you should refactor your code to be more simple.
DEPTH
The DEPTH function is nearly the same functionality as the Forth word DEPTH (the difference is that this
function works with character strings). Find existing size of stack and then put that number on top of the
stack.
NOTE: This function does not yet have error checking.
$ DEPTH ()
>{
>
temporary=$DataStackPointer #save the existing depth of the stack
>
let "DataStackPointer=$DataStackPointer + 1" #preincrement
>
DataStack["$DataStackPointer"]=$temporary #push depth on top of stack
>} # end DEPTH
$
archive copy
You can obtain the latest copy of these functions at
http://www.osdata.com/programming/shell/forthfunctions place the file in an appropriate directory.
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html
3/5/13 11:01 AM
3/5/13 11:01 AM
Distributed on the honor system. Print and read free for personal, non-profit, and/or educational purposes.
If you like the book, you are encouraged to send a donation (U.S dollars) to Milo, PO Box 5237, Balboa
Island, California, USA 92662.
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011, 2012, 2013
Milo
file:///Volumes/Mac%20FreeAgent%20GoFlex%20Drive/from%20key%20disk/osdata%20stripped/programming/shell/shellbookTODAY.html