LinuxQuestions.org
Visit Jeremy's Blog.
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 05-11-2008, 03:48 PM   #1
Travatron
LQ Newbie
 
Registered: May 2008
Posts: 2

Rep: Reputation: 0
Renaming a file to include a datestamp


I'm having a problem renaming a file to include a datestamp.

I have a file named test.tst, and want to rename it to something like 2008.05.09.13:30_test.tst

In searching it seems that
$ mv test.tst "'date +%Y.%M.%d.%H:%m'_test.tst"

is the closest I can come. However, that just renames the file to that eact syntax. I'm sure it's because of the quotation marks, but if i try it without them, my terminal prompt just turns to

>

Any help?
Thanks,
Travatron

Last edited by Travatron; 05-11-2008 at 08:42 PM.
 
Old 05-11-2008, 04:37 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
The following should do it:

Code:
$ mv test.tst `date +%Y.%M.%d.%H:%m`_test.tst
Note the use of the backquotes.
 
Old 05-11-2008, 04:57 PM   #3
Travatron
LQ Newbie
 
Registered: May 2008
Posts: 2

Original Poster
Rep: Reputation: 0
That's perfect! Thanks! I didn't even think of using backquotes, thanks for pointing out that subtle (but important!) difference!
 
Old 05-11-2008, 05:02 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
Or with the bash syntax
Code:
mv test.tst $(date +%Y.%m.%d.%H:%M)_test.tst
this is called "command substitution": without this syntax or back ticks, as suggested by harry, the command is interpreted literally as a string. Note also that you erroneously exchanged %m (month) with %M (minutes).
 
  


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
file renaming computer_tom Linux - General 3 02-18-2008 12:27 PM
renaming file to include datestamp - script PirateJack Linux - Newbie 3 03-20-2006 07:30 AM
File renaming amushtaq Linux - Software 2 01-13-2006 05:40 AM
renaming a file?? U-Toast Linux - Newbie 2 08-29-2004 01:07 AM
renaming or converting a text file to a dat file... tangaz Linux - Software 1 10-24-2003 06:57 AM


All times are GMT -5. The time now is 06:32 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