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
Perl: Extracting date from file name and comparing with current date MKNENI Shell Programming and Scripting 4 03-26-2008 04:01 PM
check the current date file in directory pallvi SUN Solaris 2 01-04-2008 05:57 PM
how to check whether the given file is 5 weeks older than current date risshanth Shell Programming and Scripting 1 10-29-2007 04:53 AM
File date vs Current date trexlim Shell Programming and Scripting 4 05-04-2007 09:35 PM
How to write current Date dynamically in a file Sree_2503 Shell Programming and Scripting 5 10-17-2006 05:19 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 05-10-2005
simurg11 simurg11 is offline
Registered User
  
 

Join Date: May 2005
Posts: 2
how to give current date in file name?

I want to rename a file by giving the actual date as a file name.
Is there a command for this?
For example file is this: a.txt
I want to copy it with a command like this: a20050510.txt
  #2 (permalink)  
Old 05-10-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
If you have an existing file a. then you can rename it as follows.

mv a.txt a$(date +%F).txt

This would give you
a2005-05-10.txt

If you are particularly looking for a20050510.txt, then it would be longer. Say

a$(date +%Y)$(date +%m)$(date +%d).txt

I think there should be an easier way for the format you requested. Someone might come up with that.

Vino
  #3 (permalink)  
Old 05-10-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Got a much better solution for your question

a$(date +%Y)$(date +%m)$(date +%d).txt

This is it.

mv a.txt a.`date '+%Y%m%d'`txt

In `date '+%Y%m%d'`,

` is the symbol which appears below ~.

Vino
  #4 (permalink)  
Old 05-10-2005
simurg11 simurg11 is offline
Registered User
  
 

Join Date: May 2005
Posts: 2
thanks a lot

Thank you very much Vino,
This helped a lot
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 01:41 AM.


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