Book Image

Working with Linux ??? Quick Hacks for the Command Line

By : Bogdan Vaida, Petru I»ôfan
Book Image

Working with Linux ??? Quick Hacks for the Command Line

By: Bogdan Vaida, Petru I»ôfan

Overview of this book

Websites, online services, databases, and pretty much every other computer that offers public services runs on Linux. From small servers to clusters, Linux is anywhere and everywhere. With such a broad usage, the demand for Linux specialists is ever growing. For the engineers out there, this means being able to develop, interconnect, and maintain Linux environments. This book will help you increase your terminal productivity by using Terminator, Guake and other tools. It will start by installing Ubuntu and will explore tools and techniques that will help you to achieve more work with less effort. Next, it will then focus on Terminator, the ultimate terminal, and vim, one of the most intelligent console editors. Futhermore, the readers will see how they can increase their command line productivity by using sed, find, tmux, network, autoenv. The readers will also see how they can edit files without leaving the terminal and use the screen space efficiently and copy-paste like a pro. Towards the end, we focus on network settings, Git hacks, and creating portable environments for development and production using Docker. Through this book, you will improve your terminal productivity by seeing how to use different tools.
Table of Contents (13 chapters)

Shell scripting for fun and profit


Pipes and subshells are one way of expanding the capabilities of our shell. The ultimate way is by writing shell scripts. These scenarios must be taken into consideration when dealing with complex tasks that can't be automated with a one-line command.

The good news is that almost all the tasks can be automated with the use of shell scripts. We won't go over an introduction to shell scripts. Instead, we will be looking at some more advanced use cases for writing them.

Let's start our journey into shell scripting! First thing, let's open a file called script.sh and split the screen so that we can test while writing. Every shell should start with #!, followed by the interpreter it uses. This line is called a shebang. We will be using bash as our default interpreter.

It's a good idea to use bash, because it's a common interpreter that comes with most Linux distributions and also OS X:

#!/bin/bash

Let's start with a simple use case: reading the arguments passed...