Linux Command Line and Shell Scripting Techniques: Master practical aspects of the Linux command line and then use it as a part of the shell scripting process

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Practical and actionable recipes for using shell and command-line scripting on your Linux OS with confidence

Key Features

  • Learn how to use the command line and write and debug Linux Shell scripts
  • Automate complex repetitive tasks and backups, and learn networking and security
  • A practical approach to system administration, and virtual machine and software management

Book Description

Linux Command Line and Shell Scripting Techniques begins by taking you through the basics of the shell and command-line utilities. You'll start by exploring shell commands for file, directory, service, package, and process management. Next, you'll learn about networking - network, firewall and DNS client configuration, ssh, scp, rsync, and vsftpd, as well as some network troubleshooting tools.

You'll also focus on using the command line to find and manipulate text content, via commands such as cut, egrep, and sed. As you progress, you'll learn how to use shell scripting. You'll understand the basics - input and output, along with various programming concepts such as loops, variables, arguments, functions, and arrays. Later, you'll learn about shell script interaction and troubleshooting, before covering a wide range of examples of complete shell scripts, varying from network and firewall configuration, through to backup and concepts for creating live environments. This includes examples of performing scripted virtual machine installation and administration, LAMP (Linux, Apache, MySQL, PHP) stack provisioning and bulk user creation for testing environments.

By the end of this Linux book, you'll have gained the knowledge and confidence you need to use shell and command-line scripts.

What you will learn

  • Get an introduction to the command line, text editors, and shell scripting
  • Focus on regular expressions, file handling, and automating complex tasks
  • Automate common administrative tasks
  • Become well-versed with networking and system security scripting
  • Get to grips with repository management and network-based file synchronization
  • Use loops, arguments, functions, and arrays for task automation

Who this book is for

This book is for anyone looking to learn about Linux administration via CLI and scripting. Those with no Linux command-line interface (CLI) experience will benefit from it by learning from scratch. More experienced Linux administrators or engineers will also find this book useful, as it will help them organize their knowledge, fill in any gaps, and work efficiently with shell scripts to increase productivity.

Table of Contents

  1. Basics of Shell and Text Terminal
  2. Using Text Editors
  3. Using Commands and Services for Process Management
  4. Using Shell to Configure and Troubleshoot Network
  5. Using Commands for File, Directory, and Service Management
  6. Shell-Based Software Management
  7. Network-Based File Synchronization
  8. Using the Command Line to Find, Extract, and Manipulate Text Content
  9. An Introduction to Shell Scripting
  10. Using Loops
  11. Working with Variables
  12. Using Arguments and Functions
  13. Using Arrays
  14. Interacting with Shell Scripts
  15. Troubleshooting Shell Scripts
  16. Shell Script Examples for Server Management, Network Configuration, and Backups
  17. Advanced Shell Script Examples

Author(s): Vedran Dakic, Jasmin Redzepagic
Edition: 1
Publisher: Packt Publishing
Year: 2022

Language: English
Pages: 552
Tags: GNU/Linux; bash; command line; scripting; shell scripting;

