LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy
User Name
Password
Puppy This forum is for the discussion of Puppy Linux.

Notices


Reply
  Search this Thread
Old 06-03-2015, 06:20 PM   #1
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Rep: Reputation: 169Reputation: 169
Generate file name with current date


Is there a way get this to generate a file with the current date as the filename itself ?

Code:
date "+DATE: %m/%d/%y%nTIME: %r"
 
Old 06-03-2015, 06:57 PM   #2
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I have this. I just need it in month/day/year format.

Code:
touch `date +%F_%T`.txt
 
Old 06-03-2015, 07:33 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
I've always preferred file names that use the full date output i.e year month date because a directory listing is always in chronological order. Just swap what you have for the date in your OP with %F.

Last edited by michaelk; 06-03-2015 at 07:35 PM.
 
Old 06-04-2015, 04:02 AM   #4
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Thanks, your change gives me

2015-06-04.txt

As an American, 06-04-2015 is easier for me to read.

Looks like D does not work ?

Last edited by Fixit7; 06-04-2015 at 04:10 AM.
 
Old 06-04-2015, 04:50 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
You get used to it. I would not use "/" in a file name even thought it is a legal character.

date +m-%d-%Y
 
Old 06-04-2015, 10:03 AM   #6
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
It doesn't work.

I am happy with what I have now.

Some things are impossible. :-)
 
Old 06-04-2015, 10:04 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
that is not impossible, just a % was missed

Last edited by pan64; 06-04-2015 at 10:15 AM. Reason: � was lost suddenly
 
Old 06-04-2015, 10:09 AM   #8
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Just a small bug in date.

no big deal.
 
Old 06-04-2015, 10:10 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
What you have is my preferred method and IMHO what you should use but I did miss a % in front of the m.

touch $( date +%m-%d-%Y ).txt
 
Old 06-04-2015, 12:49 PM   #10
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
It did not work either.

Problem solved.
 
Old 06-04-2015, 12:57 PM   #11
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
naming files by year-month-day group-sorts things better.
 
Old 06-04-2015, 01:12 PM   #12
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
I agree. Just trying to show that it is possible and you can create a filename using any of the date formats. Just saying it doesn't work isn't helping.

Last edited by michaelk; 06-04-2015 at 01:27 PM.
 
Old 06-04-2015, 01:21 PM   #13
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
I have used the correct format and it just creates an empty file.

No one here has come up with something that works which is no big deal.

I assume that they have tested "date" on their systems before posting.
Could be wrong though. :-)
 
Old 06-04-2015, 01:27 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
The touch command changes timestamps but if the file does not exist it is created but yes it is empty. So this is normal. What do you want to accomplish?

echo hello > $( date +m-%d-%Y ).txt

Last edited by michaelk; 06-04-2015 at 01:47 PM.
 
Old 06-04-2015, 02:14 PM   #15
Fixit7
Senior Member
 
Registered: Mar 2014
Location: El Lago, Texas
Distribution: Ubuntu_Mate 16.04
Posts: 1,374

Original Poster
Rep: Reputation: 169Reputation: 169
Your script generates

Quote:
m-04-2015.txt

It is very close, but the month is catewonkus.
While this one ->

Quote:
# echo hello > $( date m-d-Y ).txt
date: invalid date m-%d-%Y
#

Last edited by Fixit7; 06-04-2015 at 02:15 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
create file with Julian date and current time --- then subtract 5 minutes mfarch99 Linux - General 10 06-18-2014 08:07 AM
Find big file include current date bsdfan Linux - Server 15 05-19-2014 01:34 AM
using stat to determine last file access and comparing to current date in IF statemnt danpaluska Linux - Newbie 2 02-16-2010 11:52 AM
How to generate a .config file based on the current or initial installtion/kernel khaos83 Linux - General 11 01-22-2008 09:53 AM
Appending current date and time to a file frankietomatoes Linux - General 5 11-18-2002 02:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Puppy

All times are GMT -5. The time now is 05:15 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
Open Source Consulting | Domain Registration