Linux Shell Scripting Cookbook - Third Edition

Book description

Do amazing things with the shell

About This Book

  • Become an expert in creating powerful shell scripts and explore the full possibilities of the shell

  • Automate any administrative task you could imagine, with shell scripts

  • Packed with easy-to-follow recipes on new features on Linux, particularly, Debian-based, to help you accomplish even the most complex tasks with ease

  • Who This Book Is For

    If you are a beginner or an intermediate Linux user who wants to master the skill of quickly writing scripts and automate tasks without reading the entire man pages, then this book is for you. You can start writing scripts and one-liners by simply looking at the relevant recipe and its descriptions without any working knowledge of shell scripting or Linux. Intermediate / advanced users, system administrators / developers, and programmers can use this book as a reference when they face problems while coding.

    What You Will Learn

  • Interact with websites via scripts

  • Write shell scripts to mine and process data from the Web

  • Automate system backups and other repetitive tasks with crontab

  • Create, compress, and encrypt archives of your critical data.

  • Configure and monitor Ethernet and wireless networks

  • Monitor and log network and system activity

  • Tune your system for optimal performance

  • Improve your system's security

  • Identify resource hogs and network bottlenecks

  • Extract audio from video files

  • Create web photo albums

  • Use git or fossil to manage revision control and interact with FOSS projects

  • Create and maintain Linux containers and Virtual Machines

  • Run a private Cloud server

  • In Detail

    The shell is the most powerful tool your computer provides. Despite having it at their fingertips, many users are unaware of how much the shell can accomplish.

    Using the shell, you can generate databases and web pages from sets of files, automate monotonous admin tasks such as system backups, monitor your system's health and activity, identify network bottlenecks and system resource hogs, and more.

    This book will show you how to do all this and much more.

    This book, now in its third edition, describes the exciting new features in the newest Linux distributions to help you accomplish more than you imagine. It shows how to use simple commands to automate complex tasks, automate web interactions, download videos, set up containers and cloud servers, and even get free SSL certificates.

    Starting with the basics of the shell, you will learn simple commands and how to apply them to real-world issues. From there, you'll learn text processing, web interactions, network and system monitoring, and system tuning.

    Software engineers will learn how to examine system applications, how to use modern software management tools such as git and fossil for their own work, and how to submit patches to open-source projects.

    Finally, you'll learn how to set up Linux Containers and Virtual machines and even run your own Cloud server with a free SSL Certificate from letsencrypt.org.

    Style and approach

    This book will take you through useful real-world recipes designed to make your daily life easier when working with the shell.

    Table of contents

    1. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Sections
        1. Getting ready
        2. How to do it…
        3. How it works…
        4. There's more…
        5. See also
      5. Conventions
      6. Reader feedback
      7. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    2. Shell Something Out
      1. Introduction
      2. Displaying output in a terminal
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Escaping newline in echo
          2. Printing a colored output
      3. Using variables and environment variables
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Finding the length of a string
          2. Identifying the current shell
          3. Checking for super user
          4. Modifying the Bash prompt string (username@hostname:~$)
      4. Function to prepend to environment variables
        1. How to do it...
        2. How it works...
      5. Math with the shell
        1. How to do it...
      6. Playing with file descriptors and redirection
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Redirection from a file to a command
          2. Redirecting from a text block enclosed within a script
          3. Custom file descriptors
      7. Arrays and associative arrays
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Defining associative arrays
          2. Listing of array indexes
      8. Visiting aliases
        1. How to do it...
        2. There's more...
          1. Escaping aliases
          2. Listing aliases
      9. Grabbing information about the terminal
        1. Getting ready
        2. How to do it...
      10. Getting and setting dates and delays
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Producing delays in a script
      11. Debugging the script
        1. How to do it...
        2. How it works...
        3. There's more...
          1. Shebang hack
      12. Functions and arguments
        1. How to do it...
        2. There's more...
          1. The recursive function
          2. Reading the return value (status) of a command
          3. Passing arguments to commands
      13. Sending output from one command to another
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Spawning a separate process with subshell
          2. Subshell quoting to preserve spacing and the newline character
      14. Reading n characters without pressing the return key
        1. How to do it...
      15. Running a command until it succeeds
        1. How to do it...
        2. How it works...
        3. There's more...
          1. A faster approach
          2. Adding a delay
      16. Field separators and iterators
        1. Getting ready
        2. How to do it...
      17. Comparisons and tests
        1. How to do it...
      18. Customizing bash with configuration files
        1. How to do it...
    3. Have a Good Command
      1. Introduction
      2. Concatenating with cat
        1. How to do it...
        2. There's more...
          1. Getting rid of extra blank lines
          2. Displaying tabs as ^I
          3. Line numbers
      3. Recording and playing back terminal sessions
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Finding files and file listing
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Search based on name or regular expression match
          2. Negating arguments
          3. Searching based on the directory depth
          4. Searching based on file type
          5. Searching by file timestamp
          6. Searching based on file size
          7. Matching based on file permissions and ownership
          8. Performing actions on files with find
          9. Deleting based on file matches
          10. Executing a command
          11. Skipping specified directories when using the find command
      5. Playing with xargs
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Passing formatted arguments to a command by reading stdin
          2. Using xargs with find
          3. Counting the number of lines of C code in a source code directory
          4. While and subshell trick with stdin
      6. Translating with tr
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Deleting characters using tr
          2. Complementing character sets
          3. Squeezing characters with tr
          4. Character classes
      7. Checksum and verification
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Checksum for directories
      8. Cryptographic tools and hashes
        1. How to do it...
      9. Sorting unique and duplicate lines
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Sorting according to keys or columns
          2. uniq
      10. Temporary file naming and random numbers
        1. How to do it...
        2. How it works...
      11. Splitting files and data
        1. How to do it...
        2. There's more...
          1. Specifying a filename prefix for the split files
      12. Slicing filenames based on extensions
        1. How to do it...
        2. How it works...
      13. Renaming and moving files in bulk
        1. Getting ready
        2. How to do it...
        3. How it works...
      14. Spell–checking and dictionary manipulation
        1. How to do it...
        2. How it works...
      15. Automating interactive input
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Automating with expect
      16. Making commands quicker by running parallel processes
        1. How to do it...
        2. How it works...
        3. There's more...
      17. Examining a directory, files and subdirectories in it
        1. Getting ready
        2. How to do it...
          1. Generating a tree view of a directory.
          2. Generating a summary of files and sub-directories
    4. File In, File Out
      1. Introduction
      2. Generating files of any size
        1. How to do it...
      3. The intersection and set difference (A-B) on text files
        1. Getting ready
        2. How to do it...
        3. How it works...
      4. Finding and deleting duplicate files
        1. Getting ready
        2. How to do it...
        3. How it works...
      5. Working with file permissions, ownership, and the sticky bit
        1. How to do it...
        2. There's more...
          1. Changing ownership
          2. Setting the sticky bit
          3. Applying permissions recursively to files
          4. Applying ownership recursively
          5. Running an executable as a different user (setuid)
      6. Making files immutable
        1. Getting ready
        2. How to do it...
      7. Generating blank files in bulk
        1. Getting ready
        2. How to do it...
      8. Finding symbolic links and their targets
        1. How to do it...
        2. How it works...
      9. Enumerating file type statistics
        1. Getting ready
        2. How to do it...
        3. How it works...
      10. Using loopback files
        1. How to do it...
        2. How it works...
        3. There's more...
          1. Creating partitions inside loopback images
          2. Mounting loopback disk images with partitions more quickly
          3. Mounting ISO files as loopback
          4. Flush changing immediately with sync
      11. Creating ISO files and hybrid ISO
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Hybrid ISO that boots off a flash drive or hard disk
          2. Burning an ISO from the command line
          3. Playing with the CD-ROM tray
      12. Finding the difference between files, and patching
        1. How to do it...
        2. There's more...
          1. Generating difference against directories
      13. Using head and tail for printing the last or first 10 lines
        1. How to do it...
      14. Listing only directories - alternative methods
        1. Getting ready
        2. How to do it...
        3. How it works...
      15. Fast command-line navigation using pushd and popd
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. pushd and popd are useful when there are more than three directory paths used. However, when you use only two locations, there is an alternative and easier way, that is, cd -.
      16. Counting the number of lines, words, and characters in a file
        1. How to do it...
      17. Printing the directory tree
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. HTML output for tree
      18. Manipulating video and image files
        1. Getting ready
          1. Extracting Audio from a movie file (mp4)
        2. How to do it...
          1. Making a video from a set of still images
            1. How to do it...
            2. How it works...
          2. Creating a panned video from a still camera shot
            1. How to do it...
            2. How it works...
    5. Texting and Driving
      1. Introduction
      2. Using regular expressions
        1. How to do it...
          1. Position markers
          2. Identifiers
          3. Count modifiers
          4. Other
          5. There's more...
        2. How it works...
        3. There's more...
          1. Treatment of special characters
          2. Visualizing regular expressions
      3. Searching and mining text inside a file with grep
        1. How to do it...
        2. There's more...
          1. Recursively searching many files
          2. Ignoring case in patterns
          3. grep by matching multiple patterns
          4. Including and excluding files in a grep search
          5. Using grep with xargs with the zero-byte suffix
          6. Silent output for grep
          7. Printing lines before and after text matches
      4. Cutting a file column-wise with cut
        1. How to do it...
        2. There's more
          1. Specifying the range of characters or bytes as fields
      5. Using sed to perform text replacement
        1. How to do it...
        2. There's more...
          1. Removing blank lines
          2. Performing replacement directly in the file
          3. Matched string notation ()
          4. Substring match notation (\1)
          5. Combining multiple expressions
          6. Quoting
      6. Using awk for advanced text processing
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Special variables
          2. Passing an external variable to awk
          3. Reading a line explicitly using getline
          4. Filtering lines processed by awk with filter patterns
          5. Setting delimiters for fields
          6. Reading the command output from awk
          7. Associative arrays in Awk
          8. Using loop inside awk
          9. String manipulation functions in awk
      7. Finding the frequency of words used in a given file
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      8. Compressing or decompressing JavaScript
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      9. Merging multiple files as columns
        1. How to do it...
        2. See also
      10. Printing the nth word or column in a file or line
        1. How to do it...
        2. See also
      11. Printing text between line numbers or patterns
        1. Getting ready
        2. How to do it...
        3. See also
      12. Printing lines in the reverse order
        1. Getting ready
        2. How to do it...
        3. How it works...
      13. Parsing e-mail address and URLs from text
        1. How to do it...
        2. How it works...
        3. See also
      14. Removing a sentence in a file containing a word
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      15. Replacing a pattern with text in all the files in a directory
        1. How to do it...
        2. How it works...
        3. There's more...
      16. Text slicing and parameter operations
        1. How to do it...
        2. See also
    6. Tangled Web? Not At All!
      1. Introduction
      2. Downloading from a web page
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Restricting the download speed
          2. Resume downloading and continue
          3. Copying a complete website (mirroring)
          4. Accessing pages with HTTP or FTP authentication
      3. Downloading a web page as plain text
        1. Getting ready
        2. How to do it...
      4. A primer on cURL
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Continuing and resuming downloads
          2. Setting the referer string with cURL
          3. Cookies with cURL
          4. Setting a user agent string with cURL
          5. Specifying a bandwidth limit on cURL
          6. Specifying the maximum download size
          7. Authenticating with cURL
          8. Printing response headers excluding data
        5. See also
      5. Accessing unread Gmail e-mails from the command line
        1. How to do it...
        2. How it works...
        3. See also
      6. Parsing data from a website
        1. How to do it...
        2. How it works...
        3. See also
      7. Image crawler and downloader
        1. How to do it...
        2. How it works...
        3. See also
      8. Web photo album generator
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      9. Twitter command-line client
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      10. Accessing word definitions via a web server
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      11. Finding broken links in a website
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      12. Tracking changes to a website
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      13. Posting to a web page and reading the response
        1. Getting ready
        2. How to do it...
        3. See also
      14. Downloading a video from the Internet
        1. Getting ready
        2. How to do it...
        3. How it works...
      15. Summarizing text with OTS
        1. Getting ready
        2. How to do it...
        3. How it works...
      16. Translating text from the command line
        1. Getting ready
        2. How to do it...
        3. How it works...
    7. Repository Management
      1. Introduction
      2. Creating a new git repository
        1. Getting ready
        2. How to do it...
        3. How it works...
      3. Cloning a remote git repository
        1. How to do it...
      4. Adding and committing changes with git
        1. How to do it...
      5. Creating and merging branches with git
        1. Getting ready...
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Merging branches
            1. How to do it...
            2. How it works...
            3. There's more...
      6. Sharing your work
        1. How to do it...
      7. Pushing a branch to a server
        1. How to do it...
      8. Checking the status of a git repository
        1. How to do it...
        2. How it works...
      9. Viewing git history
        1. How to do it...
      10. Finding bugs
        1. How to do it...
        2. There's more...
          1. How to do it...
          2. How it works...
      11. Tagging snapshots
        1. How to do it...
      12. Committing message ethics
        1. How to do it...
      13. Using fossil
        1. Getting ready
        2. How to do it...
      14. Creating a new fossil repository
        1. How to do it...
        2. How it works...
        3. There's more...
          1. Web interface to fossil
            1. How to do it...
          2. Making a repository available to remote users
      15. Cloning a remote fossil repository
        1. How to do it...
        2. How it works...
      16. Opening a fossil project
        1. How to do it...
        2. How it works...
        3. There's more...
      17. Adding and committing changes with fossil
        1. How to do it...
        2. There's more...
      18. Using branches and forks with fossil
        1. How to do it
        2. How it works...
        3. There's more...
          1. Merging forks and branches
            1. How to do it...
      19. Sharing your work with fossil
        1. How to do it...
        2. How it works...
      20. Updating your local fossil repository
        1. How to do it...
      21. Checking the status of a fossil repository
        1. How to do it...
      22. Viewing fossil history
        1. How to do it...
          1. Finding bugs
            1. How to do it...
            2. There's more...
          2. Tagging snapshots
            1. How to do it...
            2. There's more...
    8. The Backup Plan
      1. Introduction
      2. Archiving with tar
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Appending files to an archive
          2. Extracting files and folders from an archive
          3. stdin and stdout with tar
          4. Concatenating two archives
          5. Updating files in an archive with a timestamp check
          6. Comparing files in the archive and filesystem
          7. Deleting files from the archive
          8. Compression with the tar archive
          9. Excluding a set of files from archiving
          10. Excluding version control directories
          11. Printing the total bytes
        5. See also
      3. Archiving with cpio
        1. How to do it...
        2. How it works...
      4. Compressing data with gzip
        1. How to do it...
        2. There's more...
          1. Gzip with tarball
          2. zcat - reading gzipped files without extracting
          3. Compression ratio
          4. Using bzip2
          5. Using lzma
        3. See also
      5. Archiving and compressing with zip
        1. How to do it...
        2. How it works...
      6. Faster archiving with pbzip2
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Manually specifying the number of CPUs
          2. Specifying the compression ratio
      7. Creating filesystems with compression
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Excluding files while creating a squashfs file
      8. Backing up snapshots with rsync
        1. How to do it...
        2. How it works...
        3. There's more...
          1. Excluding files while archiving with rsync
          2. Deleting non-existent files while updating rsync backup
          3. Scheduling backups at intervals
      9. Differential archives
        1. How to do it...
        2. How it works...
      10. Creating entire disk images using fsarchiver
        1. Getting ready
        2. How to do it...
        3. How it works...
    9. The Old-Boy Network
      1. Introduction
      2. Setting up the network
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Printing the list of network interfaces
          2. Displaying IP addresses
          3. Spoofing the hardware address (MAC address)
          4. Name server and DNS (Domain Name Service)
            1. DNS lookup
          5. Showing routing table information
        4. See also
      3. Let us ping!
        1. How to do it...
        2. There's more...
          1. Round Trip Time
          2. Sequence number
          3. Time to live
          4. Limiting the number of packets to be sent
          5. Return status of the ping command
      4. Tracing IP routes
        1. How to do it...
      5. Listing all available machines on a network
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Parallel pings
            1. Using fping
        5. See also
      6. Running commands on a remote host with SSH
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. SSH with compression
          2. Redirecting data into stdin of remote host shell commands
      7. Running graphical commands on a remote machine
        1. How to do it...
        2. See also
      8. Transferring files through the network
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Automated FTP transfer
          2. SFTP (Secure FTP)
          3. The rsync command
          4. SCP (secure copy program)
          5. Recursive copying with scp
        4. See also
      9. Connecting to a wireless network
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      10. Password-less auto-login with SSH
        1. Getting ready
        2. How to do it...
      11. Port forwarding using SSH
        1. How to do it...
        2. There's more...
          1. Non-interactive port forward
          2. Reverse port forwarding
      12. Mounting a remote drive at a local mount point
        1. Getting ready
        2. How to do it...
        3. See also
      13. Network traffic and port analysis
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Opened port and services using netstat
      14. Measuring network bandwidth
        1. How to do it...
      15. Creating arbitrary sockets
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Quickly copying files over the network
          2. Creating a broadcasting server
        4. How it works...
      16. Building a bridge
        1. Getting ready
        2. How to do it...
      17. Sharing an Internet connection
        1. Getting ready
        2. How to do it...
        3. How it works
      18. Basic firewall using iptables
        1. How to do it...
        2. How it works...
        3. There's more...
      19. Creating a Virtual Private Network
        1. Getting ready
        2. How to do it...
          1. Creating certificates
          2. Configuring OpenVPN on the server
          3. Configuring OpenVPN on the client
          4. Starting the server
          5. Starting and testing a client
    10. Put On the Monitors Cap
      1. Introduction
      2. Monitoring disk usage
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Displaying disk usage in KB, MB, or blocks
          2. Displaying the grand total sum of disk usage
          3. Printing sizes in specified units
          4. Excluding files from the disk usage calculation
          5. Finding the ten largest size files from a given directory
          6. Disk free information
      3. Calculating the execution time for a command
        1. How to do it...
        2. How it works...
      4. Collecting information about logged in users, boot logs, and boot failures
        1. Getting ready
        2. How to do it...
      5. Listing the top ten CPU– consuming processes in an hour
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      6. Monitoring command outputs with watch
        1. How to do it...
        2. There's more
          1. Highlighting the differences in the watch output
      7. Logging access to files and directories
        1. Getting ready
        2. How to do it...
        3. How it works...
      8. Logging with syslog
        1. Getting ready
        2. How to do it...
        3. See also
      9. Managing log files with logrotate
        1. Getting ready
        2. How to do it...
        3. How it works...
      10. Monitoring user logins to find intruders
        1. Getting ready
        2. How to do it...
        3. How it works...
      11. Monitoring remote disk usage health
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      12. Determining active user hours on a system
        1. Getting ready
        2. How to do it...
        3. How it works...
      13. Measuring and optimizing power usage
        1. Getting ready
        2. How to do it...
      14. Monitoring disk activity
        1. Getting ready
        2. How to do it...
      15. Checking disks and filesystems for errors
        1. Getting ready
        2. How to do it...
        3. How it works...
      16. Examining disk health
        1. Getting ready
        2. How to do it...
        3. How it works
      17. Getting disk statistics
        1. Getting ready
        2. How to do it...
        3. How it works
        4. There's more
    11. Administration Calls
      1. Introduction
      2. Gathering information about processes
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Showing environment variables for a process
          2. Creating a tree view of processes
          3. Sorting ps output
          4. Filters with ps for real user or ID, effective user or ID
          5. TTY filter for ps
          6. Information about process threads
          7. Specifying the output width and columns to be displayed
      3. What's what – which, whereis, whatis, and file
        1. How to do it...
          1. Finding the process ID from the given command names
          2. Determining how busy a system is
          3. The top command
        2. See also...
      4. Killing processes, and sending and responding to signals
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. The kill family of commands
          2. Capturing and responding to signals
      5. Sending messages to user terminals
        1. Getting ready
        2. How to do it...
          1. Sending one message to one user
          2. Holding a conversation with another user
          3. Sending a message to all users
      6. The /proc filesystem
        1. How to do it...
      7. Gathering system information
        1. How to do it...
      8. Scheduling with a cron
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
          1. Specifying environment variables
          2. Running commands at system start-up/boot
          3. Viewing the cron table
          4. Removing the cron table
      9. Database styles and uses
        1. Getting ready
        2. How to do it...
        3. There's more...
          1. Creating a table
          2. Inserting a row into an SQL database
          3. Selecting rows from a SQL database
      10. Writing and reading SQLite databases
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      11. Writing and reading a MySQL database from Bash
        1. Getting ready
        2. How to do it...
        3. How it works...
      12. User administration scripts
        1. How to do it...
        2. How it works...
      13. Bulk image resizing and format conversion
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. See also
      14. Taking screenshots from the terminal
        1. Getting ready
        2. How to do it...
      15. Managing multiple terminals from one
        1. Getting ready
        2. How to do it...
    12. Tracing the Clues
      1. Introduction
      2. Tracing packets with tcpdump
        1. Getting ready
        2. How to do it...
          1. Displaying only HTTP packets
          2. Displaying only HTTP packets generated by this host
          3. Viewing the packet payload as well as headers
        3. How it works...
      3. Finding packets with ngrep
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
      4. Tracing network routes with ip
        1. Getting ready
        2. How to do it...
          1. Reporting routes with ip route
          2. Tracing recent IP connections and the ARP table
          3. Tracing a route
          4. How it works...
      5. Tracing system calls with strace
        1. Getting ready
        2. How to do it...
        3. How it works...
      6. Tracing dynamic library functions with ltrace
        1. Getting ready
        2. How to do it...
        3. How it works...
        4. There's more...
    13. Tuning a Linux System
      1. Introduction
      2. Identifying services
        1. Getting ready
        2. How to do it...
          1. systemd-based computers
          2. RedHat-based computers
          3. Debian-based computers
        3. There's more
      3. Gathering socket data with ss
        1. Getting ready
        2. How to do it...
          1. Displaying the status of tcp sockets
          2. Tracing applications listening on ports
        3. How it works
      4. Gathering system I/O usage with dstat
        1. Getting ready
        2. How to do it...
          1. Viewing system activity
        3. How it works
        4. There's more...
      5. Identifying a resource hog with pidstat
        1. Getting ready
        2. How to do it...
        3. How it works
      6. Tuning the Linux kernel with sysctl
        1. Getting started
        2. How to do it...
          1. Tuning the task scheduler
          2. Tuning a network
        3. How it works
        4. There's more...
      7. Tuning a Linux system with config files
        1. Getting ready
        2. How to do it...
        3. How it works
      8. Changing scheduler priority using the nice command
        1. How to do it...
        2. How it works
        3. There's more
    14. Containers, Virtual Machines, and the Cloud
      1. Introduction
      2. Using Linux containers
        1. Getting ready
        2. How to do it...
          1. Creating a privileged container
          2. Starting a container
          3. Stopping a container
          4. Listing known containers
          5. Displaying container information
          6. Creating an unprivileged container
          7. Creating an Ethernet bridge
        3. How it works...
      3. Using Docker
        1. Getting ready
        2. How to do it...
          1. Finding a container
          2. Downloading a container
          3. Starting a Docker container
          4. Listing the Docker sessions
          5. Attaching your display to a running Docker container
          6. Stopping a Docker session
          7. Removing a Docker instance
        3. How it works
      4. Using Virtual Machines in Linux
        1. Getting ready
        2. How to do it...
      5. Linux in the cloud
        1. Getting ready
          1. Ubuntu 16.10
          2. OpenSuSE Tumbleweed
        2. How to do it...
          1. Configuring OwnCloud
        3. There's more...

    Product information

    • Title: Linux Shell Scripting Cookbook - Third Edition
    • Author(s): Clif Flynt, Sarath Lakshman, Shantanu Tushar
    • Release date: May 2017
    • Publisher(s): Packt Publishing
    • ISBN: 9781785881985