Cover
Title Page
Copyright and Credits
Contributors
Table of Contents
Preface
Chapter 1: Basics of Shell and Text Terminal
Technical requirements
Accessing the shell
Getting ready
How to do it…
How it works…
See also
Setting up the user shell
Getting ready
How to do it…
How it works…
Setting up the Bash shell
Getting ready
How to do it…
How it works…
There's more…
Using the most common shell commands
Getting ready
How to do it…
How it works...
Using screen
Getting ready
How to do it…
How it works…
There's more…
Chapter 2: Using Text Editors
Technical requirements
Learning the basics of the Vi(m) Editor
Getting ready
How to do it…
How it works…
See also
Learning the basics of the nano editor
Getting ready
How to do it…
There's more…
Going through the advanced Vi(m) settings
Getting ready
How to do it…
How it works…
There's more…
Chapter 3: Using Commands and Services for Process Management
Technical requirements
Process management tools
Getting ready
How to do it…
How it works…
See also
Managing background jobs
Getting ready
How to do it…
How it works…
There's more…
Managing process priorities
Getting ready
How to do it…
How it works…
There's more…
Configuring crond
Getting ready
How to do it…
How it works…
There's more…
Chapter 4: Using Shell to Configure and Troubleshoot a Network
Technical requirements
Using nmcli and netplan
Getting ready
How to do it
How it works
There's more
Using firewall-cmd and ufw
Getting ready
How to do it
How it works
There's more
Working with open ports and connections
Getting ready
How to do it
How it works
There's more
Configuring /etc/hosts and DNS resolving
Getting ready
How to do it
How it works
There's more
Using network diagnostic tools
Getting ready
How to do it
How it works
There's more
Chapter 5: Using Commands for File, Directory, and Service Management
Technical requirements
Basic file and directory-based commands
Getting ready
How to do it…
How it works…
See also
Additional commands for manipulating file/directory security aspects
Getting ready
How to do it…
How it works…
See also
Manipulating text files by using commands
Getting ready
How to do it…
How it works…
There's more…
Finding files and folders
Getting ready
How to do it…
How it works…
There's more…
Archiving and compressing files and folders
Getting ready
How to do it…
How it works…
There's more…
Managing services and targets
Getting ready
How to do it…
How it works…
There's more…
Chapter 6: Shell-Based Software Management
Technical requirements
Using dnf and apt for package management
Getting ready
How to do it…
How it works…
There's more…
Using additional repositories, streams, and profiles
Getting ready
How to do it…
How it works…
Creating custom repositories
Getting ready
How to do it…
How it works…
There's more…
Compiling third-party software
Getting ready
How to do it…
How it works…
There's more…
Chapter 7: Network-Based File Synchronization
Technical requirements
Learning how to use SSH and SCP
Getting ready
How to do it…
How it works…
There's more…
Learning how to use rsync
Getting ready
How to do it…
How it works…
There's more…
Using vsftpd
Getting ready
How to do it…
How it works…
There's more
Chapter 8: Using the Command Line to Find, Extract, and Manipulate Text Content
Technical requirements
Using text commands to merge file content
Getting ready
How to do it…
How it works…
There's more…
Converting DOS text to Linux text and vice versa
Getting ready
How to do it…
How it works…
There's more…
Using cut
Getting ready
How to do it…
How it works…
There's more…
Using egrep
Getting ready
How to do it…
How it works…
There's more…
Using sed
Getting ready
How to do it…
How it works…
There's more…
Chapter 9: An Introduction to Shell Scripting
Technical requirements
Writing your first Bash shell script
Getting ready
How to do it…
How it works…
Serializing basic commands – from simple to complex
Getting ready
How to do it…
How it works…
There's more…
Manipulating shell script input, output, and errors
Getting ready
How to do it…
How it works…
Shell script hygiene
Getting ready
How to do it…
There's more…
Chapter 10: Using Loops
The for loop
Getting ready
How to do it…
How it works…
See also
break and continue
Getting ready
How to do it…
How it works…
See also
The while loop
Getting ready
How to do it…
How it works…
See also
The test-if loop
Getting ready
How to do it…
How it works…
See also
The case loop
Getting ready
How to do it…
How it works…
See also
Logical looping with and, or, and not
Getting ready
How to do it…
How it works…
See also
Chapter 11: Working with Variables
Technical requirements
Using shell variables
Getting ready
How to do it…
How it works…
See also
Using variables in shell scripting
Getting ready
How to do it…
How it works…
See also
Quoting in the shell
Getting ready
How to do it…
How it works…
See also
Performing operations on variables
Getting ready
How to do it…
How it works…
See also
Variables via external commands
Getting ready
How to do it…
How it works…
See also
Chapter 12: Using Arguments and Functions
Technical requirements
Using custom functions in shell script code
Getting ready
How to do it…
How it works…
See also
Passing arguments to a function
Getting ready
How to do it…
How it works…
See also
Local and global variables
Getting ready
How to do it…
How it works…
See also
Working with returns from a function
Getting ready
How to do it…
How it works…
See also
Loading an external function to a shell script
Getting ready
How to do it…
How it works…
See also
Implementing commonly used procedures via functions
Getting ready
How to do it…
How it works…
See also
Chapter 13: Using Arrays
Technical requirements
Basic array manipulation
Getting ready
How to do it…
How it works…
See also
Advanced array manipulation
Getting ready
How to do it…
How it works…
See also
Chapter 14: Interacting with Shell Scripts
Technical requirements
Creating text-based interactive scripts
Getting ready
How to do it…
How it works…
See also
Using expect to automate repetitive tasks based on text output
Getting ready
How to do it…
How it works…
See also
Using dialog for menu-driven interactive scripts
Getting ready
How to do it…
How it works…
See also
Chapter 15: Troubleshooting Shell Scripts
Technical requirements
Common scripting mistakes
Getting ready
How to do it…
How it works…
See also…
Simple debugging approach – echoing values during script execution
Getting ready
How to do it…
How it works…
See also
Using the bash -x and -v options
Getting ready
How to do it…
How it works…
See also…
Using set to debug a part of the script
Getting ready
How to do it…
How it works…
See also…
Chapter 16: Shell Script Examples for Server Management, Network Configuration, and Backups
Technical requirements
Creating a file and folder inventory
How to do it…
See also
Checking if you're running as root
Getting ready
How to do it…
See also
Displaying server stats
Getting ready
How to do it…
There's more…
Finding files by name, ownership, or content type and copying them to a specified directory
Getting ready
How to do it…
There's more…
Parsing date and time data
Getting ready
How to do it…
Configuring the most common firewall settings interactively
Getting ready
How to do it…
There's more…
Configuring network settings interactively
Getting ready
How to do it…
There's more…
Backing up the current directory with shell script arguments and variables
Getting ready
How to do it…
There's more…
Creating a current backup based on the user input for the backup source and destination
Getting ready
How to do it…
There's more…
Chapter 17: Shell Script Examples
Technical requirements
Implementing a web server service and security settings
Getting ready
How to do it…
See also
Creating users and groups and forcing users to change them on the next login
Getting ready
How to do it…
See also
Creating users and groups from a standardized input file and a random password for each user
Getting ready
How to do it…
See also
Scripted VM installation on KVM
Getting ready
How to do it…
See also
Using a shell script to provision SSH keys
Getting ready
How to do it…
See also
A shell script for VM administration
Getting ready
How to do it…
See also
Index
Other Books You May Enjoy