有用的Linux date設定方式
http://www.simplehelp.net/2008/12/18/the-linux-date-command/
# date +”%d/%m/%Y”
14/12/2008
You can also use spaces and commas. Here’s a pretty fancy example:
# date +”%A,%B %d %Y”
Sunday,December 14 2008
Say you’re writing a shell script to back up the logs form you server. You want the backup script to get the logs for the day before and back them up. Here’s how you can get the previous day’s date:
# date –date=”yesterday”
Sat Dec 13 12:04:03 IST 2008
Similarly, you can also get tomorrow’s date:
# date –date=”tomorrow”
Mon Dec 15 12:04:39 IST 2008
You can get last or next month’s date:
# date –date=”last month”
Fri Nov 14 12:06:23 IST 2008
# date –date=”next month”
Wed Jan 14 12:06:25 IST 2009
Pretty cool stuff, eh! You’re just getting started. You can customize the date you want more precisely than by day and week, and get the date five days ago or seven days from now:
# date –date=”5 days ago”
Tue Dec 9 12:08:26 IST 2008
# date –date=”7 days”
Fri Dec 21 12:09:23 IST 2008
You can even ask it more difficult questions such as:
# date –date=’next Saturday’
Sat Dec 20 00:00:00 IST 2008
Or something totally in the future:
# date –date=’2 years 3 months 4 day’
Fri Mar 18 12:12:16 IST 2011
沒有留言:
張貼留言