Chapter 20: Productivity Tools

In this chapter, we’ll explore productivity tools that can make your Linux experience more enjoyable and efficient. From ASCII art generators to time management tools, these utilities add a touch of creativity and help you stay productive. By the end of this chapter, you’ll have a toolkit of fun and useful programs to enhance your command-line workflow.


1. Why Use Productivity Tools?

While Linux is often associated with serious system administration and development tasks, it’s also a platform for creativity and productivity. These tools can 
- Add a touch of humor and personality to your terminal. 
- Help you stay organized and focused. 
- Make repetitive tasks more enjoyable.


figlet: ASCII Art Text

figlet creates large ASCII art text banners.

Installation:$ sudo apt install figlet # Debian/Ubuntu
$ sudo dnf install figlet # Red Hat/Fedora

Custom Fonts: Use the -f option to specify a font. $ figlet -f slant "Linux"


lolcat: Rainbow-Colored Output

lolcat adds rainbow colors to text output.

Installation:$ sudo apt install lolcat # Debian/Ubuntu 
$ sudo dnf install lolcat # Red Hat/Fedora

Basic Usage: Pipe any command’s output to lolcat
$ figlet "Linux" | lolcat


pomodoro-cli: Time Management

pomodoro-cli is a command-line tool for the Pomodoro Technique, a time management method that uses timed work intervals.

Installation:$ sudo apt install pomodoro-cli # Debian/Ubuntu 
$ sudo dnf install pomodoro-cli # Red Hat/Fedora

Basic Usage: Start a 25-minute work session: $ pomodoro start 
Take a 5-minute break:$ pomodoro break


taskwarrior: Task Management

taskwarrior is a command-line task manager that helps you track and prioritize tasks.

Installation:$ sudo apt install taskwarrior # Debian/Ubuntu 
$ dnf install taskwarrior # Red Hat/Fedora

Basic Usage: Add a task:
$ task add "Write Chapter 25" 
List tasks:$ task list 
Mark a task as done:$ task 1 done


cal: Calendar

The cal command displays a simple calendar.

  • Basic Usage: Display the current month: $ al
    Display a specific month and year:
    $ cal 10 2025

 Combining Fun and Productivity

You can combine these tools to make your workflow more enjoyable. For example: - Add a motivational message to your daily task list:
$ cowsay "Stay focused!" | lolcat task list 
- Create a colorful banner for your project:
$ figlet "Project X" | lolcat


Working with Log Files

Log files are essential for monitoring system and application activity. They help you troubleshoot issues, track performance, and ensure everything is running smoothly.

Key Tools

  • /var/log/: The directory where most system logs are stored.
  • journalctl: A tool for querying and displaying logs from systemd.
  • tail -f: Monitors log files in real-time.

Examples

  • View the Last 10 Lines of a Log File
    $ tail -n 10 /var/log/syslog
  • Monitor a Log File in Real-Time
    $ tail -f /var/log/syslog
  • Search for Errors in the System Log
    $ journalctl -p err

Some Useful Tools
fortune

  • Purpose: Displays random quotes or fortunes.
  • Installation $ sudo apt install fortune # Debian/Ubuntu 
    $ sudo dnf install fortune # Red Hat/Fedora
  • Example: $ fortune

last

  • Purpose: Displays login history. Example: $ last

uptime

  • Purpose: Shows system uptime and load averages. Example: $ uptime

who

  • Purpose: Displays currently logged-in users.Example: $ who

neofetch

  • Purpose: Displays system information in a visually appealing way.
  • Installation
    $ sudo apt install neofetch # Debian/Ubuntu 
    $ sudo dnf install neofetch # Red Hat/Fedora
  • Example:  $ neofetch

 


Practice Time!

Let’s put your new skills to the test: 
1. Install cowsayand create a custom message with a dragon. 
2. Use figlet and lolcat to create a colorful banner for your project. 
3. Set up a Pomodoro session using pomodoro-cli
4. Add a task to taskwarrior and mark it as done.
5. Automate a Task: Schedule a cron job to run a script every hour.
6. Monitor Logs: Use tail -f to monitor a log file in real-time.
7. Display System Information: Run neofetch to display your system’s details.
8. Check Login History: Use last to view recent logins.


Automating Tasks with cron

cron is a time-based job scheduler in Linux that allows you to automate repetitive tasks. Whether you need to run a script daily, back up files weekly, or send notifications hourly, cron is the tool for the job. In this section, we’ll explore how to use cron to schedule tasks, edit crontab files, and troubleshoot common issues.


Introduction to Cron

cron is a daemon (background process) that runs scheduled tasks at specified intervals. These tasks are defined in a crontab (cron table) file, which contains a list of commands and their schedules.


1. Understanding crontab Syntax

Each line in a crontab file represents a job and follows this syntax:

* * * * * command-to-execute

The five fields represent: 1. Minute (0–59): The minute when the command will run. 2. Hour (0–23): The hour when the command will run. 3. Day of the Month (1–31): The day of the month when the command will run. 4. Month (1–12): The month when the command will run. 5. Day of the Week (0–7): The day of the week when the command will run (0 and 7 both represent Sunday).

