Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Bash Cookbook

You're reading from  Bash Cookbook

Product type Book
Published in Jul 2018
Publisher Packt
ISBN-13 9781788629362
Pages 264 pages
Edition 1st Edition
Languages
Authors (2):
Ron Brash Ron Brash
Profile icon Ron Brash
Ganesh Sanjiv Naik Ganesh Sanjiv Naik
Profile icon Ganesh Sanjiv Naik
View More author details
Toc

Table of Contents (15) Chapters close

Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
1. Crash Course in Bash 2. Acting Like a Typewriter and File Explorer 3. Understanding and Gaining File System Mastery 4. Making a Script Behave Like a Daemon 5. Scripts for System Administration Tasks 6. Scripts for Power Users 7. Writing Bash to Win and Profit 8. Advanced Scripting Techniques 1. Other Books You May Enjoy Index

Index

A

  • alarm
    • generating / How to do it..., How it works...
  • alias command / Adding aliases, and altering user paths/variables, How it works...
  • aliases
    • adding / Adding aliases, and altering user paths/variables
  • apt command / Getting ready
  • arrays / How it works...
  • artefact / Readying your script for different languages with internationalization
  • artifact / Readying your script for different languages with internationalization
  • ASCII / Basic searching for strings and files
  • audio
    • playing / Playing and managing audio from Bash, How it works…
    • managing / Getting ready, How it works…
  • AWK
    • used, for replacing substrings / Getting ready, How it works...

B

  • Bash
    • fundamentals / Getting started with Bash and CLI fundamentals
    • about / Introduction
    • strings, managing / Striping/altering/sorting/deleting/searching strings with Bash only
    • battery life, monitoring / Getting ready
  • Bash script
    • creating, with Vim / Your first Bash script with Vim
    • used, for monitoring udev input / Getting ready, How it works…
    • simple frontend GUIs, creating for / Getting ready, How to do it...
  • Bash shell
    • compiling / Compiling and installing your own Bash shell, How it works...
    • installing / Compiling and installing your own Bash shell, How it works...
  • basic loops
    • about / Basic loops
    • for loop / For loop
    • do while loop / Do while loop
  • basic network connectivity
    • configuring / Configuring basic network connectivity, How to do it..., How it works...
  • battery life
    • monitoring, Bash used / Getting ready
  • binary
    • about / Formatting your data/output using echo and printf
    • dependencies, finding / Finding binary dependencies, How to do it..., How it works...
  • binary numbers
    • evaluating / Evaluating binary numbers
  • bzip2 / How it works...

C

  • calculations
    • in scripts / Math and calculations in script, Getting ready, How to do it..., How it works...
  • case statement
    • creating / Case/switch statements and loop constructs
    • about / Basic case statement
  • cat command / How to do it…
  • chroot
    • used, for securing scripts / Using chroot and restricted Bash shells to secure scripts, How it works…
  • CLI
    • graphics, creating on / Getting ready, How it works...
    • presentations, creating on / Getting ready, How it works...
    • web, browsing from / Browsing the web from the CLI, How it works...
  • command line colors / How to do it...
  • command not found warnings/errors
    • avoiding / Avoiding command not found warnings/errors and improving portability, How it works...
  • commands
    • linking / Linking commands, pipes, and input/output
    • about / Getting additional information about commands
    • invoking, on permission requirement / Invoking commands when they require permissions, Getting ready, How to do it..., How it works...
  • Comma Separated Values (CSV) / Reading delimited data and altered output format
  • conditional logic
    • using / Conditional logic using if, else, and elseif
    • file attributes, using with / Using file attributes with conditional logic, How to do it..., How it works...
  • config file
    • creating / Creating a config file and using it in tandem with your scripts, How to do it...
    • using, in shell script / Creating a config file and using it in tandem with your scripts, How to do it...
  • configuration
    • adding, to /etc/logrotate.d/ / Adding configuration to /etc/logrotate.d/
  • connectivity diagnostics / Getting ready, How to do it..., How it works...
  • Cron Jobs
    • creating / Creating and configuring cron Jobs for task scheduling
    • configuring / Creating and configuring cron Jobs for task scheduling
  • crontab command / How it works...
  • curl command / How it works…

