Back to commands

Linux Survival Basics

Read-only

Turn Cron Into a Readable Table

Raw crontab lines are hard to scan during an incident, especially with long commands.

Command

crontab -l | awk 'NF && $1 !~ /^#/ {printf "%-16s %s\n", $1" "$2" "$3" "$4" "$5, substr($0,index($0,$6))}'

Before you run this

System impact: Read-only. Low when scoped to the shown target.

When not to use it: Do not use it for /etc/cron.d files without adapting for the user field after the schedule.

Expected output

Aligned schedule expressions next to their command strings.

System impact

Read-only. Nothing changes. awk formats the five schedule fields separately from the command.

Recovery / rollback: no state is changed.

When to use it

Use when reviewing several cron jobs and you need a quick schedule-to-command map.

When not to use it

Do not use it for /etc/cron.d files without adapting for the user field after the schedule.

Explanation-only example

Illustrated output, not a live lab run

This example is intentionally illustrative. It shows the command shape without killing real processes or changing your machine.

demo@lab:~$

$ crontab -l

# user crontab for demo
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
5 * * * * /usr/local/bin/check-disk >> /var/log/cron-disk.log 2>&1
17 2 * * * /usr/local/bin/backup-db
0 4 * * 0 /usr/local/bin/report-weekly | /usr/bin/mail -s report ops@example.com

$ crontab -l | awk 'NF && $1 !~ /^#/ {printf "%-16s %s\n", $1" "$2" "$3" "$4" "$5, substr($0,index($0,$6))}'

SHELL=/bin/bash     SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin     PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
5 * * * *        /usr/local/bin/check-disk >> /var/log/cron-disk.log 2>&1
17 2 * * *       /usr/local/bin/backup-db
0 4 * * 0        /usr/local/bin/report-weekly | /usr/bin/mail -s report ops@example.com
View commands shown

These are the commands shown in the sanitized transcript.

Commands shown

  1. crontab -l
  2. crontab -l | awk 'NF && $1 !~ /^#/ {printf "%-16s %s\n", $1" "$2" "$3" "$4" "$5, substr($0,index($0,$6))}'

next steps

Related commands

Linux Survival Basics Can be slow

Show Big Files in Human Units

Byte counts are precise. Human units are faster under pressure.

find /var -type f -printf '%s %p\n' | sort -nr | head -10 | awk '{printf "%.1f MB %s\n", $1/1024/1024, $2}'
Linux Survival Basics Read-only

Show the Real User Cron Jobs

Cron problems often hide behind comments, blank lines, and copied folklore.

crontab -l | sed -n '/^[[:space:]]*#/d;/^[[:space:]]*$/d;p'
Linux Survival Basics Read-only

Map systemd Timers to Services

A timer is only half the scheduled job. The service is the payload.

systemctl list-timers --all --no-pager --plain | awk 'NR==1 || /\.timer/ {print $(NF-1), "->", $NF}'
Linux Survival Basics Can be slow

Find the Largest CI Logs

Huge logs often point to loops, noisy tests, or runaway debug output.

find logs/ -type f -printf '%s %p\n' | sort -nr | head -10
Linux Survival Basics Read-only

Show Context Around the First App Error

The first error often explains more than the last one.

awk '{buf[NR%5]=$0} tolower($0) ~ /(error|exception|fatal)/ {for (i=NR-4;i<=NR;i++) if (i>0) print buf[i%5]; exit}' fixtures/incidents/app.log
Study mapping

Use this as independent command practice: read the notes, predict the output, then compare it with the example before using a real shell.

  • lpic1:103-gnu-unix-commands
  • lpic1:107-admin-tasks
  • lpic1:108-essential-services
  • lfcs:essential-commands
  • lfcs:operations-deployment
  • linuxplus:automation-scripting
  • linuxplus:provisional
  • risk:read-only

Useful for

  • LPIC-1 style command-line practice
  • LFCS style performance tasks
  • Linux+ style troubleshooting review

Independent study support only. No affiliation, endorsement, exam dumps, or real exam questions.