Special Characters

  • *: Matches all values (e.g., * * * * * runs the command every minute).
  • ,: Specifies multiple values (e.g., 1,15 * * * *runs the command at the 1st and 15th minute of every hour).
  • -: Specifies a range (e.g., 1-5 * * * * runs the command every minute from 1 to 5).
  • /: Specifies intervals (e.g., */5 * * * * runs the command every 5 minutes).

2. Editing the crontab File

To create or edit your crontab file, use the following command:

$ crontab -e

This opens the crontab file in your default text editor. Each user has their own crontab file, so changes you make will only affect your scheduled tasks.


3. Common cron Job Examples

Run a Script Every Day at Midnight

0 0 * * * /path/to/script.sh

Run a Command Every Hour

0 * * * * /path/to/command

Run a Command Every 5 Minutes

*/5 * * * * /path/to/command

Run a Command Every Monday at 8:00 AM

0 8 * * 1 /path/to/command

Run a Command on the 1st of Every Month at 6:30 AM

30 6 1 * * /path/to/command

4. Managing cron Jobs

List Your cron Jobs

To view your current cron jobs, use:

$ crontab -l

Remove All cron Jobs

To delete all your cron jobs, use:

$ crontab -r

Edit Another User’s crontab (Requires Root Privileges)

To edit another user’s crontab, use:

$ sudo crontab -u username -e

5. Troubleshooting cron Jobs

Check cron Logs

cron logs can help you debug issues with your jobs. On most systems, logs are stored in /var/log/syslog or /var/log/cron. Use grep to filter cron-related logs:

$ grep CRON /var/log/syslog

Redirect Output to a Log File

By default, cron sends job output to the user’s email. To save output to a log file, redirect it:

* * * * * /path/to/command >> /path/to/logfile.log 2>&1
  • >> /path/to/logfile.log: Appends standard output to a log file.
  • 2>&1: Redirects error output to the same log file.

Use Full Paths

cron jobs run with a limited environment, so always use full paths for commands and files:

* * * * * /usr/bin/python3 /home/user/script.py

6. Advanced cron Features

Environment Variables

You can set environment variables at the top of your crontab file:

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

0 * * * * /path/to/command

Special Strings

cron supports special strings for common schedules: - @reboot: Run once at startup. - @daily or @midnight: Run once a day at midnight. - @hourly: Run once an hour. - @weekly: Run once a week. - @monthly: Run once a month. - @yearly or @annually: Run once a year.

Example:

@daily /path/to/backup.sh

7. Summary

cron is a powerful tool for automating tasks on Linux. By mastering crontab syntax and understanding how to manage and troubleshoot cron jobs, you can save time and ensure that important tasks run on schedule.


'at' command

The at command in Linux is used to schedule commands or scripts to run once at a specified time in the future. Unlike cron, which is used for recurring tasks, at is for one-time execution. The at command is a useful tool for scheduling one-time tasks, such as backups, updates, or running scripts at off-peak hours.

Here’s a breakdown of how it works:

Basic Syntax:

$ at [options] [time]

After entering this command, you’ll be prompted to enter the command(s) you want to execute. Press Ctrl+D to signify the end of your input.

Specifying Time:

You can specify the time in various formats:

  • Absolute Time: HH:MM (for today), YYYY-MM-DD HH:MM (for a specific date and time)
  • Relative Time: now + 5 minutes, midnight, noon, teatime (4pm)
  • Day-Based: tomorrow, next week, next month

Example:

To run my_script.sh five minutes from now:

$ at now + 5 minutes
warning: commands will be executed using /bin/sh
$ at> my_script.sh
$ at> <Ctrl+D>

You’ll get a job number in response, which you can use to manage the scheduled task.

Options:

  • -l or -list: List pending at jobs.
  • -d or -delete: Delete a specific job (using its job number).
  • -m: Send an email notification after the job completes (even if there’s no output).
  • -f <file>: Read commands from a file instead of standard input.

Important Notes:

  • at daemon: The at command relies on the atd daemon to function. Make sure this daemon is running on your system.
  • Security: Access to at is often restricted by /etc/at.allow and /etc/at.deny. If at.allowexists, only users listed in it can use at. If at.allow doesn’t exist and at.deny exists, all users except those listed in at.deny can use at. If neither file exists, typically only root can use at.
  • Shell: Commands are usually executed using /bin/sh, even if your default shell is something else. Keep this in mind when writing scripts for at.
  • Environment: The environment variables at the time of scheduling are used when the command runs.

 


8. Practice Time!

Let’s put your new skills to the test: 
1. Schedule a Daily Backup: - Create a cron job to run a backup script every day at 2:00 AM.
2. Monitor Logs: - Schedule a job to check system logs every 10 minutes and save the output to a file.
3. Use a Special String: - Use @rebootto run a script every time your system starts up. 
4. Troubleshoot a Job: - Create a cron job that fails intentionally, then use logs to debug the issue.


That’s it for Chapter 20! You’ve now learned how to use fun and productivity tools to make your Linux experience more enjoyable and efficient. In the next chapter, we’ll dive into file transfer tools—how to move files between systems using scp, rsync, and more. Until then, have fun experimenting with these tools!


Prev: Chapter 19 | Next: Chapter 21