ebook img

Wicked Cool Shell Scripts PDF

402 Pages·2·12.036 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Wicked Cool Shell Scripts

E 2 D N I 110011 TTIIMMEE--SSAAVVIINNGG,, T D WW II CC KK EE DD CCOO OO LL I PPRROOBBLLEEMM--SSOOLLVVIINNGG O N SSHHEELLLL SSCCRRIIPPTTSS E D I2 TN IOD SS HH EE LL LL SS CC RR II PP TT SS N WW II 11 00 11 SS CC RR II PP TT SS FF OO RR LL II NN UUXX ,, OO SS XX ,, Shell scripts are an efficient way to interact with your • Tools for renaming and applying commands to files CC machine and manage your files and system opera- in bulk AA NN DD UU NN II XX SS YY SS TT EE MM SS KK tions. With just a few lines of code, your computer • Image processing and editing tools will do exactly what you want it to do. But you can EE also use shell scripts for many other essential (and Whether you want to save time managing your system DD not-so-essential) tasks. or just find new ways to goof off, these scripts are D A V E T A Y L O R A N D B R A N D O N P E R R Y wicked cool! CC This second edition of Wicked Cool Shell Scripts offers a collection of useful, customizable, and fun shell scripts ABOUT THE AUTHORS OO for solving common problems and personalizing your OO Dave Taylor is the author of more than 20 books, computing environment. Each chapter contains ready- as well as thousands of magazine and newspaper LL to-use scripts and explanations of how they work, why articles, and is an award-winning public speaker. He you’d want to use them, and suggestions for changing SS was a contributor to BSD 4.4 UNIX, and his software and expanding them. You’ll find a mix of classic favor- is included in all major UNIX distributions. HH ites, like a disk backup utility that keeps your files safe EE when your system crashes, a password manager, a Brandon Perry started writing C# applications with weather tracker, and several games, as well as the advent of the open source .NET implementation LL 23 brand-new scripts, including: Mono. In his free time, he enjoys writing modules for LL the Metasploit framework, parsing binary files, and • A ZIP code lookup tool that reports the city and state SS fuzzing things. CC • A Bitcoin address information retriever COVERS THE BOURNE-AGAIN SHELL (BASH) RR • A suite of tools for working with cloud services like FOR LINUX, UNIX, AND OS X II Dropbox and iCloud PP TT SS THE FINEST IN GEEK ENTERTAINMENT™ P T A www.nostarch.com ERANY L $34.95 ($40.95 CDN) RYDOR “I LIE FLAT.” This book uses a durable binding that won’t snap shut. PROGRAMMSHELVE IN: IN G/G EN FSC FPO ERAL 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 can’t give this book enough praise and high enough recommendation. Quite simply, this is the book that I wish I would’ve had when I was just learn- ing Linux.” —steve suehring, linuxworld editor “A great resource for intermediate to experienced shell programmers.” —webdevreviews “If you’re 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 W i c k e d co o l S h e l l S c r i p tS 2 n d ed i t i o n 101 Scripts for linux, oS X, and UniX Systems by dave taylor and 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. Fifth printing 26 25 24 23 22 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 Gutiérrez 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; [email protected] 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 (O’Reilly 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 Gutiérrez 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 com- puting environment largely compatible with Matlab, and with Mercurial, a distributed version-control system. He enjoys pure and applied math- ematics, skating, swimming, and knitting. Lately he’s been thinking a lot about greenhouse gas emissions and rhino conservation efforts. Brief Contents Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Chapter 0: A Shell Scripts Crash Course . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1: The Missing Code Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Chapter 2: Improving on User Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Chapter 3: Creating Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Chapter 4: Tweaking Unix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Chapter 5: System Administration: Managing Users . . . . . . . . . . . . . . . . . . . . . . . . . 117 Chapter 6: System Administration: System Maintenance . . . . . . . . . . . . . . . . . . . . . . 145 Chapter 7: Web and Internet Users . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Chapter 8: Webmaster Hacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 Chapter 9: Web and Internet Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Chapter 10: Internet Server Administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Chapter 11: OS X Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Chapter 12: Shell Script Fun and Games . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 Chapter 13: Working with the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Chapter 14: ImageMagick and Working with Graphics Files . . . . . . . . . . . . . . . . . . 313 Chapter 15: Days and Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Appendix A: Installing Bash on Windows 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341 Appendix B: Bonus Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.