The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 08: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 11:23 AM
Date and time log file captoro Shell Programming and Scripting 8 09-03-2007 09:23 PM
file creation date & time alisevA3 UNIX for Dummies Questions & Answers 3 07-08-2005 05:21 AM
File date and time stamp Xenon UNIX for Dummies Questions & Answers 1 10-09-2001 03:58 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-13-2007
jhamm jhamm is offline
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
  #2 (permalink)  
Old 01-13-2007
Krrishv Krrishv is offline
Registered User
  
 

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

crypto $ date
Sat Jan 13 09:36:39 PST 2007
crypto $ date "+%Y%m%d%H%M"
200701130936
  #3 (permalink)  
Old 01-16-2007
jhamm jhamm is offline
Registered User
  
 

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

thanks for the quick response
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0