Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (4 votes)
50 views

Ebooks File Shell Programming in Unix Linux and OS X Stephen G. Kochan All Chapters

Kochan

Uploaded by

donhucedo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
50 views

Ebooks File Shell Programming in Unix Linux and OS X Stephen G. Kochan All Chapters

Kochan

Uploaded by

donhucedo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Download the full version of the textbook now at textbookfull.

com

Shell Programming in Unix Linux and OS X


Stephen G. Kochan

https://textbookfull.com/product/shell-
programming-in-unix-linux-and-os-x-stephen-g-
kochan/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Wicked Cool Shell Scripts 101 Scripts for Linux OS X and


UNIX Systems Dave Taylor

https://textbookfull.com/product/wicked-cool-shell-
scripts-101-scripts-for-linux-os-x-and-unix-systems-dave-taylor/

textbookfull.com

Mastering Linux Shell Scripting a practical guide to Linux


command line Bash scripting and Shell programming Ebrahim

https://textbookfull.com/product/mastering-linux-shell-scripting-a-
practical-guide-to-linux-command-line-bash-scripting-and-shell-
programming-ebrahim/
textbookfull.com

Mastering Linux shell scripting a practical guide to Linux


command line Bash scripting and Shell programming Second
Edition. Edition Mokhtar Ebrahim
https://textbookfull.com/product/mastering-linux-shell-scripting-a-
practical-guide-to-linux-command-line-bash-scripting-and-shell-
programming-second-edition-edition-mokhtar-ebrahim/
textbookfull.com

Issues Decisive for China s Rise or Fall An International


Law Perspective Yuwa Wei

https://textbookfull.com/product/issues-decisive-for-china-s-rise-or-
fall-an-international-law-perspective-yuwa-wei/

textbookfull.com
Biography of a yogi : Paramahansa Yogananda and the
origins of modern yoga 1st Edition Foxen

https://textbookfull.com/product/biography-of-a-yogi-paramahansa-
yogananda-and-the-origins-of-modern-yoga-1st-edition-foxen/

textbookfull.com

Automata and Computability: A Programmer’s Perspective


Ganesh Gopalakrishnan

https://textbookfull.com/product/automata-and-computability-a-
programmers-perspective-ganesh-gopalakrishnan/

textbookfull.com

Android Studio 3 0 Development Essentials Android 8


Edition Neil Smyth

https://textbookfull.com/product/android-studio-3-0-development-
essentials-android-8-edition-neil-smyth/

textbookfull.com

Visualizing Graph Data MEAP edition Corey Lanum

https://textbookfull.com/product/visualizing-graph-data-meap-edition-
corey-lanum/

textbookfull.com

On Critical Pedagogy 2nd Edition Henry A. Giroux

https://textbookfull.com/product/on-critical-pedagogy-2nd-edition-
henry-a-giroux/

textbookfull.com
Demography of Russia: From the Past to the Present 1st
Edition Tatiana Karabchuk

https://textbookfull.com/product/demography-of-russia-from-the-past-
to-the-present-1st-edition-tatiana-karabchuk/

textbookfull.com
Shell Programming
in Unix, Linux
and OS X
Fourth Edition

Stephen G. Kochan
Patrick Wood

800 East 96th Street, Indianapolis, Indiana 46240


Shell Programming in Unix, Linux and OS X, Fourth Edition
Copyright © 2017 by Pearson Education, Inc.

ISBN-13: 978-0-13-4449600-9
ISBN-10: 0-13-449600-0
Printed in the United States of America
First Printing: August 2016
The Library of Congress Control Number is on file.
Brief Contents

Introduction 1

1 A Quick Review of the Basics 5

2 What Is the Shell? 39

3 Tools of the Trade 51

4 And Away We Go 93

5 Can I Quote You on That? 105

6 Passing Arguments 121

7 Decisions, Decisions 131

8 'Round and 'Round She Goes 163

9 Reading and Printing Data 185

10 Your Environment 209

11 More on Parameters 239

12 Loose Ends 255

13 Rolo Revisited 273

14 Interactive and Nonstandard Shell Features 289

A Shell Summary 321

B For More Information 359

Index 363
Contents
Introduction 1
How This Book Is Organized 2
Accessing the Free Web Edition 3

1 A Quick Review of the Basics 5


Some Basic Commands 5
Displaying the Date and Time: The date Command 5
Finding Out Who’s Logged In: The who Command 5
Echoing Characters: The echo Command 6
Working with Files 6
Listing Files: The ls Command 7
Displaying the Contents of a File: The cat Command 7
Counting the Number of Words in a File: The wc Command 7
Command Options 8
Making a Copy of a File: The cp Command 8
Renaming a File: The mv Command 8
Removing a File: The rm Command 9
Working with Directories 9
The Home Directory and Pathnames 10
Displaying Your Working Directory: The pwd Command 12
Changing Directories: The cd Command 12
More on the ls Command 15
Creating a Directory: The mkdir Command 17
Copying a File from One Directory to Another 18
Moving Files Between Directories 19
Linking Files: The ln Command 20
Removing a Directory: The rmdir Command 23
Filename Substitution 24
The Asterisk 24
Matching Single Characters 25
Filename Nuances 27
Spaces in Filenames 27
Other Weird Characters 28
Standard Input/Output, and I/O Redirection 28
Standard Input and Standard Output 28
Output Redirection 30
Input Redirection 32
Pipes 33
Filters 35
Standard Error 35
More on Commands 36
Typing More Than One Command on a Line 36
Sending a Command to the Background 36
The ps Command 37
Command Summary 37

2 What Is the Shell? 39


The Kernel and the Utilities 39
The Login Shell 40
Typing Commands to the Shell 43
The Shell’s Responsibilities 44
Program Execution 45
Variable and Filename Substitution 47
I/O Redirection 48
Hooking up a Pipeline 49
Environment Control 49
Interpreted Programming Language 50

3 Tools of the Trade 51


Regular Expressions 51
Matching Any Character: The Period (.) 51
Matching the Beginning of the Line: The Caret (^) 53
Matching the End of the Line: The Dollar Sign $ 53
Matching a Character Set: The [...] Construct 55
Matching Zero or More Characters: The Asterisk (*) 57
Matching a Precise Number of Subpatterns: \{...\} 59
Saving Matched Characters: \(...\) 61
cut 64
The -d and -f Options 66
paste 68
The -d Option 69
The -s Option 70
sed 70
The -n Option 72
Deleting Lines 73
tr 74
The -s Option 76
The -d Option 77
grep 78
Regular Expressions and grep 81
The -v Option 82
The -l Option 82
The -n Option 83
sort 84
The -u Option 84
The -r Option 85
The -o Option 85
The -n Option 86
Skipping Fields 87
The -t Option 87
Other Options 88
uniq 88
The -d Option 89
Other Options 90

4 And Away We Go 93
Command Files 93
Comments 96
Variables 97
Displaying the Values of Variables 98
Undefined Variables Have the Null Value 100
Filename Substitution and Variables 101
The ${variable} Construct 102
Built-in Integer Arithmetic 103

5 Can I Quote You on That? 105


The Single Quote 105
The Double Quote 109
The Backslash 111
Using the Backslash for Continuing Lines 112
The Backslash Inside Double Quotes 112
Command Substitution 114
The Back Quote 114
The $(...) Construct 115
The expr Command 119

6 Passing Arguments 121


The $# Variable 122
The $* Variable 123
A Program to Look Up Someone in the Phone Book 124
A Program to Add Someone to the Phone Book 125
A Program to Remove Someone from the Phone Book 127
${n} 128
The shift Command 128

7 Decisions, Decisions 131


Exit Status 131
The $? Variable 132
The test Command 135
String Operators 135
An Alternative Format for test 139
Integer Operators 140
File Operators 142
The Logical Negation Operator ! 143
The Logical AND Operator -a 143
Parentheses 144
The Logical OR Operator -o 144
The else Construct 145
The exit Command 147
A Second Look at the rem Program 147
The elif Construct 148
Yet Another Version of rem 151
The case Command 153
Special Pattern-Matching Characters 155
The -x Option for Debugging Programs 157
Back to the case 159
The Null Command : 160
The && and || Constructs 161

8 'Round and 'Round She Goes 163


The for Command 163
The $@ Variable 166
The for Without the List 167
The while Command 168
The until Command 170
More on Loops 174
Breaking Out of a Loop 174
Skipping the Remaining Commands in a Loop 176
Executing a Loop in the Background 177
I/O Redirection on a Loop 177
Piping Data into and out of a Loop 178
Typing a Loop on One Line 179
The getopts Command 180

9 Reading and Printing Data 185


The read Command 185
A Program to Copy Files 185
Special echo Escape Characters 187
An Improved Version of mycp 188
A Final Version of mycp 190
A Menu-Driven Phone Program 193
The $$ Variable and Temporary Files 198
The Exit Status from read 199
The printf Command 202

10 Your Environment 209


