

Linux Shell Scripting
Cookbook
Second Edition
Over 110 practical recipes to solve real-world shell
problems, guaranteed to make you wonder how you
ever lived without them
Shantanu Tushar
Sarath Lakshman
BIRMINGHAM - MUMBAI

Linux Shell Scripting Cookbook
Second Edition
Copyright © 2013 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without
warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers
and distributors will be held liable for any damages caused or alleged to be caused directly or
indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt
Publishing cannot guarantee the accuracy of this information.
First published: January 2011
Second edition: May 2013
Production Reference: 1140513
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78216-274-2
www.packtpub.com
Cover Image by Parag Kadam (paragvkadam@gmail.com)

Credits
Authors
Shantanu Tushar
Sarath Lakshman
Reviewers
Rajeshwari K.
John C. Kennedy
Anil Kumar
Sudhendu Kumar
Aravind SV
Acquisition Editor
Kartikey Pandey
Lead Technical Editor
Ankita Shashi
Technical Editors
Jalasha D'costa
Amit Ramadas
Lubna Shaikh
Project Coordinator
Shiksha Chaturvedi
Proofreader
Linda Morris
Indexer
Hemangini Bari
Production Coordinator
Shantanu Zagade
Cover Work
Shantanu Zagade

About the Authors
Shantanu Tushar is an advanced GNU/Linux user since his college days. He works as an
application developer and contributes to the software in the KDE projects.
Shantanu has been fascinated by computers since he was a child, and spent most of his high
school time writing C code to perform daily activities. Since he started using GNU/Linux, he
has been using shell scripts to make the computer do all the hard work for him. He also takes
time to visit students at various colleges to introduce them to the power of Free Software,
including its various tools. Shantanu is a well-known contributor in the KDE community and
works on Calligra, Gluon and the Plasma subprojects. He looks after maintaining Calligra
Active – KDE's ofce document viewer for tablets, Plasma Media Center, and the Gluon Player.
One day, he believes, programming will be so easy that everybody will love to write programs
for their computers.
Shantanu can be reached by e-mail on
shantanu@kde.org, shantanutushar on identi.
ca/twitter
, or his website http://www.shantanutushar.com.
I would like to thank my friends and family for the support and
encouragement they've given me, especially to my sweet sister for her
patience when I couldn't get time to talk to her. I am particularly thankful
to Sinny Kumari for patiently testing the scripts to make sure they function
properly and Sudhendu Kumar for helping me with the recipe on
GNU Screen.
I must also thank Krishna, Madhusudan, and Santosh who introduced me to
the wonderful world of GNU/Linux and Free Software. Also, a big thanks to
all the reviewers of the book for taking the time to painfully go through every
minute detail in the book and help me in improving it. I am also thankful to
the whole team at Packt Publishing, without whose efforts and experience,
this second edition wouldn't have happened.