Getting the current Date in Your Scripts



I LIKE stamping things with the date, whether it’s a status report email or filename. (Like say I’ve downloaded todays news in Spanish, it really seems to make sense to tag it as spanish_news_12_8_08.mp3 instead of just spanish_news.mp3 doesn’t it?)

Okay, so this is something I do in a lot of my shell scripts. Here’s some code to play with.

Thankfully, linux has a great (and flexible) date command…

In the top part of your script just assign the variable date as such:

date=`date +%b%d%Y`

this uses the date command with the following format: Dec082008

Of course, there are other ways to format it – like date +%F which gives you 2008-12-08

As you’re seeing the +and then %letter formats the date. There are MANY different ways to format the date, in fact, if you just want the month, or day of week, that’s possible too. you might want to consult the manual page for date to see all the choices.

So… from the console type man date

now, you can have the date or time stamp you want in any of your shell scripts.

Related Posts

Blog Traffic Exchange Related Posts
  • Good sarc monitoring tip Sarc is still in their month of security tips per day and todays is another good one. Todays tip is about monitoring machines, particularly those that "defend" your network. (Mail antivirus scanners/ proxy fitlers/scanners/etc.) The core of the advice is to not just ping - that only tells you if......
  • Automatically downloading a file mp3 with a bash script Linux systems give you many possibilities and one of them is good scheduling (cron), another is good scripting capabilities. I've done things with linux fairly easily that with Windows would have been next to impossible and required me to download several other things to make it happen. Anyway, I recently......
  • Remote Tech Support with x11vnc and wrapper script So, the idea is that I wanted something "like" the Ultranvnc Single Click download, only for linux. The main idea being is that if someone is looking for a bit of desktop tech support on linux, we don't need to be giving instructions for 5 different package managers, or source......
Blog Traffic Exchange Related Websites
  • How to Change the Date and Time Format for WordPress Blog By default your WordPress blog will display date and time as "September 3, 2010" and "12:59 am". When using the default template you can easily change the format by changing the General Settings from your WordPress Admin page. Go to Settings > General and change the settings using the button......
  • Love Drop #5- The Stalnaker Family Hey guys! The Love Drop team is at it again! Last month they gave over $6,000 worth of cash and goods to their recipient, the Kahlen family, who had been going through a financially hard time due to the economy (and whose daughter is currently battling Tuberous Sclerosis). They......
  • Should You Invest in a Target Retirement Date Fund? Target Date Funds were intended to be a "one-size fits all" retirement investment vehicle. Investors were encouraged to put most if not all of their retirement portfolio into a retirement date fund after selecting a target retirement date. Then, the theory went, they could sit back, relax, and watch as......
en.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site