D

  • data
    • formatting, echo used / Formatting your data/output using echo and printf
    • formatting, printf used / Formatting your data/output using echo and printf
  • datasets
    • generating / Generating datasets and random files of various size, Getting ready, How it works...
  • date command / Fetching time from different locations
  • dd command
    • using / Backing up and erasing media, disks, and partitions with DD
  • delimited data
    • reading / Reading delimited data and altered output format, Getting ready, How to do it..., How it works...
  • delimiters / Reading delimited data and altered output format
  • dialog command / Creating graphics and presentations on the CLI
  • diff
    • creating, of two files / Creating a diff of two files and patching, Getting ready, How to do it..., How it works...
  • directories
    • monitoring / Monitoring directories and files, How it works...
  • dmidecode tool / Gathering and aggregating system information
  • DMZ firewall
    • creating / Creating a simple NAT and DMZ firewall, How it works…
  • do while loop / Do while loop
  • duplicate directories
    • finding / Finding and deleting duplicate files or directories, Getting ready
    • deleting / How to do it..., How it works...
  • duplicate files
    • finding / Finding and deleting duplicate files or directories, Getting ready, How to do it...
    • deleting / How it works...
  • duplicates
    • reducing, based on file contents / Calculating statistics and reducing duplicates based on file contents, How to do it..., How it works...

E

  • echo
    • data, formatting / Formatting your data/output using echo and printf
    • output, formatting / Formatting your data/output using echo and printf
  • elif statement / Conditional logic using if, else, and elseif
  • ELinks / Browsing the web from the CLI
  • else statement / Conditional logic using if, else, and elseif
  • encoding scheme / Basic searching for strings and files
  • escape character / Hidden Bash variables and reserved words
  • evtest tool / Using Bash scripts to monitor udev input
  • extension
    • files, searching by / Searching for files by name and/or extension, Getting ready, How to do it..., How it works...
  • external functions
    • using / Including/importing a library script and using external functions

F

  • failed SSH attempts
    • IP addresses, blocking from / Blocking IP addresses from failed SSH attempts, How it works…
  • file-in-file-out program
    • creating / Creating a file-in-file-out program and running processes in parallel, How to do it..., How it works...
  • file attributes
    • using, with conditional logic / Using file attributes with conditional logic, How to do it..., How it works...
  • file descriptor
    • reference / Linking commands, pipes, and input/output
  • file integrity
    • checking for / Checking for file integrity and tampering
  • files
    • basic searching / Basic searching for strings and files, How to do it..., How it works...
    • viewing, from various angles / Viewing files from various angles – head, tail, less, and more, Getting ready, How to do it..., How it works...
    • searching, by name/extension / Searching for files by name and/or extension, Getting ready, How to do it..., How it works...
    • joining, at arbitrary positions / Joining and splitting files at arbitrary positions, Getting ready, How to do it..., How it works...
    • splitting, at arbitrary positions / Joining and splitting files at arbitrary positions, Getting ready, How to do it..., How it works...
    • generating, of multiple sizes / Generating datasets and random files of various size, Getting ready, How it works...
    • monitoring / Monitoring directories and files, How it works...
    • compressing / Compressing and archiving files, How to do it...
    • archiving / Compressing and archiving files, How to do it...
    • new configuration directives / Adding configuration to /etc/logrotate.d/
    • retrieving / Mounting network file systems and retrieving files, How it works...
    • encrypting, from script / Encrypting/decrypting files from a script
    • decrypting, from script / Encrypting/decrypting files from a script
    • collecting / Scraping the web and collecting files, How it works…
  • filesystem directories
    • crawling / Crawling filesystem directories and printing a tree, How to do it..., How it works...
  • firewall
    • Linux IPtables, using for / Using Linux iptables for a firewall, How to do it..., How it works...
  • float / Creating and using basic variables
  • for loop
    • about / For loop
    • functions, using with parameters / Using a function with parameters within a for loop
  • format / Basic searching for strings and files
  • functions
    • using / Using functions and parameters

