Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Linux Command Line and Shell Scripting Techniques
Linux Command Line and Shell Scripting Techniques

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

Arrow left icon
Profile Icon Vedran Dakic Profile Icon Jasmin Redzepagic
Arrow right icon
$29.99 $43.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (5 Ratings)
eBook Mar 2022 552 pages 1st Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Vedran Dakic Profile Icon Jasmin Redzepagic
Arrow right icon
$29.99 $43.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (5 Ratings)
eBook Mar 2022 552 pages 1st Edition
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$29.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Linux Command Line and Shell Scripting Techniques

Chapter 2: Using Text Editors

There's just no way around the topic of this chapter, as system administrators edit text files daily. Therefore, we decided to cover three commonly used editors – vi, Vim, and nano. If you're more into GUI tools, make sure that you check gedit, although we won't cover that editor here as it's practically the same as using Notepad on Microsoft Windows. There are various reasons why these editors were chosen, but most importantly, they are installed out of the box on almost all Linux distributions, so they're the most common pre-installed editors. There are situations where additional software installation is not an option, such as air-gapped environments.

We will cover the following recipes in this chapter:

  • Learning the basics of the Vi(m) editor
  • Learning the basics of the nano editor
  • Going through the advanced Vi(m) settings

Technical requirements

For these recipes, we're going to use a Linux machine. We can use any virtual machine from our previous recipe. For example, let's say that we're going to use a cli1 virtual machine as it's the most convenient to use, seeing as it's a command-line-interface-only machine. So, all in all, we need the following:

  • A virtual machine with any distribution of Linux installed (in our case, it's going to be Ubuntu 20.10).
  • A bit of time to digest the complexities of using the Vi(m) editor. nano is less complex; therefore, it's going to be easier to learn about that one.

So, start your virtual machine and let's get cracking!

Learning the basics of the Vi(m) Editor

Vi and Vim are the text editors of choice for many system administrators and engineers. In a nutshell, the difference between them is that vim (vi improved) has many more capabilities than the original vi (visual editor). You can find these editors everywhere – from all the Unixes and Linuxes to the commercial Linux- or Unix-based software of today. For example, VMware's vSphere Hypervisor has a version of the vi editor built in. The rationale for this is simple – you need to have some sort of standardized editor that can be used to edit various text files available on a filesystem. Over the years, you'll surely find some cutdown version of vi or Vim on various network devices such as switches and routers, and even more complex devices like firewalls. It's just the way it is. If something's Unix- or Linux-based, chances are it's using text configuration files, and text configuration files need a text editor. Pretty straightforward logic, isn't it?

Just as an example – the Vim editor has spinoffs that can be used in a variety of different ways, including vim-athena (created with Athena GUI support), vim-gtk, and vim-gtk3 (created with GTK/GTK3 support), vim-tiny (a slimmed-down version of Vim), and vim-nox. But still, most people that we know of prefer using the good old-fashioned vi or Vim in a CLI.

For this first part of our recipe, we're going to explain the way vi and Vim work and use them to do some most common things, such as the following:

  • Three vi(m) modes – insert, command, and ex mode
  • Moving around a text file that we want to edit by moving the cursor
  • Deleting text (we could refer to it as cutting and deleting at the same time)
  • Inserting additional content into a text file
  • Saving and exiting in the vi(m) editors
  • Finding content in a text file
  • Copying and pasting text (what vi and Vim refer to as yank and paste)

That's going to be enough for this first recipe. We're going to go back to the advanced vim capabilities in the last recipe of this chapter, where we're going to dig much deeper into Vim and learn how to use much more advanced concepts, such as using regular expressions, line marking, buffers, and sorting.

Getting ready

We just need to check whether vi and Vim are installed on our system. The simplest way to do it is to just go brute-force and issue the following command:

sudo apt-get -y install Vim-tiny busybox Vim dictionaries-common wamerican

Ubuntu doesn't have or use the vi editor by default, so we can just install the Vim-tiny package to kind of emulate the same thing. Another way to use the vi editor in Ubuntu would be to use the following command:

busybox vi

Seeing that busybox is a command-line tool that embeds multiple Linux command-line utilities into one, this command is something that we need to be aware of. But also, we need to remember that the intent of busybox is to have a way to embed multiple popular CLI tools into one, which in turn means that none of these tools are completely the same as their standalone versions.

After installation is done (if needed at all), we're going to start using Vim and learn how to use it via examples. Let's issue the following commands as root:

cp /etc/passwd /root
cp /usr/share/dict/words /root

Take note of the fact that between cp, /etc/passwd, and /root (the same thing applies to cp, /usr/share/dict/words, and /root in the second command), we need to hit the spacebar on our keyboard. We're effectively copying the passwd and words files to the /root directory to have some source files to play with.

When we have successfully finished copying these files, we'll start the Vim editor and start editing. First, we're going to use the passwd file. Type in the following:

Vim /root/passwd

Let's start learning!

How to do it…

Now that we have the /root/passwd file opened in our Vim editor, let's play with it a bit. Moving around in normal mode is straightforward. Let's just start by using the arrow keys on our keyboard to move up and down and left and right. After we're done with that, let's just jump to the top of our file by using the gg sequence (by pressing the g key twice).

First, we're going to delete the first line. Vi(m) starts in something called normal mode, and if we press the d key twice, we're going to delete the first line. Let's check the before state:

Figure 2.1 – The top section of the /root/passwd file

Figure 2.1 – The top section of the /root/passwd file

And now, after we have pressed the d key twice, it should look like this (if we are still positioned at the first line, the root line):

Figure 2.2 – After pressing the d key twice, the first line is gone

Figure 2.2 – After pressing the d key twice, the first line is gone

Let's now expand this use case further by pressing (just as an example) the 5dd key sequence. The result should look something like this:

Figure 2.3 – After the 5dd operation (deleting five lines), we deleted five lines after the cursor

Figure 2.3 – After the 5dd operation (deleting five lines), we deleted five lines after the cursor

As we can see, the first five lines after our cursor (the lines starting with daemon, bin, sys, sync, and games) are gone.

Let's now jump to the last line in our /root/passwd file, and copy and paste it behind the last line. First, we need to go to the end of our file, which can be achieved by using the Shift + g sequence (basically, the capital letter G). After that, if we want to copy the line after the cursor (in effect, complete the last line in the file), we need to first yank it (copy) and then paste it to a correct spot. Yanking can be achieved by using the yy sequence (pressing the y key twice). That puts the line after our cursor in a copy and paste buffer. If we want to paste it after our last line, we need to press the p key. Our copied line will automatically be pasted after the last line. The end result, if we used the same virtual machine as in Chapter 1, Basics of Shell and Text Terminal, should be something like this:

Figure 2.4 – The yank and paste of a single line

Figure 2.4 – The yank and paste of a single line

Now, let's select three lines beginning with sshd (so, the sshd, systemd-coredump, and student lines) and copy and paste them after the line beginning with joe. First, we're going to use cursor keys to position at the beginning of the sshd line. Then, we're going to type the y3y key sequence. This will start yanking (copying) from the cursor, copy the next three lines in the copy and paste buffer, and then end yanking. If we did that successfully, Vim is going to throw us a message at the bottom of the screen, saying 3 lines yanked.

After we have these lines in the copy and paste buffer, we need to paste them. Let's use the cursor keys to move to the line beginning with joe, and then press the p key. The result should look like this:

Figure 2.5 – Yank and paste, and multiple lines of text

Figure 2.5 – Yank and paste, and multiple lines of text

Now that we have played with yank and paste and delete, it's time to add some content to this file. In order to do that, we need to enter insert mode. That can be achieved by typing the i key. So, let's add a bit of text after our cursor – press the i key and start typing. Let's add the following:

something:x:1400:1400::/home/something:/bin/bash

After we're done with inserting, press the Esc key (to go back to normal mode). The end result should look like this:

Figure 2.6 – Inserting additional text with insert mode

Figure 2.6 – Inserting additional text with insert mode

Now that we've done that successfully, the next logical step will be to save the file if we're happy with its contents. Let's say that we are and we're ready to save the file. In order for us to do that, we need to enter ex mode and tell Vim that we want to exit and save. There are several different key sequences that will make this happen for us. The first one is :wq! (write and quit – don't ask us for confirmation), and the second one is :x. There are other ways, such as using the ZZ key sequence, but let's stick to the more commonly used ones (wq and x). We need to make sure that we type these key sequences with a colon sign (:). As we will explain in a bit, using the colon sign means that we want to enter ex mode and do some final operations with our edited file. If we use this key sequence successfully, we should end up in shell, with our original file saved with all the changes that we made to it.

In truth, Vim has a spectacular number of key sequences that can be used for a variety of operations on text files. Feel free to translate this spectacular as either a very good or very bad thing, as it's all subjective – some of us like it a lot, some of us will hate it. Here are some commonly used key sequences:

  • dw – delete a word
  • 2dw – delete two words
  • yw – yank one word
  • u – undo the last change
  • U – undo changes made to the current line
  • a – append text after the cursor
  • A – append text to the end of the current line
  • Ctrl + f – scroll the file forward by one screen
  • n Ctrl + f – scroll the file forward by n screens
  • Shift + m – move the cursor to the middle of the page
  • :50 – move the cursor to line 50 of the current file
  • $ – move the cursor to the end of the line
  • x – delete the character at the cursor
  • X – delete the character before the cursor
  • ^ – go to the first character of the line
  • o – insert a line after the current one
  • Ctrl + g – print the file info

There are literally hundreds of other commands, and we deliberately selected only some of them that we feel are useful and commonly used. Let's now do some more complex things by using a built-in Vim teaching tool called Vimtutor. In the command line, start Vimtutor by typing the following:

Vimtutor

After that, Vimtutor is going to ask us about the intended output file for practice, and we can just press the Enter key here. We should have the following content on our screen:

Figure 2.7 – The Vimtutor start page

Figure 2.7 – The Vimtutor start page

Let's now use this file to practice a bit. The first thing that we're going to do is copy the first paragraph (starting with Vim and ending with editor.) before the paragraph starting with The approximate time.

Let's position our cursor at the beginning of the Vim line by using the arrow keys. After we have done that, we need to use the y} key sequence to instruct Vim to yank the paragraph starting at the cursor. Then, we need to move to the empty line between the first and second paragraphs by using the cursor keys and pressing the p key to paste the copied paragraph after the cursor. The result should look like this:

Figure 2.8 – Yanking and pasting a text paragraph

Figure 2.8 – Yanking and pasting a text paragraph

Let's say that we want to convert the complete file to lowercase characters. Of course, this operation involves several other operations:

  • We need to move to the beginning of our file (gg).
  • We need to turn on visual mode (more about this a bit later), achieved by pressing the Shift + v key sequence (uppercase V).
  • We need to mark the text all the way to the end of our file, achieved by pressing the Shift + g key sequence (uppercase G).
  • We need to make the text lowercase, achieved by pressing the u key.

So, the key sequence we're looking for is ggVGu. The result of our operation should look like this:

Figure 2.9 – Our Vimtutor file, with all lowercase characters

Figure 2.9 – Our Vimtutor file, with all lowercase characters

If we wanted to do the opposite (uppercase all the characters), we'd use the ggVGU key sequence (U is for uppercase and u is for lowercase characters).

We're going to take a short break from all of these key sequences by explaining how Vim works – specifically, we're going to focus on commonly used modes and briefly mention some of the lesser-used ones. Let's start with normal mode and work our way toward visual and replace modes.

How it works…

The Vim editor has more than 10 different modes, which roughly translates into the different ways in which it works. The most used modes are as follows:

  • Normal mode
  • Insert mode
  • Ex mode
  • Visual mode
  • Replace mode

When we start Vim, we're in normal mode; we can sniff around in it by using the cursor, we can do a bit of yank and paste, and we can delete. So, it's used for general operations such as navigating through an edited file, a bit of rough-cut editing, and that's that.

If we want to add additional content to our text file, we usually switch to insert mode by using the i key. In insert mode, we can easily add a bit of text after our cursor and move around in our edited file. When we're ready to go back to normal mode, we can do that by pressing the Esc key. If, however, we're done with file editing and we just want to save the file and exit, we need to go to normal mode and then to ex mode. This is achieved by pressing the Esc key, followed by the colon (:). That puts us in ex mode, and then we can proceed to do wq!, x, or ZZ.

Visual and replace modes are quite a bit different. Visual mode has sub-modes (character, line, and block), and can be used to select (highlight) parts of the text that we want to work with and manipulate. For example, line and block modes can be useful for modifying YAML files when working with Ansible. Character mode can be used to highlight a part of code. YAML syntax is sensitive to indenting, so by using line mode, we can highlight portions of our playbooks and indent them left or right (by using the > and < keys) so that we don't have to do it manually. Block mode can be used efficiently to check indentation that was created by using line mode. These modes can be entered by using Shift + V (line mode) and Ctrl + v (block mode). Character mode can be entered by using the v key.

Replace mode allows us to type in our content in a text file over existing content. We can use the R key to enter replace mode (from normal mode).

See also

If you need more information about the basics of Vim, we suggest that you check out this content:

Learning the basics of the nano editor

If you feel that the Vim editor is too complicated for you, we can feel your pain. That's why choosing the editor you're going to work with is a subjective choice. We'd like to offer another much simpler editor to the table, called nano.

Getting ready

Keep the CLI1 virtual machine powered on and let's continue editing our files.

How to do it…

We're going to edit the words file that we copied in the previous recipe. Before that, let's just make sure that nano is installed by typing in the following command:

sudo apt-get -y install nano

Let's now open the file called words from the root directory by typing in the following command:

nano /root/words

Our file should be opened in the nano editor, as shown in the following screenshot:

Figure 2.10 – Starting editing with the nano editor

Figure 2.10 – Starting editing with the nano editor

For those of us who are more prone to using text editors such as Notepad or Wordpad, nano should be a bit more familiar territory. It doesn't have the scope of capabilities or advanced functionality that Vim has, but for the most part, that might not be so important, at least not for most text file editing operations. Or is it really that simple? Let's check it out.

Editing in nano works in the same fashion as with other regular editors – we just need to explain the lower part of the screenshot (the part where we can see Help, Exit, and so on). In nano, if we need help, we need to press Ctrl + g. This is the result that we'll get:

Figure 2.11 – nano help

Figure 2.11 – nano help

We can spend our time scrolling through this help window if we want to. But, for starters, let's just say that this ^ character means press the Ctrl key.

So, on our first nano screenshot, ^G means Ctrl + G, ^X means Ctrl + X, and so on. It still isn't as easy as using some text editors that a lot of people use on Microsoft Windows, but it's a bit more user-friendly than Vim. If nothing else, some of the commonly used commands are right at the bottom of our screen so that we don't have to learn all of the key sequences or research them online before we consider using the editor.

If we want to close our help window from the second nano screenshot, we just need to press Ctrl + X. This will get us back to the state shown in the first nano screenshot.

If we want to delete a line, we need to use Ctrl + K. If we need to delete multiple lines, things start to get a bit more complex. We first need to select the content that we want to delete (Ctrl + Shift + 6), use the cursor to move to the place that we want to delete to, and then press Ctrl + K. Let's say that we want to delete five lines. So, selecting content that we want to delete looks like this:

Figure 2.12 – After pressing Ctrl + Shift + 6 and using the cursor keys to 
go down five lines, we're ready for Ctrl + K

Figure 2.12 – After pressing Ctrl + Shift + 6 and using the cursor keys to go down five lines, we're ready for Ctrl + K

After we have selected the correct text, we just need to press Ctrl + K to delete it. The result will look like this:

Figure 2.13 – Five lines successfully deleted – result!

Figure 2.13 – Five lines successfully deleted – result!

The same idea applies to doing a copy and paste operation on a paragraph. We'd use Ctrl + Shift + 6 and the cursor to mark the text, Alt + 6 to put the copied text in the copy and paste buffer, and then use Ctrl + U to paste it wherever it needs to be pasted in nano. Saving the file is equivalent to using Ctrl + X to exit, and then confirming that we want the changes to be saved to a file.

There's more…

If you need to learn more about nano, check out the following links:

Going through the advanced Vi(m) settings

In the first part of this chapter, we learned some basic Vim operations, which were moving around, copying and pasting, saving, and exiting. Let's take care of some more advanced operations, such as working with find and replace, regular expressions, and similar concepts.

Getting ready

We need to leave our CLI virtual machine running. If it's not powered on, we need to power it back on.

How to do it…

Finding content in Vim is a multi-step process, and it depends on a couple of things. First, it depends on the direction that we want to take, forward or backward, as there are different key sequences for these operations. Let's open the /root/words file again to find some text:

Vim /root/words

Let's start by finding the word fast. For that to work, we need to use the / character from normal mode, as it tells Vim that we're about to use the search function. So, /fast will search for the words fast forward from our cursor. This is the expected result:

Figure 2.14 – Finding a word in Vim

Figure 2.14 – Finding a word in Vim

If we now press Enter and then the n key, we will search for the next appearance of the word fast. This is the expected result:

Figure 2.15 – The next appearance of the word fast

Figure 2.15 – The next appearance of the word fast

However, if we want to find the 10th appearance of the word fast, we need to either press the correct key sequence or use a regular expression. Let's start with a key sequence, which is going to be (again from normal mode) 10/fast. This is the expected result:

Figure 2.16 – Finding the n-th appearance of a word

Figure 2.16 – Finding the n-th appearance of a word

If we want to find the previous appearance of our word (basically, search backward), we need to press the N key (capital N). This is the expected result:

Figure 2.17 – Finding a word backward from the previous cursor

Figure 2.17 – Finding a word backward from the previous cursor

Let's now do a bit of search and replace. Let's say that we want to find all appearances of the word airplane and change them to metro, starting from the beginning of our file. The key sequence used for that would be gg (to go back to the file beginning) and then :%s/airplane/metro/g, followed by the Enter key. This is the expected result:

Figure 2.18 – Replacing all appearances of a word with another word

Figure 2.18 – Replacing all appearances of a word with another word

This syntax presumes the automatic replacement of all occurrences of the word airplane with the word metro placed anywhere in the file. If we just wanted to replace the first appearance of a string in any line, we need to first find that word by using the /word key sequence. Then, we need to use the :s/word1/word2/ key sequence to only change the first appearance of word1 with word2. Let's use the word airship for that example and change that word to ship. If we type in /airship, followed by the Enter key, Vim will position us to the first next appearance of the word airship. If we then use the :s/airship/ship/ key sequence followed by the Enter key, we should get this result:

Figure 2.19 – Replacing one appearance of a word in a specific line with another word

Figure 2.19 – Replacing one appearance of a word in a specific line with another word

It's a subtle difference, but an important one.

We could also use many more commands in vi – for example, using a dot sign (.). That can be used to repeat the last change made in normal mode, which you might also find to be very useful.

We're going to stop here, as we will cover more advanced text search patterns by using regular expressions in Chapter 7, Network-Based File Synchronization.

How it works…

String replacement in Vim works by using an external command called sed, a stream editor. This command is regularly used by system engineers all over the world to quickly replace simple or complex text patterns of any given file (or multiple files) to another complex text pattern. It uses regular expressions as a basis (explained in Chapter 7, Network-Based File Synchronization), which means that, by default, doing search and replace in Vim is quite powerful, albeit a bit complex, as we need to learn the ins and outs of sed and the way Vim treats it as a plugin.

That being said, most of us focus on the quite powerful part of the last paragraph, as using a Vim/sed combination to quickly replace complex text patterns yields fast and precise results – as long as we know what we're doing, of course.

There's more…

Using these concepts requires a bit of extra reading. So, we need to make sure that we check the following additional links:

Left arrow icon Right arrow icon

Key benefits

  • 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

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.

Who is this book 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.

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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 24, 2022
Length: 552 pages
Edition : 1st
Language : English
ISBN-13 : 9781800204607

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 24, 2022
Length: 552 pages
Edition : 1st
Language : English
ISBN-13 : 9781800204607

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 153.97
Mastering Ubuntu Server
$54.99
Linux Administration Best Practices
$43.99
Linux Command Line and Shell Scripting Techniques
$54.99
Total $ 153.97 Stars icon
Banner background image

Table of Contents

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

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(5 Ratings)
5 star 60%
4 star 20%
3 star 20%
2 star 0%
1 star 0%
Miguel Perez Colino Jun 19, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A very nice book to get started on shell scripting. Very useful for people that are starting a career in system administration and DevOps. Very good complement to books to start learning how to manage linux systems.The book is well structured and covers the basics throughly, creating a good foundation to feel comfortable with shell scripting and starting on programming for system administration. It extends to several good examples on how to apply knwoledge to common daily tasks.I recommend it.
Amazon Verified review Amazon
Chuck Jun 26, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The book reads easily; the concepts are communicated to you in a clear and casual way as if someone is sitting with you and talking about them. I needed to get a better idea of what was possible and learn how to write decent bash scripts. Excellent book... looking forward to applying what I just learned.
Amazon Verified review Amazon
Dženi Vujković Aug 12, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great written book, easy to read, understand and follow up. Highly recommended to mostly all levels of expertise.
Amazon Verified review Amazon
Bill C Apr 08, 2023
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
The binding of the book is poorly done. Some pages are printed skewed, others are a different size. Returning this one and going to re-order as the actual content seems good so far. This is one of those books I need a hard copy of to help learn/retain otherwise I would go for the electronic version.Update : received a replacement book which is in perfect condition. Updated my rating from 2 to 4 stars. I still need to get much deeper into the content to determine if its 5 star worthy.
Amazon Verified review Amazon
Kindle Customer Sep 17, 2022
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Good book but arrived damaged.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.