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
  • Scheduling tasks in linux cron Windows has scheduled tasks which most people are only halfway aware of. Linux has very powerful scheduling capabilities coming from it's unix heritage. cron is the daemon that deals with scheduled tasks under most linux distributions. There are a couple ways that you can schedule cron tasks. The first is......
  • Quickbooks "An error has occurred in the script on this page" I ran into an install of Quickboos Pro 2005 that was having a peculiar problem. When any company file was opened I was seeing an Internet Explorer Script Error message (quickbooks uses Internet Explorer to parse the company page ( Usually C:\Program Files\Intuit\Quickbooks\Components\Pages\Comppage.qpg ) The error basically said "An error......
  • Cutting Short, splitting or truncating mp3 files... from the command line in linux... or generating them from Wavs.... So, I've got this CD that I've made and is up for sale at lulu.com traditional hymns done as "chimes". I've spent quite a bit of time recording to hard drive, editing and getting the wav files as good......
Blog Traffic Exchange Related Websites
  • Buy Twitter Accounts: Help & Tactics Currently, there's a new and progressive marketing scheme that directs marketers to a brand new amount of interaction throughout the hustle and bustle globe of on the web marketing. The new alternative to buy twitter accounts that has now set a brand new pattern for conducting useful online marketing tactics.......
  • Ten Steps To Become a Linux/Unix Geek Until recently, Linux/Unix was considered OS of the geeks. However, with GUI and more desktop Linux distributions, things have simplified on both Linux and Unix. Still you can geek out with Unix/Linux using its terminal. Just follow the steps below to master the terminal. 1. Never used Linux! Get Ubuntu......
  • 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......
www.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