G

  • git command / Parsing a GitHub project and generate a report
  • GitHub project
    • parsing / Parsing a GitHub project and generate a report, How it works…
  • global context / Hidden Bash variables and reserved words
  • globbing / Using wildcards and regexes
  • graphics
    • creating, on CLI / Creating graphics and presentations on the CLI, How it works...
  • grep command / Linking commands, pipes, and input/output, How it works..., How to do it…
  • groups
    • creating / How to do it...

H

  • head command / Viewing files from various angles – head, tail, less, and more
  • headers
    • including / Including source files
  • here-string / How it works...
  • hexadecimal / Formatting your data/output using echo and printf
  • hidden variables / Hidden Bash variables and reserved words
  • high-quality scripts
    • writing / Writing high-quality scripts by example, How it works...
  • HTTP GET method / How to do it…
  • HTTP POST method / How to do it…
  • hunk / How it works...

I

  • if statement / Conditional logic using if, else, and elseif
  • incremental remote backup
    • creating / Creating a poor man's incremental remote backup, How it works…
  • inotify / Monitoring directories and files
  • inotifywait command / How it works...
  • integer / Creating and using basic variables
  • integrated development editors (IDEs) / Getting started with Bash and CLI fundamentals
  • internationalization
    • script, reading for languages / Readying your script for different languages with internationalization, Getting ready, How to do it..., How it works...
  • inverted logic / How it works...
  • IP addresses
    • blocking, from failed SSH attempts / Blocking IP addresses from failed SSH attempts, How it works…
  • iptables / Using Linux iptables for a firewall
  • iwconfig command / Linking commands, pipes, and input/output

J

  • jobs / Getting ready

L

  • lame utility HTTP server
    • creating / Creating a lame utility HTTP server, How to do it…, How it works…
  • less command / Viewing files from various angles – head, tail, less, and more
  • library script
    • including / Including/importing a library script and using external functions
    • importing / Including/importing a library script and using external functions
  • Linux IPtables
    • using, for firewall / Using Linux iptables for a firewall, How to do it..., How it works...
  • literal string / Creating and using basic variables
  • log files
    • managing / How to do it..., How it works...
  • logrotate command / Getting ready
  • logs
    • files, rotating from RAM to storage / Rotating files from RAM to storage for log rotation
  • loops
    • until loop / Until loop
    • writing / Writing one-line conditional statements and loops, How it works...
  • Lorem Ipsum / How it works...
  • ls command / Getting started with Bash and CLI fundamentals

M

  • man command / Getting additional information about commands
  • math
    • in scripts / Math and calculations in script, Getting ready, How to do it..., How it works...
  • MD5sum / Finding and deleting duplicate files or directories
  • media file
    • backing up / Backing up and erasing media, disks, and partitions with DD, How to do it...
    • erasing / Backing up and erasing media, disks, and partitions with DD
  • more command / Viewing files from various angles – head, tail, less, and more
  • mount command / Mounting network file systems and retrieving files, How to do it...

N

  • name
    • files, searching by / Searching for files by name and/or extension, Getting ready, How to do it..., How it works...
  • named pipes / How to do it...
  • nested conditional statements / Nested if statements
  • network file systems
    • mounting / Mounting network file systems and retrieving files, How it works...
  • network information
    • gathering / Getting ready, How to do it..., How it works...
  • network traffic
    • capturing, headlessly / Capturing network traffic headlessly, How to do it...

O

  • one-line conditional statements
    • writing / Writing one-line conditional statements and loops, How it works...
  • OpenSSL / How it works...
  • output
    • retrieving / Retrieving return codes and output
    • echoing, to raw terminal devices / Echoing output to raw terminal devices, How to do it...
  • output format
    • altering / Reading delimited data and altered output format, Getting ready, How to do it..., How it works...
  • output HTML / How to do it…

