Linux Shell Scripting Cookbook, Second Edition

Don’t neglect the shell – this book will empower you to use simple commands to perform complex tasks. Whether you’re a casual or advanced Linux user, the cookbook approach makes it all so brilliantly accessible and, above all, useful.

Linux Shell Scripting Cookbook, Second Edition

Shantanu Tushar, Sarath Lakshman

2 customer reviews
Don’t neglect the shell – this book will empower you to use simple commands to perform complex tasks. Whether you’re a casual or advanced Linux user, the cookbook approach makes it all so brilliantly accessible and, above all, useful.
Mapt Subscription
FREE
$29.99/m after trial
eBook
$5.40
RRP $26.99
Save 79%
Print + eBook
$44.99
RRP $44.99
What do I get with a Mapt Pro subscription?
  • Unlimited access to all Packt’s 5,000+ eBooks and Videos
  • Early Access content, Progress Tracking, and Assessments
  • 1 Free eBook or Video to download and keep every month after trial
What do I get with an eBook?
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with Print & eBook?
  • Get a paperback copy of the book delivered to you
  • Download this book in EPUB, PDF, MOBI formats
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
What do I get with a Video?
  • Download this Video course in MP4 format
  • DRM FREE - read and interact with your content when you want, where you want, and how you want
  • Access this title in the Mapt reader
$0.00
$5.40
$44.99
$29.99p/m after trial
RRP $26.99
RRP $44.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 5,000+ eBooks & Videos
  • 50+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781782162742
Paperback384 pages

Book Description

The shell remains one of the most powerful tools on a computer system — yet a large number of users are unaware of how much one can accomplish with it. Using a combination of simple commands, we will see how to solve complex problems in day to day computer usage.

Linux Shell Scripting Cookbook, Second Edition will take you through useful real-world recipes designed to make your daily life easy when working with the shell. The book shows the reader how to effectively use the shell to accomplish complex tasks with ease.

The book discusses basics of using the shell, general commands and proceeds to show the reader how to use them to perform complex tasks with ease.

Starting with the basics of the shell, we will learn simple commands with their usages allowing us to perform operations on files of different kind. The book then proceeds to explain text processing, web interaction and concludes with backups, monitoring and other sysadmin tasks.

Linux Shell Scripting Cookbook, Second Edition serves as an excellent guide to solving day to day problems using the shell and few powerful commands together to create solutions.

Table of Contents

