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

Using temporary files and lock files in your program


Another mechanism or component programs and scripts often use is called a lock file. It's usually temporary (it resides in /tmp) and is sometimes used when multiple entities rely on a single source of data or need to know that other programs exist. Sometimes, it's merely the presence of a file, a particular timestamp on a file, or another simple artifact.

There are several ways to test for the existence of a file, but one important attribute that has not been demonstrated or explored is the concept of a hidden file. A hidden file in Linux is not really hidden (like in Windows), but it is not usually apparently unless a particular flag or command is ran. For example, the ls command does not return hidden files among the results, but the ls command with the -a flag will (-a for all).

Note

Most file explorers have hidden files that aren't visible by default. In Ubuntu, Ctrl + H inside of the file explorer toggles this feature.

To create a hidden...