PRAISE FOR THE FIRST EDITION OF WICKED COOL SHELL SCRIPTS
A must for any new or intermediate-level Linux administrator. This is the book that every other publisher tries to imitate.
LINUXWORLD
I cant give this book enough praise and high enough recommendation. Quite simply, this is the book that I wish I wouldve had when I was just learning Linux.
STEVE SUEHRING, LINUXWORLD EDITOR
A great resource for intermediate to experienced shell programmers.
WEBDEVREVIEWS
If youre interested in the command line and shell scripting, this is an excellent book which will extend your knowledge and provide more than a hundred ready-to-run scripts.
MACBLOG.COM
There are a few books in the [computer] field that remain useful for years and years after their publishing date. Wicked Cool Shell Scripts is one of those fortunate few.
THE BRAINSHED
Incredibly fun (really!) and chock full of scripts.
SLASHDOT
WICKED COOL SHELL SCRIPTS
2ND EDITION
101 Scripts for Linux, OS X, and UNIX Systems
Dave Taylor
Brandon Perry
San Francisco
WICKED COOL SHELL SCRIPTS, 2ND EDITION. Copyright 2017 by Dave Taylor and Brandon Perry.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
20 19 18 17 16 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-602-8
ISBN-13: 978-1-59327-602-7
Publisher: William Pollock
Production Editor: Laurel Chun
Cover Illustration: Josh Ellingson
Interior Design: Octopod Studios
Developmental Editor: Liz Chadwick
Technical Reviewer: Jordi Gutirrez Hermoso
Additional Technical Reviewers: Therese Bao, Mark Cohen, Matt Cone, Grant McWilliams, and Austin Seipp
Copyeditor: Paula L. Fleming
Compositors: Laurel Chun and Janelle Ludowise
Proofreader: James Fraleigh
Indexer: Nancy Guenther
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900;
www.nostarch.com
The Library of Congress has catalogued the first edition as follows:
Taylor, Dave.
Wicked cool shell scripts / Dave Taylor.
p. cm.
ISBN 1-59327-012-7
1. UNIX (Computer file) 2. UNIX Shells. I. Title.
QA76.76.O63T3895 2004
005.4'32--dc22
2003017496
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an As Is basis, without warranty. While every precaution has been taken in the preparation of this work, neither the authors nor No Starch Press, Inc. shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in it.
About the Authors
Dave Taylor has been in the computer industry since 1980. He was a contributor to BSD 4.4 UNIX, and his software is included in all major UNIX distributions. He is an award-winning public speaker and has written thousands of magazine and newspaper articles. He is the author of more than 20 books, including Learning Unix for OS X (OReilly Media), Solaris 9 for Dummies (Wiley Publishing), and Sams Teach Yourself Unix in 24 Hours (Sams Publishing). A popular columnist for Linux Journal magazine, he also maintains a customer tech support and gadget reviews website, askdavetaylor.com.
Brandon Perry started writing C# applications with the advent of the open source .NET implementation Mono. In his free time, he enjoys writing modules for the Metasploit framework, parsing binary files, and fuzzing things.
About the Technical Reviewer
Jordi Gutirrez Hermoso is a coder, mathematician, and hacker-errant. He has run Debian GNU/Linux exclusively since 2002, both at home and at work. Jordi is involved with GNU Octave, a free numerical computing environment largely compatible with Matlab, and with Mercurial, a distributed version-control system. He enjoys pure and applied mathematics, skating, swimming, and knitting. Lately hes been thinking a lot about greenhouse gas emissions and rhino conservation efforts.
CONTENTS IN DETAIL
A SHELL SCRIPTS CRASH COURSE
THE MISSING CODE LIBRARY
IMPROVING ON USER COMMANDS
CREATING UTILITIES
TWEAKING UNIX
SYSTEM ADMINISTRATION: MANAGING USERS
SYSTEM ADMINISTRATION: SYSTEM MAINTENANCE
WEB AND INTERNET USERS
WEBMASTER HACKS
WEB AND INTERNET ADMINISTRATION
INTERNET SERVER ADMINISTRATION
OS X SCRIPTS
SHELL SCRIPT FUN AND GAMES
WORKING WITH THE CLOUD
IMAGEMAGICK AND WORKING WITH GRAPHICS FILES
DAYS AND DATES
A
INSTALLING BASH ON WINDOWS 10
B
BONUS SCRIPTS
Acknowledgments for the First Edition
A remarkable number of people have contributed to the creation and development of this book, most notably Dee-Ann LeBlanc, my first-generation tech reviewer and perpetual IM buddy, and Richard Blum, tech editor and scripting expert, who offered significant and important commentary regarding the majority of the scripts in the book. Nat Torkington helped with the organization and robustness of the scripts. Others who offered invaluable assistance during the development phase include Audrey Bronfin, Martin Brown, Brian Day, Dave Ennis, Werner Klauser, Eugene Lee, Andy Lester, and John Meister. The MacOSX.com forums have been helpful (and are a cool place to hang out online), and the AnswerSquad.com team has offered great wisdom and infinite opportunities for procrastination. Finally, this book wouldnt be in your hands without the wonderful support of Bill Pollock and stylistic ministrations of Hillel Heinstein, Rebecca Pepper, and Karol Jurado: Thanks to the entire No Starch Press team!
Id like to acknowledge the support of my wonderful childrenAshley, Gareth, and Kianaand our menagerie of animals.
Dave Taylor
Acknowledgments for the Second Edition
Wicked Cool Shell Scripts has proven itself over the past decade as a useful and encouraging read for anyone who enjoys bash scripting or wants to learn more advanced techniques. In updating the second edition, Dave and I hoped to give this book a breath of fresh air and to inspire another decade of shell script exploration. This work to add new scripts and polish up the explanations couldnt have been done without the support of a lot of people.