How Do I Get Previous Month in Linux?

How Do I Get Previous Month in Linux?
Contents

How do I get previous month Shell?

How to get first date of last month and last date of last month in Linux or Bash – Quora. First day of month is always the first, so it is easy: $ date -d “month ago” “+%Y/%m/01”

How do I get the last date of the month in Unix?

For example:

  1. Start with the current date ( date ) -> 2017-03-06.
  2. Set that date to the 1st day of its month ( -v1d ) -> 2017-03-01.
  3. Subtract one day from that ( -v-1d) -> 2017-02-28.
  4. Format the date ( +%d%b%Y ) -> 28Feb2017.
Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.