The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to extract date with time from file prash_b Shell Programming and Scripting 5 06-18-2008 05:30 AM
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 08:23 AM
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 06:23 PM
file creation date & time alisevA3 UNIX for Dummies Questions & Answers 3 07-08-2005 02:21 AM
File date and time stamp Xenon UNIX for Dummies Questions & Answers 1 10-09-2001 12:58 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-13-2007
Registered User
 

Join Date: Jan 2007
Posts: 5
how do I put a date and time in a file name

I want to copy a file to another file so that the current time and date are in the file name. For example I want to copy file profit.txt to a file name in the format
of profit_YYYYMMDDHHmm.txt where YYYY is year, MM is number of the month DD is the number of day of the month, HH is the hour of the day, and mm is the minute in the hour.

for example, profit_200701130830.txt would mean the file was created on
Jan 13, 2007 at 8:30am.

i know how to copy to a file name in format of YYYYMMDD, but i also need the time. see below
#!/usr/bin/ksh

DTSTAMP=$(date "+%Y%m%d")
cp /fdb/prod/fdbadm/data/profit.txt /fdb/prod/fdbadm/data/profit_$DTSTAMP.txt
Reply With Quote
Forum Sponsor
  #2  
Old 01-13-2007
Registered User
 

Join Date: Dec 2006
Location: CA,United States
Posts: 174
Add %H & %M

crypto $ date
Sat Jan 13 09:36:39 PST 2007
crypto $ date "+%Y%m%d%H%M"
200701130936
Reply With Quote
  #3  
Old 01-16-2007
Registered User
 

Join Date: Jan 2007
Posts: 5
Smile your solution was just what i needed, Thanks !!

thanks for the quick response
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 04:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0