P

  • parameters
    • using / Using functions and parameters
  • passwordless remote access
    • SSH keys, creating for / Creating SSH keys for password less remote access, How to do it...
  • patch / Creating a diff of two files and patching
  • patching / How to do it..., How it works...
  • pattern / Basic searching for strings and files
  • pipes / Redirection and pipe bonzanza, Creating a file-in-file-out program and running processes in parallel
  • play command / How it works…
  • portability
    • improving / Avoiding command not found warnings/errors and improving portability, How it works...
  • presentations
    • creating, on CLI / Creating graphics and presentations on the CLI, How it works...
  • printf
    • data, formatting / Formatting your data/output using echo and printf
    • output, formatting / Formatting your data/output using echo and printf
  • processes
    • running, in parallel / Creating a file-in-file-out program and running processes in parallel, How to do it..., How it works...
  • program flags
    • passing / Passing your program flags
  • program input parameters
    • obtaining / Getting program input parameters 
  • programs
    • keeping running, after logoff / Keeping programs/scripts running after logoff, Getting ready, How to do it..., How it works...
    • temporary files, using / Using temporary files and lock files in your program, Getting ready, How it works...
    • lock files, using / Using temporary files and lock files in your program, Getting ready, How it works...
  • pwd command / Getting started with Bash and CLI fundamentals

R

  • raw terminal devices
    • output, echoing to / Echoing output to raw terminal devices, How to do it...
  • readarray command / How it works...
  • recursive functionality / Introduction
  • redirection / Redirection and pipe bonzanza
  • regexes
    • using / Using wildcards and regexes, Getting ready, How to do it..., How it works...
    • reference / How it works...
  • report
    • generating / Getting ready
  • reserved words
    • about / Hidden Bash variables and reserved words
    • reference / Hidden Bash variables and reserved words
  • restricted Bash shells
    • used, for securing scripts / Using chroot and restricted Bash shells to secure scripts, How it works…
  • return codes
    • retrieving / Retrieving return codes and output
  • return codes 101 / Return code 101
  • root user / Getting started with Bash and CLI fundamentals
  • RSS feeds
    • parsing / Parsing RSS feeds and output HTML

S

  • scope / Creating and using basic variables
  • scp command / How to do it...
  • scripts
    • running, indefinitely / Running a program continuously (forever) using looping constructs or recursion, Getting ready, How to do it..., How it works...
    • keeping running, after logoff / Keeping programs/scripts running after logoff, Getting ready, How to do it..., How it works...
    • executing, on startup / Executing your script on startup, Getting ready, How to do it..., How it works...
    • files, encrypting from / Getting ready
    • files, decrypting from / Getting ready
    • securing, restricted Bash shells used / Using chroot and restricted Bash shells to secure scripts, How it works…
    • securing, chroot used / Using chroot and restricted Bash shells to secure scripts, How it works…
    • runtime, calculating / Calculating and reducing the runtime of a script, How it works...
    • runtime, reducing / Calculating and reducing the runtime of a script, How it works...
  • Select
    • used, for making simple user menu / Making a simple multi-level user menu using select, How to do it..., How it works...
  • SHA512sum / Finding and deleting duplicate files or directories
  • shell
    • about / Getting started with Bash and CLI fundamentals
    • improving / Improving your shell – GCC and command line colors, How to do it..., How it works...
  • shell script
    • about / Getting started with Bash and CLI fundamentals
    • config file, using in / Creating a config file and using it in tandem with your scripts, How to do it...
  • SIGHUP / Generating and trapping signals for cleanup
  • sign / How it works...
  • signals
    • generating / Generating and trapping signals for cleanup, Getting ready, How it works...
    • trapping, for cleanup / Generating and trapping signals for cleanup, Getting ready, How it works...
  • simple frontend GUIs
    • creating, for Bash scripts / Creating simple frontend GUIs for Bash scripts, How to do it...
  • simple IRC chat bot logger
    • making / Making a simple IRC chat bot logger, How to do it…, How it works…
  • simple NAT firewall
    • creating / Creating a simple NAT and DMZ firewall, How it works…
  • source files
    • including / Including source files
  • SoX / Playing and managing audio from Bash
  • SQL databases
    • accessing, remotely / Accessing SQL databases remotely or locally, How it works...
    • accessing, locally / Getting ready, How it works...
  • SSH keys
    • creating, for passwordless remote access / Creating SSH keys for password less remote access, How to do it...
  • statistics
    • calculating / Calculating statistics and reducing duplicates based on file contents, How to do it..., How it works...
  • stream editor (SED)
    • about / Using SED and AWK to remove/replace substrings
    • used, for removing substrings / Getting ready, How it works...
  • strings
    • about / Creating and using basic variables
    • evaluating / Evaluating strings
    • basic searching / Basic searching for strings and files, How to do it..., How it works...
    • striping / Striping/altering/sorting/deleting/searching strings with Bash only, Getting ready, How to do it...
    • altering / Striping/altering/sorting/deleting/searching strings with Bash only, How to do it..., How it works...
    • sorting / Striping/altering/sorting/deleting/searching strings with Bash only, How to do it...
    • deleting / How to do it...
    • searching / How it works...
  • substitute user do (Sudo) / Invoking commands when they require permissions
  • substrings
    • removing, SED used / Getting ready, How it works...
    • replacing, AWK used / Getting ready, How it works...
  • switch statement
    • creating / Case/switch statements and loop constructs
  • symbolic links
    • creating / Creating symbolic links and using them effectively, How to do it...
    • using / How to do it..., How it works...
  • Syslog entries
    • creating / Creating Syslog entries and generating an alarm  , How to do it..., How it works...
  • system information
    • gathering / Gathering and aggregating system information, How to do it..., How it works...
    • aggregating / Gathering and aggregating system information, How to do it..., How it works...

