Book Image

Bash Cookbook

By : Ron Brash, Ganesh Sanjiv Naik
Book Image

Bash Cookbook

By: Ron Brash, Ganesh Sanjiv Naik

Overview of this book

In Linux, one of the most commonly used and most powerful tools is the Bash shell. With its collection of engaging recipes, Bash Cookbook takes you through a series of exercises designed to teach you how to effectively use the Bash shell in order to create and execute your own scripts. The book starts by introducing you to the basics of using the Bash shell, also teaching you the fundamentals of generating any input from a command. With the help of a number of exercises, you will get to grips with the automation of daily tasks for sysadmins and power users. Once you have a hands-on understanding of the subject, you will move on to exploring more advanced projects that can solve real-world problems comprehensively on a Linux system. In addition to this, you will discover projects such as creating an application with a menu, beginning scripts on startup, parsing and displaying human-readable information, and executing remote commands with authentication using self-generated Secure Shell (SSH) keys. By the end of this book, you will have gained significant experience of solving real-world problems, from automating routine tasks to managing your systems and creating your own scripts.
Table of Contents (15 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Viewing files from various angles – head, tail, less, and more


As of this very moment, your system likely has many text files of various sizes including a never ending log file being written too. You might even have several large files containing copious amounts of code (such as the Linux kernel or a software project) and would like to quickly view them from the console without slowing your system down to a halt.

To do this, there are four essential commands that should be able to provide you more than enough functionality for their purposes:

  • Head: Can be used to output the beginning lines of a file
  • Tail: Can be used to output the end or tail of a file (continuously as well)
  • More: A tool used as a pager to view large files page by page/line by line
  • Less: Is the same as more, but it has more features, including backwards scrolling

Note

Sometimes, you may see the command more on embedded systems and not the less command. This is because the less command is larger than more. Does your head hurt yet...