LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 11-18-2005, 10:36 AM   #1
yilez
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 127

Rep: Reputation: Disabled
Filenames based on the date


How do I create a filename based on the date?

i.e.

I'd like to run 'date' from the prompt, and create a file based upon that.

for example, create a file with the prefix 'test-' which would create a file with a name like:

test-Fri Nov 18 16:38:50 GMT 2005.txt

Thanks.
 
Old 11-18-2005, 11:22 AM   #2
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 78
Code:
$ touch "test-`date`.txt"
 
Old 11-18-2005, 11:25 AM   #3
yilez
Member
 
Registered: Apr 2004
Distribution: Slackware
Posts: 127

Original Poster
Rep: Reputation: Disabled
Cheers!
 
Old 11-18-2005, 02:37 PM   #4
blindcoder
ROCK Linux
 
Registered: Dec 2003
Location: Berlin, Germany
Distribution: Crystal ROCK
Posts: 108

Rep: Reputation: 15
You might want something like this for easier sorting:
Code:
touch "test-`date +%Y%m%d`"
 
Old 11-19-2005, 04:31 PM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Re: Filenames based on the date

Quote:
Originally posted by yilez
I'd like to run 'date' from the prompt, and create a file based upon that.

for example, create a file with the prefix 'test-' which would create a file with a name like:

test-Fri Nov 18 16:38:50 GMT 2005.txt

Thanks.
You'll live to regret creating filenames with spaces on Linux systems.
 
Old 11-19-2005, 10:11 PM   #6
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
How about:
Code:
touch $( echo "test-$( date )" | sed 's/ //g' )
No more spaces.

Or better still:
Code:
touch $( echo "test-$( date )" | sed -e 's/ //g' -e 's/\://g' )
No more spaces, no more colons.

edit: blindcoder's is good too. Nice and short.

Last edited by anomie; 11-19-2005 at 10:14 PM.
 
  


Reply



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
Script to delete mail based on date gquiring Linux - General 8 05-08-2013 09:24 AM
Delete files based on date stefaandk Linux - General 3 06-17-2005 02:20 AM
need to assign serial based on date clsonnt Programming 5 10-28-2004 04:26 PM
Date-based copy AdmiralThrawn Linux - General 2 02-23-2004 09:03 AM
Listing Files based on date axero Linux - Newbie 2 10-19-2003 04:58 PM

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

All times are GMT -5. The time now is 02:28 AM.

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
Open Source Consulting | Domain Registration