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)

JSON jamming in the new age


Nowadays, JSON is everywhere, in web apis, in configuration files, even in logs. JSON is the default format used to structure data. Because it is used so much, there will be times when we will need to process JSON from the command line. Could you imagine doing this with grep, sed, or other conventional tools? That would be quite a challenge.

Luckily for us, there is a simple Command-line tool called jq that we can use to query JSON files. It comes with its own language syntax, as we will see in just a few minutes.

First let's install jq with the following command:

sudo apt install jq

Now let's use an example file, a dummy access log in JSON format: access.log, which we can also find in the course GitHub repository.

Let's start with some simple queries:

jq . access.log

We will print the JSON objects back to the screen, in a pretty format:

If we want to grab the request method from each request, run the following:

jq '.requestMethod' access.log

This will print the...