LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-20-2006, 07:03 AM   #1
PirateJack
LQ Newbie
 
Registered: Aug 2005
Location: London, England
Distribution: RHEL3
Posts: 20

Rep: Reputation: 0
renaming file to include datestamp - script


I don't understand why this script won't work.. running on RH 9:

--------------------------------------
#!/bin/sh

dt='date +%d%m%y'

mv deleteme deleteme.$dt
--------------------------------------

I want the deleteme file to be renamed deleteme.<date>

When running the script this happens:

#./test
mv: when moving multiple files, last argument must be a directory
Try `mv --help' for more information.
#

I've tried putting it in quotation marks so:
--------------------------------------
#!/bin/sh

dt='date +%d%m%y'

mv deleteme "deleteme.$dt"
--------------------------------------

And then the outcome is:

deleteme.date +%d%m%y

Not the desired effect!
Any ideas? From my understanding it should work but doesn't :-(
 
Old 03-20-2006, 07:24 AM   #2
Agrouf
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: LFS
Posts: 1,591

Rep: Reputation: 79
try ` instead of '

dt=`date +%d%m%y`

mv deleteme deleteme.$dt

or dt=$(date +%d%m%y)
or directly mv deleteme deleteme.$(date +%d%m%y)

regards,
Agrouf

Last edited by Agrouf; 03-20-2006 at 07:28 AM.
 
Old 03-20-2006, 07:27 AM   #3
PirateJack
LQ Newbie
 
Registered: Aug 2005
Location: London, England
Distribution: RHEL3
Posts: 20

Original Poster
Rep: Reputation: 0
Hi Agrouf,

The output if I do that is :

mv: when moving multiple files, last argument must be a directory
 
Old 03-20-2006, 07:30 AM   #4
PirateJack
LQ Newbie
 
Registered: Aug 2005
Location: London, England
Distribution: RHEL3
Posts: 20

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Agrouf
try ` instead of '

dt=`date +%d%m%y`

mv deleteme deleteme.$dt

or dt=$(date +%d%m%y)
or directly mv deleteme deleteme.$(date +%d%m%y)

regards,
Agrouf
Ahaa
That is the answer, thanks :-)
 
  


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
shell renaming script paskari Programming 3 09-24-2005 02:15 PM
Simple Renaming Script Boffy Programming 5 08-12-2005 09:07 AM
file renaming with shell script or ? XJNick Linux - General 5 07-29-2005 02:43 PM
include a file in perl script Ateo Programming 1 04-22-2005 09:53 PM
renaming files script. xushi Programming 4 10-10-2004 08:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration