Download of the day: Easy date manipulation with yest utility under Linux/UNIX

All these years I was using *all dirty shell script hacks* to create my own date manipulation utilities for backups and other admin task. Thanks to this project no more dirty work.

Recently our site visitor Milton left a comment about this nice utility. This utility is very good if you would like to do lots of date manipulation or to crate report/log file names with date in filename.

From the project home page:
yest is a command line date/time manipulation and formatting program, very useful in scripts. You can easily add or subtract days, hours and/or minutes from a specified date. It supports all date command output formats plus more.

This program is called “yest” because the default is to output yesterday’s date. This utility knows about leap year, aylight savings time, and such variations.

Task: Install yest

Download yest from project home page. Or use wget command as follows:
$ cd /tmp
$ wget http://easynews.dl.sourceforge.net/sourceforge/yest/yest-2.7.0.3.tgz

Untar the source code:
$ tar -zxvf yest-2.7.0.3.tgz

Compile and install binary
$ su -
# gcc -o /usr/bin/yest yest-2.7.0.3.c

Install man page:
# cp yest-2.7.0.3.man1 yest.1
# gzip yest.1
# cp yest.1.gz /usr/share/man/man1/

How do I use yest?

Following command will display yesterdays date (default):
$ date
Thu Oct 12 23:45:24 IST 2006
$ yest
10/11/2006

Display the date ten days ago (-10 or +10 next 10 days)
$ date
Thu Oct 12 23:46:23 IST 2006

$ yest -10
10/02/2006

$ yest +10
10/22/2006

Format date in dd-mm-yyyy:
$ yest -10 "%d-%m-%Y"
02-10-2006

Get more help
$ yest --help
$ man yest

yest in action

So to executing a script/command on the last day of a month, I was using following script:
#! /bin/bash
TOM=$(TZ=MST-24 date +%d)
if [ $TOM -eq 1 ]; then
# commands or script on the last day of a month
/path/to/mytask
fi

But with yest it is just one line shell script 😀
[ $(yest +0 "%d") -eq $(yest "%L") ] && /path/to/mytask || :

=> yest Download is highly recommended tool for all seasoned UNIX admin.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Yogesh Aug 13, 2007 @ 12:46

    gr8 …. its rocks on tru64
    i hav used following command to compile

    cc -o yest yest-2.7.0.3.c
    now i can do all date manuculation as i used to do it with GNU date

    Thanks

  • Robert Jun 13, 2007 @ 17:43

    What about when timezone identifiers change?
    Like MST to MDT?

  • 🐧 nixCraft Mar 22, 2007 @ 10:00

    May be you need headers files…

  • Don Eytel Mar 21, 2007 @ 20:33

    Problem compiling an idea.

    gcc -o /home/deytel/bin/yest /home/deytel/yest-2.7.0.4.c
    /home/deytel/yest-2.7.0.4.c: In function `main’:
    /home/deytel/yest-2.7.0.4.c:1470: structure has no member named `tm_zone’

  • bleh Oct 14, 2006 @ 12:24

    ehm… you have never tried

    date -d “yesterday” or date -d “+10 days” have you?

    date already does all this…

  • 🐧 nixCraft Oct 14, 2006 @ 10:57

    Tiger

    Sometime you have 29, 28 (leap year), 30, 31 as month-end day. Sometime day pattern get repeated as 31, 31 (july, aug).

    I don’t just wanna keep changing at command according to month. I manage 100 of boxes I don’t have time to keep writing at command for each box. So this tool makes for sense to me.

  • tiger Oct 13, 2006 @ 19:41

    what about using AT or CRON?

    > at 00:00 Aug 31
    script goes here
    ctrl+D

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.