LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 12-24-2007, 12:56 AM   #1
kosys
Member
 
Registered: Dec 2007
Location: Kolkata, WB,India
Posts: 30

Rep: Reputation: 15
File rename


Hi all,

I do have a requirement where I need to rename the file with a name that would include current date.

Say, the file is data.txt Everyday the file will be renamed with the name data<current date>.txt

Can anyone help me out on this matter?

Thanks and Regards,
Kosys
 
Old 12-24-2007, 01:02 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You could write a script to do it and have that script run every day with a cron job.
 
Old 12-24-2007, 01:07 AM   #3
kosys
Member
 
Registered: Dec 2007
Location: Kolkata, WB,India
Posts: 30

Original Poster
Rep: Reputation: 15
Hi,

I know that I've to write a script for that but I want to know the command or its option by which I can do it. Please.......if anybody know......then let me know how to do it.

Regards,
Kosys
 
Old 12-24-2007, 01:15 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You'll want to use mv and date. Read their man pages for info, because it's really quite simple.
 
Old 12-24-2007, 01:24 AM   #5
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
You can use mv like this
mv filename.txt filename$(date --rfc-3339='date').txt
filename.txt will become filename2007-12-24.txt as of today.
 
Old 12-24-2007, 02:09 AM   #6
kosys
Member
 
Registered: Dec 2007
Location: Kolkata, WB,India
Posts: 30

Original Poster
Rep: Reputation: 15
Hi Uncle Theodore,

The cmd you gave is not working.......

# mv test.txt test$(date --rfc-3339='date').txt
date: unrecognized option `--rfc-3339=date'
Try `date --help' for more information.
mv: cannot stat `test.txt': No such file or directory

Please comment............

Thanks,
Kosys
 
Old 12-24-2007, 02:19 AM   #7
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
Hmmm... I copypasted what you wrote from the screen and it worked as expected

Code:
teddy@toshiba64 ~$ touch test.txt
teddy@toshiba64 ~$ mv test.txt test$(date --rfc-3339='date').txt
teddy@toshiba64 ~$ ls test*
test2007-12-24.txt
teddy@toshiba64 ~$
Kinda strange. What if you try it this way?

mv test.txt test$(date +%F).txt
 
Old 12-24-2007, 03:18 AM   #8
kosys
Member
 
Registered: Dec 2007
Location: Kolkata, WB,India
Posts: 30

Original Poster
Rep: Reputation: 15
Hi Uncle Theodore,

Atlast!!!

Thank you........the second command ran successfully........

Thanks once again....

Kosys
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to rename a file and copy a file in a shell zach014 Linux - Newbie 6 11-23-2006 09:23 AM
rename a file anoosh Programming 3 04-12-2006 02:15 PM
How can i Rename file? Khmer Linux - Newbie 4 10-21-2005 08:09 AM
How do I rename a file? Thaidog Linux - Newbie 5 10-10-2003 10:28 PM
How to rename a file? juanb Linux - General 4 03-19-2003 11:20 AM


All times are GMT -5. The time now is 02:26 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration