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......
  • 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......
  • 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 Get Started Collecting Old Money There are many different things that you are likely to enjoy doing in your life. If you enjoy collecting coins and currency, there are many different ways that you will be able to get the kinds of pieces that you can add to your collection. Among the best ways that......
  • 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......
  • Creating a Blog Video Online About two years ago, blogging hit a surge that allowed its way into the mainstream, and now everybody is blogging for a wide variety of different reasons. Blogs resemble web-based public diaries of sorts, where the creator can record their thoughts, their opinions, questions and answers and essentially anything else......
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