Linux Command Line and Shell Scripting Techniques
eBook - ePub

Linux Command Line and Shell Scripting Techniques

Vedran Dakic, Jasmin Redzepagic

Share book
  1. 552 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Linux Command Line and Shell Scripting Techniques

Vedran Dakic, Jasmin Redzepagic

Book details
Book preview
Table of contents
Citations

About This Book

Practical and actionable recipes for using shell and command-line scripting on your Linux OS with confidenceKey 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 managementBook DescriptionLinux 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 automationWho this book is forThis 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.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Linux Command Line and Shell Scripting Techniques an online PDF/ePUB?
Yes, you can access Linux Command Line and Shell Scripting Techniques by Vedran Dakic, Jasmin Redzepagic in PDF and/or ePUB format, as well as other popular books in Computer Science & Operating Systems. We have over one million books available in our catalogue for you to explore.

Information

Year
2022
ISBN
9781800204607
Edition
1

Chapter 1: Basics of Shell and Text Terminal

An ancient Chinese proverb states that A journey of a thousand miles begins with a single step. This chapter is going to be that single, first step on our journey to mastering the Linux command-line interface (CLI) and shell scripting. Specifically, we're going to learn how to use Terminal, the shell, some basic commands, and one very handy utility to work on many things at once, called screen.
As you progress further through the book, you'll notice that we will be using these concepts a lot, as they're the basis for what we're going to do in the later chapters. When dealing with systems administration, we can usually do a lot more in some kind of CLI than in any kind of graphical user interface (GUI). This stems from the idea of the programmability of a CLI versus the static nature of most GUIs in IT. Furthermore, a utility such as screen will make our life in the CLI a lot easier, as we're going to be able to deal with multiple virtual screens at the same time, thus enhancing our productivity.
So, in short, we're going to deal with the following recipes:
  • Accessing the shell
  • Setting up the user shell
  • Setting up the Bash shell
  • Using the most common shell commands
  • Using screen

Technical requirements

For these recipes, we're going to use two Linux machines – in our case, it's going to be two VMware virtual machines with Ubuntu (20.04 Focal Fossa). Let's call them cli1 and gui1, and as the book progresses, we're going to add some more, as our topics grow in complexity. So, all in all, we need the following:
  • VMware Player, Workstation, Fusion, or ESXi
  • Ubuntu 20.04 Focal Fossa installation ISO file
  • A bit of time to install these two virtual machines without the GUI (the cli1 machine) and with the GUI (gui1)
After the installation process is finished, we're going to start with shell basics – our very next topic.

Accessing the shell

First, let's briefly discuss various shell access methods. It can be as simple as just installing a virtual machine with Linux that's running text mode only, but it could also be a virtual machine with the GUI. That would require us doing something to have access to text mode; so, let's learn about these different ways of getting access to the shell.
It's also important to understand why accessing the shell is so important. The reasoning behind this is simple, which is that we can do a lot more in the shell than in the GUI. In the second part of this book, we're going to dig deeper into the concept of shell scripting, and then it's going to become obvious how that applies to our statement about being able to do a lot more in the shell.

Getting ready

For starters, we need to deploy our two virtual machines. We can actually install both of these machines as text-mode machines with the OpenSSH server (the installation process asks about OpenSSH at one point). Then, we could add the GUI to the gui1 machine so that we can work with that, too. We do that by typing a couple of commands into the gui1 machine after logging in as student (which is the username we came up with for this example):
sudo apt-get -y install tasksel
tasksel
sudo is going to ask us for the student user password (it can be any user that you created during the installation process; student is just something that we used in our example). When the tasksel TUI interface starts, we will select the Ubuntu desktop package set, as shown in the following screenshot:
Figure 1.1 – Ubuntu desktop package
Figure 1.1 – Ubuntu desktop package
As you can see from Figure 1.1, you need to select Ubuntu desktop by using the arrow keys and spacebar to select from the menu, then use Tab or the arrow keys to select Ok and press Enter.
Let's now discuss how to access the shell.

How to do it…

If we deployed our Ubuntu machine with default options, we're going to be faced with text mode by default. To access the shell and have the capability to do something with our Linux virtual machine, we need to type in our username and password. It needs to be the username or password that we typed in during the installation process. In our virtual machine, the user named student was created, with the preassigned student password. When we successfully log in, we're faced with the regular text mode and associated shell, as in the following screenshot:
Figure 1.2 – Accessing the CLI from text mode after logging in
Figure 1.2 – Ac...

Table of contents