Chapter 1: Shell Something Out
Introduction
Printing in the terminal
Playing with variables and environment variables
Function to prepend to environment variables
Math with the shell
Playing with file descriptors and redirection
Arrays and associative arrays
Visiting aliases
Grabbing information about the terminal
Getting and setting dates and delays
Debugging the script
Functions and arguments
Reading the output of a sequence of commands in a variable
Reading n characters without pressing the return key
Running a command until it succeeds
Field separators and iterators
Comparisons and tests
Chapter 2: Have a Good Command
Introduction
Concatenating with cat
Recording and playing back of terminal sessions
Finding files and file listing
Playing with xargs
Translating with tr
Checksum and verification
Cryptographic tools and hashes
Sorting unique and duplicates
Temporary file naming and random numbers
Splitting files and data
Slicing filenames based on extension
Renaming and moving files in bulk
Spell checking and dictionary manipulation
Automating interactive input
Making commands quicker by running parallel processes
Chapter 3: File In, File Out
Introduction
Generating files of any size
The intersection and set difference (A-B) on text files
Finding and deleting duplicate files
Working with file permissions, ownership, and the sticky bit
Making files immutable
Generating blank files in bulk
Finding symbolic links and their targets
Enumerating file type statistics
Using loopback files
Creating ISO files and hybrid ISO
Finding the difference between files, patching
Using head and tail for printing the last or first 10 lines
Listing only directories – alternative methods
Fast command-line navigation using pushd and popd
Counting the number of lines, words, and characters in a file
Printing the directory tree
Chapter 4: Texting and Driving
Introduction
Using regular expressions
Searching and mining a text inside a file with grep
Cutting a file column-wise with cut
Using sed to perform text replacement
Using awk for advanced text processing
Finding the frequency of words used in a given file
Compressing or decompressing JavaScript
Merging multiple files as columns
Printing the nth word or column in a file or line
Printing text between line numbers or patterns
Printing lines in the reverse order
Parsing e-mail addresses and URLs from text
Removing a sentence in a file containing a word
Replacing a pattern with text in all the files in a directory
Text slicing and parameter operations
Chapter 5: Tangled Web? Not At All!
Introduction
Downloading from a web page
Downloading a web page as plain text
A primer on cURL
Accessing Gmail e-mails from the command line
Parsing data from a website
Image crawler and downloader
Web photo album generator
Twitter command-line client
Creating a "define" utility by using the Web backend
Finding broken links in a website
Tracking changes to a website
Posting to a web page and reading the response
Chapter 6: The Backup Plan
Introduction
Archiving with tar
Archiving with cpio
Compressing data with gzip
Archiving and compressing with zip
Faster archiving with pbzip2
Creating filesystems with compression
Backup snapshots with rsync
Version control-based backup with Git
Creating entire disk images using fsarchiver
Chapter 7: The Old-boy Network
Introduction
Setting up the network
Let us ping!
Listing all the machines alive on a network
Running commands on a remote host with SSH
Transferring files through the network
Connecting to a wireless network
Password-less auto-login with SSH
Port forwarding using SSH
Mounting a remote drive at a local mount point
Network traffic and port analysis
Creating arbitrary sockets
Sharing an Internet connection
Basic firewall using iptables
Chapter 8: Put on the Monitor's Cap
Introduction
Monitoring disk usage
Calculating the execution time for a command
Collecting information about logged in users, boot logs, and boot failures
Listing the top 10 CPU consuming processes in an hour
Monitoring command outputs with watch
Logging access to files and directories
Logfile management with logrotate
Logging with syslog
Monitoring user logins to find intruders
Remote disk usage health monitor
Finding out active user hours on a system
Measuring and optimizing power usage
Monitoring disk activity
Checking disks and filesystems for errors
Chapter 9: Administration Calls
Introduction
Gathering information about processes
Killing processes and send or respond to signals
Sending messages to user terminals
Gathering system information
Using /proc for gathering information
Scheduling with cron
Writing and reading the MySQL database from Bash
User administration script
Bulk image resizing and format conversion
Taking screenshots from the terminal
Managing multiple terminals from one

What You Will Learn

  • Explore a variety of regular usage tasks and how it can be made faster using shell command
  • Write shell scripts that can dig data from web and process it with few lines of code
  • Use different kinds of tools together to create solutions
  • Interact with simple web API from scripts
  • Perform and automate tasks such as automating backups and restore with archiving tools
  • Create and maintain file/folder archives, compression formats and encrypting techniques with shell
  • Set up Ethernet and Wireless LAN with the shell script
  • Monitor different activities on the network using logging techniques

Authors

Table of Contents

