How to Find Yesterday's Date in Unix
Modern Unix and Linux machines come with graphical user interfaces (GUI), but they were designed, first and foremost, to be used from the command line. As a consequence, some of the most powerful Unix tools are found from the shell. One such powerful tool for manipulating dates is the "date" command.
Instructions
-
-
1
Open the shell. The procedure for this will vary depending upon the version of Unix you have installed, but for most, there will be a shortcut directly on the desktop or the menu bar that opens the shell.
-
2
Type in "date" (without the quotation marks).
This will give you today's date, most likely in the following format:
Fri Mar 11 10:21:54 EST 2011
-
-
3
Type the above command again, but this time with the command "-v -1d" added. The "-v" tells "date" that you want to adjust the date, while the "-1d" tells "date" by how much. You will receive a new date:
Thu Mar 10 10:22:54 EST 2011
-
1
Tips & Warnings
You can adjust dates using the letters (s)econd, (m)inute, (h)our, (d)ay, (w)eek, (m)onth, and (y)ear.
You can read the entire manual for the date command by typing: "man date" into your terminal. The manual provides a list of all the commands to the "date" program and instructions on how to format the output to include only the desired information.
These instructions are for the "BSD" version of the date command. For the GNU version of the date command, you would type:
date --d="-1 day"
You can discover your current version of the date command by typing "man date."