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)

Sed – one-liner productivity treasure


If a picture is worth 1000 words, then sed one liners are definitely worth a thousand lines of code! One of the most feared commands in the Linux CLI is, you guessed it, sed! It's been feared by programmers and sysadmins everywhere, because of it's cryptic usage, but it can serve as a very powerful tool for quickly editing large amounts of data.

We have created five files to help demonstrate the power of this awesome tool. The first one is a simple file containing the humble line of text: Orange is the new black. Let's start by creating a simple sed command to replace the word black with white.

The first argument of sed is the replace command. It's divided into 3 parts by 3 /. The first part is s for substitute, the second part is the word to be replaced, black, in our case, and the third part is the replacement word, white.

The second argument is the input, in our case, a file:

sed "s/black/white/" 1.txt

Now, the result will be printed on the screen, and...