T

  • tail command / Linking commands, pipes, and input/output, Viewing files from various angles – head, tail, less, and more
  • tampering
    • checking for / Checking for file integrity and tampering
  • TAR file / How it works...
  • tcpdump / Capturing network traffic headlessly
  • terminal / Getting started with Bash and CLI fundamentals
  • terminal sessions
    • recording, for automation / Recording terminal sessions for automation, How it works...
  • time
    • fetching, from different locations / Fetching time from different locations, How it works...
  • time command / Calculating and reducing the runtime of a script, How to do it...
  • timeout
    • leveraging, on wait for command completion / Leveraging timeout when waiting for command completion, How to do it..., How it works...
  • TLP / Using Bash to monitor battery life and optimize it, How it works…
  • tree
    • printing / Crawling filesystem directories and printing a tree, How to do it..., How it works...
  • ttyrec tool / Recording terminal sessions for automation

U

  • udev input
    • monitoring, Bash scripts used / Using Bash scripts to monitor udev input, How it works…
  • until loop / Until loop
  • useradd command / How to do it...
  • user input
    • sanitizing / Sanitizing user input and for repeatable results, Getting ready, How to do it..., How it works...
  • user menu
    • making, Select used / Making a simple multi-level user menu using select, How to do it..., How it works...
  • user paths
    • altering / Adding aliases, and altering user paths/variables
  • users
    • creating / Creating users and groups systematically
  • UTF / Basic searching for strings and files

V

  • variable assignment / Hands-on variable assignment
  • variables
    • creating / Creating and using basic variables
    • using / Creating and using basic variables
    • hidden variables / Hidden Bash variables and reserved words
    • altering / Adding aliases, and altering user paths/variables
  • Vim
    • Bash script, creating / Your first Bash script with Vim
    • reference / Your first Bash script with Vim

W

  • W3M / Browsing the web from the CLI
  • web
    • browsing, from CLI / Browsing the web from the CLI, How it works...
    • scraping / Scraping the web and collecting files, How it works…
  • wget utility / How it works…
  • whoami command / Getting started with Bash and CLI fundamentals
  • wildcards
    • using / Using wildcards and regexes, Getting ready, How to do it..., How it works...
  • wpa_supplicant / Configuring basic network connectivity

Z

  • zenity tool
    • about / Creating simple frontend GUIs for Bash scripts
    • working / How it works...
  • zip / How it works...
lock icon The rest of the chapter is locked
arrow left Previous Section
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}