krypted.com

Tiny Deathstars of Foulness

When I need to look at what day a date is on, I typically open the Calendar app. But sometimes I’m in the middle of a task in the command line and don’t want to do so. Luckily, there’s a cal binary in OS X. To use cal, simply invoke it and ask for a julian calendar using the -j option: cal -j Which outputs a calendar view: March 2016 Su Mo Tu We Th Fr Sa 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 The days you see above are numbered as the day in order in that year. To see the full year, use -jy: cal -jy To just see one month, use the -m followed by the number of the month. So to see July: cal -j -m 7 To see all of 2018, use the -y and the year: cal -j -y 2018 To see the dy of the month, we’ll use ncal, which also shows which day of the week each day fall on: ncal -J The output would be as follows: March 2016 Mo 1 8 15 22 29 Tu 2 9 16 23 30 We 3 10 17 24 31 Th 4 11 18 25 Fr 5 12 19 26 Sa 6 13 20 27 Su 7 14 21 28 When I’m scripting, especially with outputting to logger, I’ll usually use date. But cal and ncal are nice little doohickeys for quickly finding days and dates and the such. Happy calendaring!

March 15th, 2016

Posted In: Mac OS X

Tags: , ,