Chapter 1: Shell Something Out
Introduction
Printing in the terminal
Playing with variables and environment variables
Function to prepend to environment variables
Math with the shell
Playing with file descriptors and redirection
Arrays and associative arrays
Visiting aliases
Grabbing information about the terminal
Getting and setting dates and delays
Debugging the script
Functions and arguments
Reading the output of a sequence of commands in a variable
Reading n characters without pressing the return key
Running a command until it succeeds
Field separators and iterators
Comparisons and tests
Chapter 2: Have a Good Command
Introduction
Concatenating with cat
Recording and playing back of terminal sessions
Finding files and file listing
Playing with xargs
Translating with tr
Checksum and verification
Cryptographic tools and hashes
Sorting unique and duplicates
Temporary file naming and random numbers
Splitting files and data
Slicing filenames based on extension
Renaming and moving files in bulk
Spell checking and dictionary manipulation
Automating interactive input
Making commands quicker by running parallel processes
Chapter 3: File In, File Out
Introduction
Generating files of any size
The intersection and set difference (A-B) on text files
Finding and deleting duplicate files
Working with file permissions, ownership, and the sticky bit
Making files immutable
Generating blank files in bulk
Finding symbolic links and their targets
Enumerating file type statistics
Using loopback files
Creating ISO files and hybrid ISO
Finding the difference between files, patching
Using head and tail for printing the last or first 10 lines
Listing only directories – alternative methods
Fast command-line navigation using pushd and popd
Counting the number of lines, words, and characters in a file
Printing the directory tree
Chapter 4: Texting and Driving
Introduction
Using regular expressions
Searching and mining a text inside a file with grep
Cutting a file column-wise with cut
Using sed to perform text replacement
Using awk for advanced text processing
Finding the frequency of words used in a given file
Compressing or decompressing JavaScript
Merging multiple files as columns
Printing the nth word or column in a file or line
Printing text between line numbers or patterns
Printing lines in the reverse order
Parsing e-mail addresses and URLs from text
Removing a sentence in a file containing a word
Replacing a pattern with text in all the files in a directory
Text slicing and parameter operations
Chapter 5: Tangled Web? Not At All!
Introduction
Downloading from a web page
Downloading a web page as plain text
A primer on cURL
Accessing Gmail e-mails from the command line
Parsing data from a website
Image crawler and downloader
Web photo album generator
Twitter command-line client
Creating a "define" utility by using the Web backend
Finding broken links in a website
Tracking changes to a website
Posting to a web page and reading the response
Chapter 6: The Backup Plan
Introduction
Archiving with tar
Archiving with cpio
Compressing data with gzip
Archiving and compressing with zip
Faster archiving with pbzip2
Creating filesystems with compression
Backup snapshots with rsync
Version control-based backup with Git
Creating entire disk images using fsarchiver
Chapter 7: The Old-boy Network
Introduction
Setting up the network
Let us ping!
Listing all the machines alive on a network
Running commands on a remote host with SSH
Transferring files through the network
Connecting to a wireless network
Password-less auto-login with SSH
Port forwarding using SSH
Mounting a remote drive at a local mount point
Network traffic and port analysis
Creating arbitrary sockets
Sharing an Internet connection
Basic firewall using iptables
Chapter 8: Put on the Monitor's Cap
Introduction
Monitoring disk usage
Calculating the execution time for a command
Collecting information about logged in users, boot logs, and boot failures
Listing the top 10 CPU consuming processes in an hour
Monitoring command outputs with watch
Logging access to files and directories
Logfile management with logrotate
Logging with syslog
Monitoring user logins to find intruders
Remote disk usage health monitor
Finding out active user hours on a system
Measuring and optimizing power usage
Monitoring disk activity
Checking disks and filesystems for errors
Chapter 9: Administration Calls
Introduction
Gathering information about processes
Killing processes and send or respond to signals
Sending messages to user terminals
Gathering system information
Using /proc for gathering information
Scheduling with cron
Writing and reading the MySQL database from Bash
User administration script
Bulk image resizing and format conversion
Taking screenshots from the terminal
Managing multiple terminals from one

Book Details

ISBN 139781782162742
Paperback384 pages
Read More
From 2 reviews

Read More Reviews

Recommended for You

Mastering Object-oriented Python Book Cover
Mastering Object-oriented Python
$ 26.99
$ 18.90
Git: Version Control for Everyone Book Cover
Git: Version Control for Everyone
$ 23.99
$ 16.80
Responsive Web Design with HTML5 and CSS3 Book Cover
Responsive Web Design with HTML5 and CSS3
$ 23.99
$ 4.80
Mastering Web Application Development with AngularJS Book Cover
Mastering Web Application Development with AngularJS
$ 26.99
$ 5.40
Linux Mint Essentials Book Cover
Linux Mint Essentials
$ 29.99
$ 21.00
Python Network Programming Cookbook Book Cover
Python Network Programming Cookbook
$ 26.99
$ 18.90