Local Variables 209
Subshells 210
Exported Variables 211
export -p 215
PS1 and PS2 216
HOME 217
PATH 217
Your Current Directory 225
CDPATH 226
More on Subshells 227
The .Command 227
The exec Command 230
The (...) and { ...; } Constructs 231
Another Way to Pass Variables to a Subshell 234
Your .profile File 235
The TERM Variable 236
The TZ Variable 237

11 More on Parameters 239


Parameter Substitution 239
${parameter} 239
${parameter:-value} 240
${parameter:=value} 241
${parameter:?value} 241
${parameter:+value} 242
Pattern Matching Constructs 242
${#variable} 244
The $0 Variable 245
The set Command 246
The -x Option 246
set with No Arguments 247
Using set to Reassign Positional Parameters 247
The -- Option 248
Other Options to set 251
The IFS Variable 251
The readonly Command 254
The unset Command 254

12 Loose Ends 255


The eval Command 255
The wait Command 257
The $! Variable 257
The trap Command 258
trap with No Arguments 259
Ignoring Signals 260
Resetting Traps 261
More on I/O 261
<&- and >&- 262
In-line Input Redirection 262
Shell Archives 264
Functions 268
Removing a Function Definition 271
The return Command 271
The type Command 271

13 Rolo Revisited 273


Data Formatting Considerations 273
rolo 274
add 277
lu 278
display 278
rem 280
change 281
listall 283
Sample Output 284

14 Interactive and Nonstandard Shell Features 289


Getting the Right Shell 289
The ENV File 290
Command-Line Editing 291
Command History 292
The vi Line Edit Mode 292
Accessing Commands from Your History 294
The emacs Line Edit Mode 296
Accessing Commands from Your History 298
Other Ways to Access Your History 300
The history Command 300
The fc Command 301
The r Command 301
Functions 303
Local Variables 303
Automatically Loaded Functions 303
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Integer Arithmetic 303
Integer Types 304
Numbers in Different Bases 305
The alias Command 307
Removing Aliases 309
Arrays 309
Job Control 315
Stopped Jobs and the fg and bg Commands 316
Miscellaneous Features 317
Other Features of the cd Command 317
Tilde Substitution 318
Order of Search 319
Compatibility Summary 319

A Shell Summary 321


Startup 321
Commands 321
Comments 322
Parameters and Variables 322
Shell Variables 322
Positional Parameters 322
Special Parameters 323
Parameter Substitution 324
Command Re-entry 326
The fc Command 326
vi Line Edit Mode 326
Quoting 329
Tilde Substitution 329
Arithmetic Expressions 330
Filename Substitution 331
I/O Redirection 331
Exported Variables and Subshell Execution 332
The (...) Construct 332
The { ...; } Construct 332
More on Shell Variables 333
Functions 333
Job Control 333
Shell Jobs 333
Stopping Jobs 334
Command Summary 334
The : Command 334
The . Command 334
The alias Command 335
The bg Command 335
The break Command 336
The case Command 336
The cd Command 337
The continue Command 338
The echo Command 338
The eval Command 339
The exec Command 339
The exit Command 340
The export Command 340
The false Command 341
The fc Command 341
The fg Command 342
The for Command 342
The getopts Command 343
The hash Command 344
The if Command 344
The jobs Command 347
The kill Command 347
The newgrp Command 347
The pwd Command 348
The read Command 348
The readonly Command 349
The return Command 349
The set Command 350
The shift Command 352
The test Command 352
The times Command 354
The trap Command 355
The true Command 356
The type Command 356
The umask Command 356
The unalias Command 356
The unset Command 357
The until Command 357
The wait Command 358
The while Command 358

B For More Information 359


Online Documentation 359
Documentation on the Web 360
Books 360
O’Reilly & Associates 360
Pearson 361

Index 363
Introduction

It’s no secret that the family of Unix and Unix-like operating systems has emerged over the last
few decades as the most pervasive, most widely used group of operating systems in computing
today. For programmers who have been using Unix for many years, this came as no surprise:
The Unix system provides an elegant and efficient environment for program development.
That’s exactly what Dennis Ritchie and Ken Thompson sought to create when they developed
Unix at Bell Laboratories way back in the late 1960s.

Note
Throughout this book we’ll use the term Unix to refer generically to the broad family of
Unix-based operating systems, including true Unix operating systems such as Solaris
as well as Unix-like operating systems such as Linux and Mac OS X.

One of the strongest features of the Unix system is its wide collection of programs. More than
200 basic commands are distributed with the standard operating system and Linux adds to it,
often shipping with 700–1000 standard commands! These commands (also known as tools)
do everything from counting the number of lines in a file, to sending electronic mail, to
displaying a calendar for any desired year.

But the real strength of the Unix system comes not from its large collection of commands but
from the elegance and ease with which these commands can be combined to perform far more
sophisticated tasks.

The standard user interface to Unix is the command line, which actually turns out to be a
shell, a program that acts as a buffer between the user and the lowest levels of the system itself
(the kernel ). The shell is simply a program that reads in the commands you type and converts
them into a form more readily understood by the system. It also includes core programming
constructs that let you make decisions, loop, and store values in variables.

The standard shell distributed with Unix systems derives from AT&T’s distribution, which
evolved from a version originally written by Stephen Bourne at Bell Labs. Since then,
the IEEE has created standards based on the Bourne shell and the other more recent shells.
The current version of this standard, as of this writing, is the Shell and Utilities volume
of IEEE Std 1003.1-2001, also known as the POSIX standard. This shell is what we use as the
basis for the rest of this book.

The examples in this book were tested on a Mac running Mac OS X 10.11, Ubuntu Linux 14.0,
and an old version of SunOS 5.7 running on a Sparcstation Ultra-30. All examples, with the
2 Introduction

exception of some Bash examples in Chapter 14, were run using the Korn shell, although all of
them also work fine with Bash.

Because the shell offers an interpreted programming language, programs can be written, modified,
and debugged quickly and easily. We turn to the shell as our first choice of programming
language and after you become adept at shell programming, you will too.

How This Book Is Organized


This book assumes that you are familiar with the fundamentals of the system and command
line; that is, that you know how to log in; how to create files, edit them, and remove them;
and how to work with directories. In case you haven’t used the Linux or Unix system for a
while, we’ll examine the basics in Chapter 1, “A Quick Review of the Basics.” In addition,
filename substitution, I/O redirection, and pipes are also reviewed in the first chapter.

Chapter 2, “What Is the Shell?,” reveals what the shell really is, how it works, and how it ends
up being your primary method of interacting with the operating system itself. You’ll learn
about what happens every time you log in to the system, how the shell program gets started,
how it parses the command line, and how it executes other programs for you. A key point
made in Chapter 2 is that the shell is just another program; nothing more, nothing less.

Chapter 3, “Tools of the Trade,” provides tutorials on tools useful in writing shell programs.
Covered in this chapter are cut, paste, sed, grep, sort, tr, and uniq. Admittedly, the
selection is subjective, but it does set the stage for programs that we’ll develop throughout the
remainder of the book. Also in Chapter 3 is a detailed discussion of regular expressions, which
are used by many Unix commands, such as sed, grep, and ed.

Chapters 4 through 9 teach you how to put the shell to work for writing programs. You’ll
learn how to write your own commands; use variables; write programs that accept arguments;
make decisions; use the shell’s for, while, and until looping commands; and use the read
command to read data from the terminal or from a file. Chapter 5, “Can I Quote you on
That?”, is devoted entirely to a discussion of one of the most intriguing (and often confusing)
aspects of the shell: the way it interprets quotes.

By that point in the book, all the basic programming constructs in the shell will have been
covered, and you will be able to write shell programs to solve your particular problems.

Chapter 10, “Your Environment,” covers a topic of great importance for a real understanding
of the way the shell operates: the environment. You’ll learn about local and exported variables;
subshells; special shell variables, such as HOME, PATH, and CDPATH; and how to set up
your .profile file.

Chapter 11, “More on Parameters,” and Chapter 12, “Loose Ends,” tie up some loose ends, and
Chapter 13, “Rolo Revisited,” presents a final version of a phone directory program called
rolo that is developed throughout the book.
Accessing the Free Web Edition 3

Chapter 14, “Interactive and Nonstandard Shell Features,” discusses features of the shell that
either are not formally part of the IEEE POSIX standard shell (but are available in most
Unix and Linux shells) or are mainly used interactively instead of in programs.

Appendix A, “Shell Summary,” summarizes the features of the IEEE POSIX standard shell.

Appendix B, “For More Information,” lists references and resources, including the Web sites
where different shells can be downloaded.

The philosophy this book uses is to teach by example. We believe that properly chosen
examples do a far better job of illustrating how a particular feature is used than ten times as
many words. The old “A picture is worth …” adage seems to apply just as well to coding.

We encourage you to type in each example and test it on your own system, for only by doing
can you become adept at shell programming. Don’t be afraid to experiment. Try changing
commands in the program examples to see the effect, or add different options or features to
make the programs more useful or robust.

Accessing the Free Web Edition


Your purchase of this book in any format includes access to the corresponding Web Edition,
which provides several special features to help you learn:
■ The complete text of the book online
■ Interactive quizzes and exercises to test your understanding of the material
■ Updates and corrections as they become available

The Web Edition can be viewed on all types of computers and mobile devices with any modern
web browser that supports HTML5.

To get access to the Web Edition of Shell Programming with Unix, Linux, and OS X all you need to
do is register this book:

1. Go to www.informit.com/register.

2. Sign in or create a new account.

3. Enter ISBN: 9780134496009.

4. Answer the questions as proof of purchase.

The Web Edition will appear under the Digital Purchases tab on your Account page. Click the
Launch link to access the product.
1
A Quick Review
of the Basics

This chapter provides a review of the Unix system, including the file system, basic commands,
filename substitution, I/O redirection, and pipes.

Some Basic Commands


Displaying the Date and Time: The date Command
The date command tells the system to print the date and time:
$ date
Thu Dec 3 11:04:09 MST 2015
$

date prints the day of the week, month, day, time (24-hour clock, the system’s time zone),
and year. Throughout the code examples in this book, whenever we use boldface type like
this, it’s to indicate what you, the user, type in. Normal face type like this is used to
indicate what the Unix system prints. Italic type is used for comments in interactive sequences.

Every Unix command is submitted to the system with the pressing of the Enter key. Enter
says that you are finished typing things in and are ready for the Unix system to do its thing.

Finding Out Who’s Logged In: The who Command


The who command can be used to get information about all users currently logged in to the
system:
$ who
pat tty29 Jul 19 14:40
ruth tty37 Jul 19 10:54
steve tty25 Jul 19 15:52
$
6 Chapter 1 A Quick Review of the Basics

Here, three users are logged in: pat, ruth, and steve. Along with each user ID is listed the
tty number of that user and the day and time that user logged in. The tty number is a unique
identification number the Unix system gives to each terminal or network device that a user is
on when they log into the system.

The who command also can be used to get information about yourself:
$ who am i
pat tty29 Jul 19 14:40
$

who and who am i are actually the same command: who. In the latter case, the am and i are
arguments to the who command. (This isn’t a good example of how command arguments work;
it’s just a curiosity of the who command.)

Echoing Characters: The echo Command


The echo command prints (or echoes) at the terminal whatever else you happen to type on the
line (there are some exceptions to this that you’ll learn about later):
$ echo this is a test
this is a test
$ echo why not print out a longer line with echo?
why not print out a longer line with echo?
$ echo
A blank line is displayed
$ echo one two three four five
one two three four five
$

You will notice from the preceding example that echo squeezes out extra blanks between
words. That’s because on a Unix system, the words are important while the blanks are only
there to separate the words. Generally, the Unix system ignores extra blanks (you’ll learn more
about this in the next chapter).

Working with Files


The Unix system recognizes only three basic types of files: ordinary files, directory files, and
special files. An ordinary file is just that: any file on the system that contains data, text,
program instructions, or just about anything else. Directories, or folders, are described later in
this chapter. Finally, as its name implies, a special file has a special meaning to the Unix system
and is typically associated with some form of I/O.

A filename can be composed of just about any character directly available from the keyboard
(and even some that aren’t) provided that the total number of characters contained in the
name is not greater than 255. If more than 255 characters are specified, the Unix system
simply ignores the extra characters.
Working with Files 7

The Unix system provides many tools that make working with files easy. Here we’ll review
some of the basic file manipulation commands.

Listing Files: The ls Command


To see what files you have stored in your directory, you can type the ls command:
$ ls
READ_ME
names
tmp
$

This output indicates that three files called READ_ME, names, and tmp are contained in the
current directory. (Note that the output of ls may vary from system to system. For example,
on many Unix systems ls produces multicolumn output when sending its output to a
terminal; on others, different colors may be used for different types of files. You can always
force single-column output with the –1 option—that’s the number one.)

Displaying the Contents of a File: The cat Command


You can examine the contents of a file by using the cat command. (That’s short for “concatenate,”
if you’re thinking feline thoughts.) The argument to cat is the name of the file whose contents
you want to examine.
$ cat names
Susan
Jeff
Henry
Allan
Ken
$

Counting the Number of Words in a File: The wc Command


With the wc command, you can get a count of the total number of lines, words, and characters
contained in a file. Once again, the name of the file is expected to be specified as the argument
to this command:
$ wc names
5 7 27 names
$

The wc command lists three numbers followed by the filename. The first number represents the
number of lines in the file (5), the second the number of words (7), and the third the number
of characters (27).
8 Chapter 1 A Quick Review of the Basics

Command Options
Most Unix commands allow the specification of options at the time a command is executed.
These options generally follow the same format:
-letter

That is, a command option is a minus sign followed immediately by a single letter. For
example, to count just the number of lines contained in a file, the option -l (that’s the letter l)
is given to the wc command:
$ wc -l names
5 names
$

To count just the number of characters in a file, the -c option is specified:


$ wc -c names
27 names
$

Finally, the -w option can be used to count the number of words contained in the file:
$ wc -w names
7 names
$

Some commands require that the options be listed before the filename arguments. For example,
sort names -r is acceptable, whereas wc names -l is not. Still, the former is unusual and
most Unix commands are designed for you to specify command options first, as exemplified by
wc -l names.

Making a Copy of a File: The cp Command


To make a copy of a file, use the cp command. The first argument to the command is the name
of the file to be copied (known as the source file), and the second argument is the name of the
file to place the copy into (known as the destination file). You can make a copy of the file names
and call it saved_names as follows:
$ cp names saved_names
$

Execution of this command causes the contents of the file names to be copied into a new file
named saved_names. As with many Unix commands, the fact that no output other than a
command prompt was displayed after the cp command was typed indicates that the command
executed successfully.

Renaming a File: The mv Command


A file can be renamed with the mv (“move”) command. The arguments to the mv command
follow the same format as the cp command. The first argument is the name of the file to be
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Working with Directories 9

renamed, and the second argument is the new name. So, to change the name of the file
saved_names to hold_it, for example, the following command would do the trick:
$ mv saved_names hold_it
$

Be careful! When executing an mv or cp command, the Unix system does not care whether the
file specified as the second argument already exists. If it does, the contents of the file will be
lost. For example, if a file called old_names exists, executing the command
cp names old_names

would copy the filenames to old_names, destroying the previous contents of old_names in the
process. Similarly, the command
mv names old_names

would rename names to old_names, even if the file old_names existed prior to execution of
the command.

Removing a File: The rm Command


Use the rm command to remove a file from the system. The argument to rm is simply the name
of the file to be removed:
$ rm hold_it
$

You can remove more than one file at a time with the rm command by simply specifying all
such files on the command line. For example, the following would remove the three files wb,
collect, and mon:
$ rm wb collect mon
$

Working with Directories


Suppose that you had a set of files consisting of various memos, proposals, and letters.
Further suppose that you had another set of files that were computer programs. It would seem
logical to group this first set into a directory called documents and the latter into a directory
called programs. Figure 1.1 illustrates such a directory organization.

documents programs

plan dact sys.A new.hire no.JSK AMG.reply wb collect mon

Figure 1.1 Example directory structure


10 Chapter 1 A Quick Review of the Basics

The file directory documents contains the files plan, dact, sys.A, new.hire, no.JSK, and
AMG.reply. The directory programs contains the files wb, collect, and mon. At some point,
you may decide to further categorize the files in a directory. This can be done by creating
subdirectories and then placing each file into the appropriate subdirectory. For example,
you might want to create subdirectories called memos, proposals, and letters inside your
documents directory, as shown in Figure 1.2.

documents programs

memos proposals letters wb collect mon

plan dact sys.A new.hire no.JSK AMG.reply

Figure 1.2 Directories containing subdirectories

documents contains the subdirectories memos, proposals, and letters. Each of these
subdirectories in turn contains two files: memos contains plan and dact; proposals contains
sys.A and new.hire; and letters contains no.JSK and AMG.reply.

Although each file in a given directory must have a unique name, files contained in different
directories do not. So you could have a file in your programs directory called dact, even
though a file by that name also exists in the memos subdirectory.

The Home Directory and Pathnames


The Unix system always associates each user of the system with a particular directory. When
you log in to the system, you are placed automatically into your own directory (called your
home directory).

Although the location of users’ home directories can vary from one system to the next,
let’s assume that your home directory is called steve and that this directory is actually a
subdirectory of a directory called users. Therefore, if you had the directories documents and
programs, the overall directory structure would actually look something like Figure 1.3.
A special directory named / (pronounced “slash”) is shown at the top of the directory tree.
This directory is known as the root.

Whenever you are “inside” a particular directory (called your current working directory), the
files contained within that directory are immediately accessible, without specifying any path
information. If you want to access a file from another directory, you can either first issue a
command to “change” to the appropriate directory and then access the particular file, or you
can specify the particular file by its pathname.
Working with Directories 11

users


pat steve ruth

documents programs

memos proposals letters wb collect mon

plan dact sys.A new.hire no.JSK AMG.reply

Figure 1.3 Hierarchical directory structure

A pathname enables you to uniquely identify a particular file to the Unix system. In the
specification of a pathname, successive directories along the path are separated by the slash
character /. A pathname that begins with a slash character is known as a full or absolute
pathname because it specifies a complete path from the root. For example, the pathname
/users/steve identifies the directory steve contained within the directory users. Similarly,
the pathname /users/steve/documents references the directory documents as contained
in the directory steve within users. As a final example, the pathname /users/steve/
documents/letters/AMG.reply identifies the file AMG.reply contained along the appropriate
directory path.

To help reduce the typing that would otherwise be required, Unix provides certain notational
conveniences. A pathname that does not begin with a slash is known as a relative pathname:
the path is relative to your current working directory. For example, if you just logged in to the
system and were placed into your home directory /users/steve, you could directly reference
the directory documents simply by typing documents. Similarly, the relative pathname
programs/mon could be typed to access the file mon contained inside your programs directory.

By convention, .. always references the directory that is one level higher than the current
directory, known as the parent directory. For example, if you were in your home directory
/users/steve, the pathname .. would reference the directory users. If you had issued
the appropriate command to change your working directory to documents/letters, the
pathname .. would reference the documents directory, ../.. would reference the directory
steve, and ../proposals/new.hire would reference the file new.hire contained in the
proposals directory. There is usually more than one way to specify a path to a particular
file, a very Unix-y characteristic.
12 Chapter 1 A Quick Review of the Basics

Another notational convention is the single period., which always refers to the current
directory. That’ll become more important later in the book when you want to specify a shell
script in the current directory, not one in the PATH. We’ll explain this in more detail soon.

Displaying Your Working Directory: The pwd Command


The pwd command is used to help you “get your bearings” by telling you the name of your
current working directory.

Recall the directory structure from Figure 1.3. The directory that you are placed in after you log
in to the system is called your home directory. You can assume from Figure 1.3 that the home
directory for the user steve is /users/steve. Therefore, whenever steve logs in to
the system, he will automatically be placed inside this directory. To verify that this is the
case, the pwd (print working directory) command can be issued:
$ pwd
/users/steve
$

The output from the command verifies that steve’s current working directory is /users/
steve.

Changing Directories: The cd Command


You can change your current working directory by using the cd command. This command
takes as its argument the name of the target or destination directory.

Let’s assume that you just logged in to the system and were placed in your home directory,
/users/steve. This is depicted by the arrow in Figure 1.4.

You know that two directories are directly “below” steve’s home directory: documents and
programs. This can be easily verified at the terminal by issuing the ls command:
$ ls
documents
programs
$

The ls command lists the two directories documents and programs the same way it listed
other ordinary files in previous examples.
Working with Directories 13

users


pat steve ruth

documents programs

memos proposals letters wb collect mon

plan dact sys.A new.hire no.JSK AMG.reply

Figure 1.4 Current working directory is steve

To change your current working directory, issue the cd command, followed by the name of the
new directory:
$ cd documents
$

After executing this command, you will be placed inside the documents directory, as depicted
in Figure 1.5.

users


pat steve ruth

documents programs

memos proposals letters wb collect mon

plan dact sys.A new.hire no.JSK AMG.reply

Figure 1.5 cd documents


Random documents with unrelated
content Scribd suggests to you:
deposition as a boulder-clay has been amply verified. It has now,
moreover, been paralleled by a very similar rock discovered by A. C.
Coleman in the Huronian beds of Canada.
CHAPTER V
IGNEOUS ROCKS

INTRODUCTION[58]
Igneous rocks, those varied masses that have consolidated from a
state of fusion, attracted attention in the eighteenth century through
their active appearance in volcanoes. James Hutton in 1785 showed
that the crystalline granite of the Scottish highlands "had been made
to invade that country in a fluid state." More than a hundred years,
however, elapsed before geologists on the continent of Europe were
willing to connect superficial lavas with the materials exposed by
denudation in consolidated cauldrons of the crust.
It is interesting therefore to note that G. P. Scrope in 1825 treated of
granite, without apology or hesitation, in a work entitled
"Considerations on Volcanoes." So far from separating deep-seated
from superficial products, Scrope wrote of the molten magma in the
crust as "the general subterranean bed of lava." He conceived this
fundamental magma, "the original or mother-rock," to be capable of
consolidating as ordinary granite. Successive meltings and physical
modifications of this granite gave rise, in his view, to all the other
igneous rocks. Scrope laid no stress, however, on chemical variations
within the magma, but urged that the transitions observable
between different types of igneous material established a community
of origin.
The connexion between lavas and highly crystalline deep-seated
rocks, so simply accepted by Scrope, was worked out some fifty
years later by J. W. Judd for areas in Hungary and in the Inner
Hebrides. The features displayed in thin sections under the
microscope were used by Judd, in a series of papers, to substantiate
his views; but in France and Germany these features became the
source of subtle distinctions between the igneous rocks of Cainozoic
and pre-Cainozoic days. The lavas, in which some glassy matter
could be traced, were said to be typically post-Cretaceous, and
essentially different from those earlier types in which glass was
replaced by finely crystalline matter; while the coarsely crystalline
igneous rocks were uniformly regarded as pre-Cainozoic. Glassy
rocks, such as pitchstone, interbedded contemporaneously in
Permian or Devonian strata, were described as "vitreous porphyries,"
while those known to be of post-Cretaceous date might be styled
andesites, trachytes, or rhyolites. Luckily common sense has recently
triumphed in this matter, and the relative scarcity of glassy types of
igneous rocks in early geological formations has been recognised as
due to the readiness with which glass undergoes secondary
crystallisation. The discussion has ended by showing that we have
no evidence of world-wide changes in the types of material erupted
during geological time.
At the present day, attention has been focused on the processes that
go on in subterranean cauldrons, in the hope of explaining the
differences between one type of extruded rock and another.
Doctrines of descent have been elaborated, and one of the most
subtle systems of classification[59] has been based upon characters
that the igneous rock might have possessed, had circumstances not
imparted others to it during the process of consolidation. The
principle of this classification is, however, obviously correct, if we
wish to trace back a rock bearing certain characters at the present
day to the molten source from which it came.

CHARACTERS OF IGNEOUS ROCKS


The characters of igneous rocks vary considerably according as they
have consolidated under atmospheric pressure only, or under that of
superincumbent rocks. We must remember also that submarine
lavas have to sustain a pressure of an extra atmosphere for every
thirty feet of depth, or 400 atmospheres at 2000 fathoms, and that
such rocks have a claim to be regarded as deep-seated. The gases
that igneous rocks contain, probably as essential features of the
molten magma, and at a temperature above their critical points,
escape to a large extent near or at the surface of the earth. The
bubbles raised in lava, whereby it is rendered scoriaceous, and the
clouds of vapour rising from cooling lava-flows and from the throat
of a volcano in eruption, are sufficient evidences of this process. The
extremely liquid lavas of Kilauea in Hawaii, which emit very little
vapour, are notable as exceptions. In the case of masses that cool
underground, the retention of gases, and ultimately of liquids, until a
very late stage of consolidation retards crystallisation until
temperatures are reached lower than those at which it starts in
surface-flows. As A. Harker points out[60], "the loss of these
substances, by raising the melting-points in the magma, may be the
immediate cause of crystallisation, quite as much as any actual
cooling."
The formation of crystals in lavas is rapid, and the average crystals
are therefore small, and often felted together in a mesh, the
interstices of which are filled by residual glass.
Slowness of cooling is the really important factor that affects the size
of crystals, that is, the coarseness of grain, in igneous rocks.
Pressure may promote crystallisation, by raising the melting-points
of minerals; but, after a certain maximum effect in this direction, it is
quite possible that an increase of pressure may actually lower the
melting-points, and cause one or other mineral to remain in solution
in the magma. It is not clear how pressure can affect the size of any
constituent, except by bringing about conditions under which it can
go on growing, while other constituents remain in solution, or do not
grow so fast.
Such conditions may arise from the aid given by pressure to the
retention of what French geologists have called agents
minéralisateurs. Several familiar minerals, for instance albite,
orthoclase, and quartz, require the presence of water for their
formation. Volatile substances, not utilised in the ultimate product,
no doubt similarly assist the formation of many rock-forming
minerals. Occasionally, moreover, as in the development of the micas
and certain of the silicates known as zeolites, some proportion of
hydrogen is retained by minerals thus crystallising from the magma.
Micas appear to require the presence of fluorine for their
development. J. P. Iddings[61], however, lays stress in this case on
the chemical activity of hydrogen at high temperatures.
Igneous rocks, unless cooled with singular rapidity, thus contain
crystals of various kinds. In lavas, these may form the globular
aggregates known as spherulites[62], or may accumulate as a
compact ground of minute grains and needles, not quite resolvable
with the microscope. In many rocks of slightly coarser grain, a
compact lithoidal or stony texture is set up, which the microscope
resolves into an aggregate of crystalline rods or granules. Such
compact rocks are often styled felsitic. In other types, as in ordinary
granite, the constituent minerals are easily distinguished with the
naked eye.
The order in which these constituents have developed is sometimes
clear from the inclusion of one mineral in another. When two
substances are dissolved in one another, there is a certain proportion
between them, varying with the substances, which allows them to
crystallise at the same time, instead of in succession. This eutectic
proportion, when attained by two mineral substances in a magma,
brings about a complete interlocking of their crystals, as is seen in
the quartz and alkali-felspar of the rock known as "graphic granite."
The order of crystallisation of minerals from an ordinary non-eutectic
magma is profoundly affected by the proportions in which their
constituents are present in the mass.
The minerals, when they have separated out, are found to be mostly
silicates. A few oxides, such as rutile, magnetite, and ilmenite, may
occur, the two latter being especially common where iron is an
important constituent of the rock. But almost all igneous rocks
consist largely of one or more species of felspar, silica being here
combined with alumina, potash, soda, and lime. Free silica may
remain, and separates as quartz, or rarely as tridymite. Pale mica
occurs in many rocks of deep-seated origin. In contrast with these
light-coloured minerals, iron, magnesium, and part of the calcium,
appear in another series of silicates, usually dark in colour, and this
series may be broadly styled "ferromagnesian." The pyroxenes, of
which augite is the type, the amphiboles, of which hornblende is the
type, dark mica (mostly biotite), and olivine, are the ordinary
ferromagnesian minerals.
Broadly, then, igneous rocks divide themselves by texture into (i)
those which are completely crystalline, and in which the minerals are
distinctly visible; (ii) those which are completely crystalline, but in
which the crystals are so small as to give rise to a compact lithoidal
ground-mass; and (iii) those in which some glass is present. The
third group may appear lithoidal, or in other cases actually glassy, to
the unaided eye.
This mode of division is justified from a natural history point of view.
The first group includes rocks that have consolidated slowly
underground. The second includes rocks cooled more quickly, on the
margins of magma-basins, or as offshoots from them, filling cracks
in the surrounding rocks, and producing wall-like masses known as
dykes. The third group appears mostly in dykes and lava-flows.
Where a dyke has intruded among heated rocks and undergoes no
sudden chilling, it may become coarsely crystalline, even though
comparatively small. Some dykes exhibit a chilled margin of glass
along their bounding surfaces, and are none the less completely
crystalline at the centre, where cooling has been slow. No structure
is peculiar to dyke-rocks, nor can a class be established for such
rocks on chemical or mineralogical grounds, even though a few
special types of igneous rock may at present be known only among
these minor intrusive bodies.
Fig. 14. Side of a Volcanic Cone. Ash-layer of 1906 on the
west flank of Vesuvius. Cliffs of the exploded crater
of Monte Somma behind.
The fine-grained layers of volcanic dust, commonly spoken of as ash,
and the coarser tuffs, in which lumps of scoriaceous lava are clearly
visible, bridge the gap between sedimentary and igneous rocks. The
dust, during a great eruption, is distributed by wind over hundreds
of square miles of country. The tuffs, deposited nearer the orifice of
the volcano, vary in coarseness from day to day, and exhibit marked
stratification. Ash-beds and tuffs may be laid out in lakes or in the
sea, and their layers may then include organic remains. Waves may
round their particles on the shore, and may sift them till only a
coarse volcanic sand remains.
After an eruption, the newly deposited ash and tuff usually form
obvious layers on the surface of the country. Landslips on the side of
the volcanic cone may reveal sections of the new coating and of
previously stratified material (Fig. 14). In certain districts,
sedimentary and other rocks torn off from below form a large part of
the fragmental deposits of volcanic action. The characteristic
volcanic cone is itself due to the greater accumulation of tuffs and
ashes near the vent (Fig. 15).
The loose tuffs formed of scoriæ allow water to percolate easily
through them, and a cone of fairly coarse material resists the
weather well. The remarkable freshness of the extinct "cinder-cones"
of Auvergne was thus long ago explained by Lyell. Surfaces of ash,
on the other hand, are easily washed down by rain in the form of
dangerous mud-flows, which spread across the lowlands, and give
rise to compact clays, shrinking as they dry.
Fig. 15. Tuff-Cone with Tuff-Beds at the base. Puy de la
Vache, Puy-de-Dôme, France.
Lava-flows are masses of molten rock that have welled out from the
vent, without being torn to pieces by the explosion of the gases that
they contained. The rapidity of their flow depends on their chemical
composition, on the amount of gases present, and on the
temperature at which they are extruded. The more highly siliceous
lavas, for a given temperature, are more viscous than those towards
the basaltic end of the series, which contain only about 48 per cent.
of silica. A lava of considerable fluidity will consolidate in somewhat
thin sheets with smooth and ropy surfaces. A less fluid type will
become markedly scoriaceous, where the vapours endeavour to
escape from it; the rugged crust formed on its upper cooling surface
will be broken up by the continued movement of the more liquid
mass below, and the blocks thus formed may become rolled over the
advancing front of the flow and entombed in the portion that has not
yet consolidated.
The surface of ordinary lava-flows remains rough for centuries, and
only slowly crumbles down before weathering to form a soil. While
tuff-beds provide light and fertile lands, the lava-streams remain
marked out among them, as sinuous bands of rock, given over to an
irregular growth of woodland. By repeated outflows, lavas tend to fill
up the interspaces between the earlier streams, just as these have
filled up the hollows in the country over which they spread. A
uniform surface thus arises, and lava-plains eventually bury a varied
land of hill and dale. Where a number of small vents have opened,
perhaps along parallel fissures in the earth, the flooding of the
country with igneous rock may lead to an appearance of
stratification in masses extending over hundreds of square miles.
Sections in the igneous series, however, show that the individual
flows dove-tail into and overlap one another, more rapidly than is the
case with the lenticular masses that constitute an ordinary
sedimentary series.
After the constituents of the lava have begun to crystallise, and
when the rock may be considered solid, cracks due to contraction
are set up. The upper part of the flow, radiating its heat and parting
with its gases into the air above, solidifies comparatively rapidly, and
cracks arise without much regularity. Now and then, columnar
structure, like that of dried starch, appears on a small scale, the
columns starting from various oblique surfaces of cooling, and lying
in consequence in various directions in the rock.
J. P. Iddings shows that curvature of the columns will result if one
portion of the surface loses heat more rapidly than another. As the
contraction-cracks bounding the columns spread inwards, the layer
reached by them at any time in the lava will be farther in from a part
of the surface where cooling is rapid than it will be from a part
where it is slow. Hence the layer in the lava where contractional
stresses are producing cracks, i.e. the layer reached at any time by
the inner ends of the contraction-columns, will be a curved one, and
its curvature will increase as it occupies positions more and more
removed from the surface of the lava-flow. The axes of the
contraction-columns, as they spread, are perpendicular to this layer,
and the columns will thus curve as their development proceeds.
The base of a massive lava-flow, however, cools under much more
uniform conditions, and the columns, stretching upwards from the
ground and produced by slow contraction, give rise to the regular
prismatic structures long ago known as "giants' causeways." The
original Giant's Causeway in the county of Antrim is the lower part of
a basaltic flow, exposed by denudation on the shore. Fingal's Cave in
Staffa owes its tough compact roof to the preservation of that
portion of the flow which cooled downwards from the upper surface.
G. P. Scrope[63] long ago observed this dual structure in columnar
lavas.
The columns, or the more irregular joint-blocks that sometimes
represent them, are often subdivided by further contraction into
spheroids, the coats of which peel off, as the rock weathers, like
those of an onion. The curved cross-joints of massive columns, now
convex upwards, now concave, represent the same tendency
towards globular contraction.
A lava-flow is sometimes divided into large rudely spheroidal masses,
which fit into one another, and which show signs of more rapid
cooling on their surfaces. These were particularly observed on the
mountains near Mont Genèvre by Cole and Gregory[64], who
compared the forms to "pillows or soft cushions pressed upon and
against one another." It was suggested that these forms were
produced by the seething of viscid lavas, masses being heaved up
and falling over, and the outer layers having time to cool in a glassy
state before they were deformed by contact with others. This pillow-
structure has been widely recognised, and J. J. H. Teall has
remarked how often "pillow-lavas" are associated with radiolarian
cherts. He regarded them, therefore, as of submarine origin. Sir A.
Geikie[65], moreover, stated that the spheroidal sack-like structure
was produced by the flow of such lavas into water or watery silt.
This acute suggestion has now been verified by Tempest
Anderson[66], who has observed in Samoa the chilling of the lobes of
lava, as they are thrust off into the sea and washed over by the
waves. H. Dewey and J. S. Flett[67] have pointed out that pillow-
structure commonly occurs in lavas in which there has been a
conversion of lime soda felspars into albite, a change frequent in a
series of rocks which they call the "spilitic suite." The importation of
soda is attributed to vapours entering soon after the consolidation of
the rock, and it is urged that any excess of sodium silicate must
have escaped into the sea-water in which the pillow-lavas were
produced. Hence radiolaria will flourish in the neighbourhood
(presuming that a decomposition of the silicate can be brought
about), and their remains will in time form flint in the hollows of the
lavas. The paper quoted contains numerous references to previous
work, and is a suggestive example of how petrographic study may
go hand in hand with the appreciation of rocks from a natural history
point of view. It is only characteristic of the subject of petrology that
G. Steinmann[68] has with equal ingenuity explained the relations
between radiolaria and spilitic lavas by reminding us that gravity-
determinations show an excess of basic material under the oceans
and of lighter material, rich in silica, under continental land. Hence,
when deep-sea deposits are crumpled by earth-movements, basic
types of rock, graduating even into serpentine, become associated
with radiolarian chert, partly as extruded lavas, but usually as
intrusive sheets injected at the epoch of mountain-building.
The characters of igneous rocks in dykes, that is, of those types that
have consolidated in fissures, resemble in many respects the
characters of lava-flows. Chilling being usually equal on both
surfaces, glassy or compact types of rock occur on both sides, and
the dyke is, as previously observed, more crystalline in the centre.
Columnar structures arise from both surfaces, the dyke also
shrinking parallel to its margins. In the outer layers so formed, the
columns are small, and they increase in diameter nearer the centre.
In small dykes and veins, the columns may run continuously from
side to side; in larger ones, they meet along a central surface, which
forms, on weathering, a plane of weakness in the rock. Dykes may
thus become worn away, decay spreading from the central region,
and leaving the more resisting and more glassy portions clinging to
the bounding walls.
Where, however, the surrounding rocks are more easily worn away
than the igneous invader, as very often happens, the dykes stand
out on the surface as great ribs and walls.
The rocks cooled in the deep-seated cauldrons, under what are
styled plutonic conditions, have parted with their gases so slowly
that they do not show scoriaceous structure. They may become very
coarsely crystalline, like many of the Scandinavian granites;
minerals, moreover, may be produced which are unstable or difficult
to form nearer the surface. Crystals developed in plutonic
surroundings become carried forward when the partially consolidated
mass is pressed up to a volcanic orifice, and may undergo resorption
on the way. Many, however, escape, and impart a porphyritic
structure to lavas. The deep-seated rock, from causes that promote
the growth of one mineral and the retention of another in solution,
may also become "porphyritic" in situ, smaller crystals, or even a
eutectic intergrowth, finally filling in the ground.
The viscidity of igneous rocks may cause any of the types to show a
fluidal structure. Constituents already formed become dragged along
in parallel series as the mass moves forward. Sometimes a group of
spherulites, or a knot of "felsitic" matter caused by the dense growth
of embryo-crystals, is stretched out into a sheet, and on fractured
surfaces a banded structure characterises the mass. These banded
rocks record, in their crumpled and obviously fluidal layers, the
formerly molten condition of the mass. Even completely crystalline
rocks may show parallel arrangement of their minerals, owing to
flow during the last stages of consolidation, or to pressure from the
walls of the cauldron, influencing the positions taken up by crystals
that possess a rod-like or platy form.

Fig. 16. Granite invading Mica-Schist. Clifton, near Cape


Town. Adjacent sections were studied by Charles
Darwin (see p. 156).
The conspicuously banded structures in some crystalline rocks that
are often grouped with the metamorphic gneisses may, however, be
best explained by their composite origin, and the history of the
structure is easily determinable in the field. A common case arises
where a granite magma, perhaps already bearing crystals, is
intruded, under pressure operating from a distance, into a well-
bedded series of sedimentary rocks. The sediments open up like the
leaves of a book and admit the invader along their planes of
stratification. Even limestone may thus become interlaminated with
an igneous rock, just as basalt has been known to separate the
annual rings of trees involved in it. This intimate admixture permits
of extensive mineral changes, and the two types of rock, probably
very different in geological age, become welded together into a
composite gneiss, both members of which have influenced one
another by contact-metamorphism, often across a wide stretch of
country (Fig. 16).
Intrusive igneous rocks in the field will, however, ordinarily prove
their character by cutting somewhere across the prevalent structure
of the district. When the materials that elsewhere form dykes
penetrate between strata for considerable distances as intrusive
sheets, they may yet be traced to some point where they have made
use of a crack across the bedding. The necks or plugs of old volcanic
centres sometimes seem to occupy orifices drilled, or rather
shattered, by explosion right through the overlying obstacles. The
approximately circular necks in South Africa, filled by brecciated
masses of serpentinous rock, are notable examples. The
underground cauldrons themselves, when brought to light by
denudation, are represented by regions of crystalline rock, which
may have various relations to their surroundings. We may trace, in
every case, upon their margins the ramifying veins that first proved
to James Hutton that granite was younger than the rocks among
which it lay. But the portion exposed may be merely the top of a
huge body or batholite of igneous matter, stretching far down into
the crust; or it may be part of a localised knot, which filled up some
cavity provided for it by earth-movement, oozing in step by step as
room was made for its advance. In the latter case, it was originally
bounded above by some series of strata which was arched up as a
dome or as an anticline. Or possibly strata have been moved apart
from one another, the upper ones sliding over the lower ones and at
the same time bulging upwards, so as to leave a cavity of roughly
hemispherical form. Such a space, allowing relief from pressure, will
be occupied by igneous rock, which may or may not have a direct
root through the stratum underneath it. The igneous mass may in
such cases be merely an expansion of a large intrusive sheet. It
sends off veins into the roof above, and can only be distinguished
from a batholite by the presence of stratified rock beneath it.
Occurrences of this kind were first described in the Henry Mountains
of Utah by G. K. Gilbert, who gave them the name of "stone-
cisterns" or laccoliths, a word now commonly written laccolites. It
may be questioned if the expansion of the gases in the intruding
igneous rock is sufficient in itself to form the laccolitic dome. The
igneous rock has probably been pressed into position by the forces
that produced the earth-movements.
In many cases, batholites seem to have worked their way upwards
without any relation to earth-movements in the district. The
processes by which they come into place among other rocks are
worthy of separate consideration.

THE INTRUSION OF LARGE BODIES OF


IGNEOUS ROCK
Attention has been already called to the composite gneisses formed
by the intrusion of an igneous magma between the leaves, as it
were, of sediments. Such occurrences are often seen on the margins
of batholites or of any kind of igneous dome, and they no doubt
represent the picking off of layer after layer from the walls
surrounding the intrusive mass. If these layers can become absorbed
into the igneous rock, the crest of the dome can advance, and the
dome itself can widen, so long as sufficient heat is supplied to it
from below. Space is found for the intrusive mass at the expense of
the marginal rocks; but it is obvious that the portions absorbed
merely add to the bulk of the igneous material. The composition of
the latter must also undergo modification. Its great size, reaching as
it does far down into the crust, in comparison with the quantity of
matter absorbed in the upper regions, may render such modification
very difficult to trace beyond the latest zone of contact.
Petrologists differ very widely as to the extent to which igneous
masses assume their place in the upper regions of the crust by
processes of "stoping," absorption, and assimilation. The statement,
however, in a recent work that "the assimilation hypothesis" is "still
supported by some French geologists" is calculated to surprise those
who recognise the trend of modern opinion both in America and on
the continent of Europe. Far from the views of A. Michel Lévy, C.
Barrois, and A. Lacroix, surviving as an expression of national
perversity, they have been supported to a remarkable degree by the
observations of Sederholm in Finland, of Lepsius and H. Credner in
Saxony, of A. Lawson and F. D. Adams in North America, and by the
careful reasoning of C. Doelter[69] based largely on his own
experimental work. A. Harker[70] and J. P. Iddings[71] have argued
that assimilation is merely a local phenomenon, of little importance
in the theory of igneous intrusion. W. C. Brögger[72], however, who
strongly supports the laccolitic view for the Christiania district,
expresses himself with far more caution, and leaves the way clear
for conclusions as to absorption and mingling of molten products in
the lower regions of the crust.
Doelter lays stress on the influence of high temperature, and
especially of the highly heated gases in the igneous rock, in
promoting corrosion of the cauldron-walls. He attributes greater
power of corrosion to the magmas rich in silica, and agrees with R.
A. Daly that the rapidly moving basic magmas reach the upper layers
of the crust in a condition of comparative purity. Daly[73] may be
looked on as an extremist in this matter; but it is hard for those who
have studied regions where the deep-seated cauldrons have been
cut across by denudation to avoid very large views of igneous
absorption. The contact-zones between the igneous mass and the
surrounding rocks are often seen merely in cross-section on the
flanks of a batholite or laccolite. In the areas of Archæan rocks, on
the other hand, where prolonged denudation has exposed the zones
of repeated interaction over hundreds of square miles on an
approximately horizontal surface, one may form some idea of the
processes that are still effective in the depths.
G. V. Hawes[74], in 1881, recognised the importance of the process
known by the mining term of "stoping," as a means whereby
igneous rocks work their way upward in the crust. Cracks in the
overlying roof are entered by the magma, blocks are wedged off,
and these are ultimately absorbed in the molten mass. In this matter
Hawes stands as a pioneer. As the viscosity of the magma increases
during cooling, the blocks last detached may remain embedded in
the marginal zone. The remarkable purity of this zone, however, in
many cases has raised an obvious difficulty; but it has been pointed
out[75] that the modified marginal and composite rock may
continuously sink down into the depths, aided by any of the causes
that promote magmatic differentiation, while a fairly pure magma,
almost of the original composition, is left on the crest of the
advancing dome. R. A. Daly[76] has developed the stoping theory
with considerable boldness. The areas most likely to carry conviction
to those who doubt that igneous masses can be intruded at the
expense of their surroundings are those where banded gneisses
have arisen on a regional scale (see p. 160).

THE RANGE OF COMPOSITION IN IGNEOUS


ROCKS
The broad division of igneous rocks into those of light colour and of
low specific gravity on the one hand and those that are dark and
heavy on the other is a very natural one, and Bunsen and Durocher
insisted that two magmas were fundamental in the crust. In one of
these, the "acid" magma, which gives rise to granites and rhyolites,
silica formed about 70 per cent. by weight of the ultimate rocks; in
the other, it formed about 50 per cent., and the products are basic
diorites, gabbros, and basalts[77]. The former group of rocks is rich
in alkalies, the latter, the "basic" group, in calcium, magnesium, and
iron. The mixture of these more extreme types of magma was held
to give rise to what are now called "intermediate" rocks.
Two other views are of course possible. If the composition of the
globe was originally uniform, the two magmas must have arisen by
separation from one of intermediate nature. Hence, in any cauldron
in the crust, in place of one of two magmas, an intermediate magma
may be presumed to exist, and to split up, from various causes, into
a number of parts which are separately erupted at the surface.
Charles Darwin's[78] remarks as to the sinking of crystals in a cooling
magma, and the consequent production of a trachytic and basaltic
type in the same cauldron, led the way to a general acceptance of
the theory of magmatic differentiation in laccolites and batholites. W.
C. Brögger's[79] brilliant explanation of the variation and succession
of types of igneous rock in the Christiania district has had a profound
influence on workers in other fields, and has perhaps directed
attention away from the parallel possibilities of differentiation by
assimilation.
The assimilation theory provides the second possible view above
referred to. A magma may be modified by the rocks into which it
intrudes, so that a "basic" fluid may become charged with silica from
a sandstone, the product crystallising as a granite; while an "acid"
fluid may become so charged with limestone that diorite ultimately
results. A. Harker[80] has discussed both theories clearly, with a
strong leaning to the acceptance of magmatic differentiation in the
cauldron as the only important cause of variation. R. A. Daly, on the
other hand, goes at least as far as Lacroix in France in supporting
the theory of assimilation. For him, the primitive igneous magma is
already basic, and basalts are therefore the prevalent type of
igneous rock. They reach us, moreover, from considerable depths.
The acid rocks are formed by amalgamation of this magma with
siliceous material lying nearer the earth's surface. Igneous rocks
exceptionally rich in alkalies, the so-called "alkaline" series, result
from the absorption of limestone in the magma; denser lime-bearing
silicates are thus formed, which sink by gravitation, leaving a lighter
magma above in which soda has become concentrated. Carbon
dioxide liberated from the limestone also plays a part in carrying up
the alkalies that might otherwise remain in a lower portion[81].
E. H. L. Schwarz[82] extends Daly's views with an almost romantic
fulness. He holds, with Chamberlin, that the primitive globe resulted
from the aggregation of basic meteoritic material. The more siliceous
crust arose from the withdrawal of magnesium and iron into the
depths by long-continued processes of leaching and gravitation. The
melting of this crust produces the acid igneous rocks. Igneous
cauldrons originate in the heat due to faulting, or to crumpling, or
even to the impact of gigantic meteorites. When a molten magma is
locally established, variation occurs in it by assimilation of different
types of material round it.
The balance of judgment as to differentiation and assimilation, which
should be regarded as parallel probabilities rather than as rival
propositions, is admirably held by C. Doelter[83], whose chapters on
this matter can be appreciated by all geologists.
It is of course possible that differentiation of type, from various
causes, has already proceeded so far in the earth's crust as to
produce noteworthy contrasts in the rocks erupted in different areas.
The interior of our globe, on Chamberlin's planetesimal hypothesis,
need not have been uniform in constitution, either at the outset or
at any subsequent time. J. W. Judd[84] has called attention to the
existence of petrographical provinces, a conception that has been
very fruitful in results. These provinces have been grouped by
Harker[85] in two branches, characterised respectively by rocks rich
in alkalies and by rocks rich in lime. The former branch appears to
be associated with the movements of faulting and block-structure,
rather than of crumpling, that have produced E. Suess's "Atlantic"
type of coast. The rocks rich in lime, on the other hand, are said to
be characteristic of areas that have been folded like the countries
bordering the Pacific. The names "Atlantic" and "Pacific" have
consequently been given to the two branches, but these terms seem
too geographical in their suggestion. Dewey and Flett[86] have put
forward a third type of magma, giving rise especially to albite as a
primary or secondary constituent, and characterised by the
production of pillow-lavas. This type is held to be associated with
areas that have steadily subsided, without much folding. G.
Steinmann[87], however, has connected the spilites and "ophiolitic"
rocks with regions of intense over-folding.
So far, there are many cases where it is difficult to assign a
petrographic province to one or other of these branches, and the
system seems to demand more simplicity within the provinces than
nature is prepared to yield.
Whatever the causes of variation, it is necessary to mark out by
names certain kinds of igneous material, and it is generally accepted
that the types thus set up are best based on chemical composition.
At the same time, the minerals present in the rock, and also its
structure, record certain phases of its history, and deserve an
important place in any system of classification. The natural history of
an igneous rock is concerned with its mode of occurrence, and no
isolated specimen can satisfy the geological investigator. In the field,
the porphyritic crystals, which have an important influence on the
total chemical composition, may be found to be strangers to the
magma, and to have been derived from some mass imperfectly
absorbed. The dark flecks and patches in a granitoid rock, so often
ascribed, somewhat mysteriously, to local "segregation" in the
magma, again and again prove to be metamorphosed and minutely
injected fragments of foreign rocks[88].
None the less, a broad classification is possible on chemical grounds,
and the acid, intermediate, basic, and ultrabasic grouping adopted
by Judd has been found of great convenience. Among acid rocks we
have granite as the coarsely crystalline type, with potassium felspars
prevalent and the excess of silica manifest as quartz. The finer
grained and sometimes compact types are the eurites, quartz-
felsites, or quartz-porphyries. When the rock contains more or less
residual glass, we have what are now known as rhyolites, of which
ordinary obsidian is the most glassy representative.
The opposite types, those of the basic group, include, at the coarsely
crystalline end, gabbro and basic diorite; the finely crystalline forms
are styled dolerites, and those with a trace of glass, or at any rate
very fine-grained and compact, are basalts. Glassy types are
naturally rare in this group, owing to the unsuitable chemical
composition.
Between granite and gabbro lie various rocks of intermediate
composition, some of them rich in soda rather than in potash.
Syenite, granodiorite, and the diorites with a prevalence of soda over
lime, are coarsely crystalline types. Compact types of these of course
occur. It will be sufficient, however, here to name the forms with
traces of residual glass, which range from trachyte, the type rich in
potash, to andesite, which connects them with basalt, in a series
where lime ultimately predominates over soda.
In the ultrabasic group are a number of exceptional types. Olivine
often becomes an important constituent, and the rocks then
decompose into the soft green or reddish masses known as
serpentine—or, more properly, serpentine-rock.
Igneous rocks, owing to their range of mineral composition and of
structure, combined with their general hardness, lend themselves to
various economic purposes. While the granites, resisting atmospheric
attack admirably in a polished state, provide our handsomest
building-stones, dolerites and fine-grained diorites, which owe their
toughness largely to the interlocked relations of their constituent
minerals, serve as our most satisfactory road-metals.

THE SCENERY OF IGNEOUS ROCKS


Volcanic landscapes, where activity is very recent or still in progress,
present a number of characteristic surface-forms. The cones that
have accumulated round the vents surpass all other hills in regularity
of outline, and the crater in the summit is often relatively large.
Lava-cones may be steep-sided bosses when formed of protrusions
of viscid rocks rich in silica, like the remarkable domes in the north
of Bohemia, or they may present very gentle slopes where fluid
basic lavas have been extruded.
Tuff-cones are liable to be breached on one side, owing to the
outflow of lava which the crater-wall could not sustain, and they
then assume the form of a mountain in which glacial influences have
hollowed out a cirque.
Rain washes down the loose materials from great volcanic cones,
and emphasises the concave curve of the mountain sides, the form
that is so beautiful in Fuji-yama in Japan, and which Hokusai, with
pardonable and affectionate exaggeration, reproduced in a hundred
illustrations. Ultimately, however, grooves appear on the flanks of the
cone, in which permanent streams gather, and the slopes are
dissected and worn away. During this process, the tuffs yield steep
and fantastic forms, and wall-like dykes weather out among them.
The dykes are usually the last features to decay.
Where the vent has been plugged with lava at the close of its
activity, the neck of rock often remains standing above the
surrounding country. The site of cone after cone can be picked out in
this way in the Cainozoic volcanic areas of central Germany. The
jutting crag of trachyte or of basalt has often been seized on as the
site of a feudal castle, under which the dependent agriculturists still
gather at nightfall in their red-roofed town. The group of sheer-sided
necks in the Hegau in southern Württemberg, the Hohentwiel,
Hohenkrähen, and the rest, form a very striking landscape amid
undulating Cainozoic lands.
The lava-beds that cover wide areas are naturally of basic
composition. Basalts thus form enormous plains with rugged
surfaces, on which at last a red-brown soil collects. When exposed to
denudation from the edge of the region inwards, they develop a
marked terrace-structure, through which the rivers cut steep and
grim ravines. Grass may grow on the ledges and the tables; but the
scarps, controlled by the well-marked vertical jointing of the lavas,
remain sharp and prominent, and the rock falls away from these
walls in whole columns at a time. This structure is characteristically
seen in northern Mull and the adjacent smaller isles, and is still more
impressive from the centre to the north of Skye, where the rain
swept terraces covered by grass and bog and scanty oatfields, and
the black steps of rock between them, present a scene of strange
monotony and desolation.
In regions less exposed to stormy weather, the lava-plateaus may
provide good soils. For instance, after the great seaward scarp of the
basalts has been crossed in the counties of Antrim and of
Londonderry, the lava-fields, dropped by faults towards Lough
Neagh, are seen to be occupied by prosperous farms. In arid
countries, however, the savage surface of the flows merely becomes
modified by red dust and scoriaceous gravel, worn by wind and
changes of temperature from the upstanding portions of the land.
Where a stratified country has been freely invaded by sheets of lava
along its planes of bedding, the stratification is emphasised in any
part exposed to weathering. The resisting igneous rock stands out in
scarps along the hills, and marks out any folds that have been
formed since the epoch of its intrusion.
When the beds remain fairly level, and are also uplifted, flat-topped
hills are formed by the intrusive sheets, like those that may be
carved out of a country flooded over by lava-streams. The crystalline
rock, very probably a dolerite, protects what lies below it. The kopjes
north of the Great Karroo in the centre of the Cape of Good Hope
are thus level on the crest and bounded by a steep wall or krans of
rock.
The edges of similar "sills" of igneous rock have controlled much of
the scenery between the Highland border of Scotland and the Tyne.
A fine example is the indented scarp of the Great Whin Sill, a sheet
of dolerite intruded among the Carboniferous strata of
Northumberland. This mass forms a platform for Bamburgh Castle
against the wild North Sea, and is traceable south-westward across
the country towards Carlisle. North of Hexham, its escarpment is
occupied by Hadrian's wall, and the town of Borcovicus was planted
on the edge, overlooking all Northumbria.
The farmers of North Britain and Ireland have long known
upstanding igneous dykes as unprofitable "whinstones." The
regularity of direction among dykes over very wide areas points to
their intrusion along cracks produced by stretching of the crust.
Radial grouping of dykes, such as one finds near volcanic necks, or,
on a gigantic scale, round Tycho on the moon, may be due to
explosive action; but the majority of dykes seem to have followed
upon earth-movement. In the north of Ireland, from the coast of
Down to that of Donegal, a series of compact rocks of Devonian age
occurs in dykes lying almost invariably north and south. The post-
Cretaceous dykes of the same region have a still more uniform
trend, from north-west to south-east. Such series of dykes modify
the scenery of coasts by forming promontories and serviceable piers
for boats.
The offshoots near the surface of a great intrusive mass are far less
regular. We are here close to the zone of attack, the "shatter-zone,"
and the structures or regular fracture-planes of the overlying rock
only partially control the position taken up by the intrusive magma.
Irregular knots and bosses appear in place of far-spreading sheets,
and a network of crossing veins occurs, instead of a system of co-
ordinated dykes. The resulting country is hummocky and broken,
and, where the cauldron itself has become exposed, striking
contrasts of surface are seen as we pass from the igneous core to
the older and frequently stratified rocks upon its flanks.
Some large bodies of intrusive rock have, however, been formed
sheet by sheet, and a bedded sill-like structure is then revealed in
them on weathering. Sir A. Geikie[89] calls attention to this in his
description of the heart of the black gabbro mass in Skye. But, as a
rule, the continuity of structure in batholites, and their characteristic
joint-planes set at angles to one another, cause them to appear as
massive blocks in the landscape, untraversed by any regular lines.
Granite, with its broad tabular jointing, which is often developed
parallel to a surface of cooling, forms rounded slopes and domes
after long-continued weathering. When reared high into the zone of
frost-action, it develops spires and pinnacles, as in the huge
"aiguilles" of Mont Blanc. But, as decay goes on, the uniform descent
of boulders and sand forms spreading taluses, banked against the
lower slopes, while the curving joints, not too closely set, promote a
smoothness on the higher lands. These joints, moreover, divide the
rock into boulders almost ready-made. Tabular structure sometimes
predominates; but even in this case the exposed ends of the layers
soon become rounded, as the felspar crystals pass into a powdery
state. Commonly, a rough spheroidal structure prevails, as may be
traced in many of the Dartmoor "tors," and the blocks that slip away
through widening of the joints become more and more rounded as
their surfaces crumble on the talus (Fig. 17).
Fig. 17. Weathering Granite. Lundy Island.
In tropical lands, granite exfoliates under the alternations of clear
hot days and clear cold nights, and the joint-structure allows of the
formation of great round-backed surfaces, on which spheroidal
boulders appear poised. These boulders are the relics of an overlying
layer of granite, most of which has slipped away to the hill-foot.
Their surfaces crumble, owing to the unequal expansion of the
constituent minerals. When the rainy season sets in, the
decomposed crust is washed away; during the dry season it falls off
in flakes and powder. In this way the magnificent series of monoliths
that surround the grave of Cecil Rhodes in the Matopo Hills have
become separated out from a continuous sheet of granite. They
stand now like glacial boulders on a surface almost as smooth as
that of a roche moutonnée (Fig. 18). The landscape for miles around
is fantastic with huge fallen masses, and with high-perched blocks
that seem about to fall. Similar scenery is well known in central
India, and exfoliation controls the form of mountain-domes in
California and Brazil. J. C. Branner [90] lays most stress on
temperature-changes in the surface-zone, and little on original
spheroidal jointing, in promoting the exfoliation of the rounded
boulders.
Fig. 18. Granite weathering under tropical conditions.
Rhodes's Grave, Matopo Hills, S. Rhodesia. The
blocks like boulders are residues of a sheet of
granite that once overlay the hill.
The basic rocks present far more rugged outlines. When a cauldron
occupied by basic diorite or by gabbro comes under denuding action,
the numerous crossing joints oppose the formation of domes or
tables. The weather widens one groove here, another there; the
rock breaks away in angular fragments rather than as a powder over
a broad surface, and serrated edges and jagged pinnacles arise
along the crests. The diorites among our old metamorphic rocks in
Scotland or in Ireland can be recognised on the sky-line at
considerable distances. Sir A. Geikie, in his "Scenery of Scotland,"
has made the contrast between granite and gabbro in the centre of
the Isle of Skye familiar to all geologists. Here the two types of rock
were erupted at no long interval, and they have been exposed to
denudation under the same conditions. J. Macculloch dwelt in
1819[91] on the relative resistance of the gabbro and the rapid
disintegration of the granite hills, quaintly remarking of the latter
that "the loose stones, by their constant descent from the summits,
obscure the rocky surface, covering the sides with long torrents of
red rubbish even more unpleasing to the sight than their conoidal
forms." Macculloch noted that the loose blocks in the gabbro region
lay much as they had fallen, without the production of a sand.
In most mountain-chains produced by folding, igneous matter has
been forced up as an accompaniment of the earth-movements. The
local knots and laccolites, or the great cores admitted along certain
anticlines, stand out on weathering among schistose or stratified
hills. Their surfaces are marked by accidents, and each peak as it
comes into view offers something of a new surprise. The wall of
Mont Blanc from the angle near Entrèves, and the huge crag of the
Matterhorn above the valley of the Visp, have illustrated to every
traveller the dominance of igneous masses in the landscape. In our
own islands, the granites of Ben Cruachan and Cairn Gorm have
resisted long ages of denudation; an intrusive sheet of finer grain
forms the long sheer wall of Cader Idris; while obsidian lava-flows,
now grey and dull and crystalline, have furnished on Snowdon the
finest scenery of Wales. The fortress-town of Edinburgh has arisen
on the relics of a dead volcano; and the high moor of Leinster, so
long the peril of the English, records an igneous cauldron that has
been exposed to denudation from the opening of Devonian times.

You might also like