LinuxQuestions.org
Review your favorite Linux distribution.
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-11-2018, 07:35 PM   #1
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Rep: Reputation: Disabled
Question Specific date in "English" format?


I have a Bash script that returns a file's modified date as year-month-day hour:minutes:seconds by way of a cut command applied to the return of an ls -alh command.

What i would like to do is get a return more on the order of "Wed Nov 26 2015 12:18:56." I've seen solutions which apply this formatting to what's returned by the date command, but as I'm not concerned with the current system date, I'm at a loss as to how to do this.

It occurs to me that this is a nearly polar opposite of a thread I started more than a year ago about generating random dates to use with the touch -t command. I suspect the "way to do this" will be equally unfamiliar and complex.

Carver

Last edited by L_Carver; 11-11-2018 at 07:36 PM. Reason: Added a few words.
 
Old 11-11-2018, 07:41 PM   #2
lougavulin
Member
 
Registered: Jul 2018
Distribution: Slackware,x86_64,current
Posts: 279

Rep: Reputation: 100Reputation: 100
Something like :
Code:
date +"%c" -d 2018-10-12
Use your date and modify output format (%c) if it is not exactly what you need.
 
Old 11-11-2018, 07:53 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,692

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
One quick solution would be to use the stat command to output modified time in seconds since epoch, then use the date command to put that in whatever format desired. Easier then parsing the ls command.

Last edited by michaelk; 11-11-2018 at 07:55 PM.
 
Old 11-12-2018, 03:34 AM   #4
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 900

Rep: Reputation: 290Reputation: 290Reputation: 290
Why not resolve the issue from the very beginning directly in the ls command, like the following?
Code:
ls -alh --time-style='+%a %b %d %Y %H:%M:%S'
 
3 members found this post helpful.
Old 11-12-2018, 04:24 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,125

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120

That's gotta be worth a rep or two ...
 
Old 11-12-2018, 06:08 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,692

Rep: Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894Reputation: 5894
If the OP just wants the modification date.

Code:
date -d "@$(stat -c %Y file.name)" "+%a %d %b %Y %H:%M:%S"
 
1 members found this post helpful.
Old 11-12-2018, 11:26 AM   #7
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by syg00 View Post

That's gotta be worth a rep or two ...
...or a dozen. Added one!
 
1 members found this post helpful.
Old 11-13-2018, 08:24 AM   #8
L_Carver
Member
 
Registered: Sep 2016
Location: Webster MA USA
Posts: 243

Original Poster
Rep: Reputation: Disabled
Wink

Quote:
Originally Posted by michaelk View Post
If the OP just wants the modification date.

Code:
date -d "@$(stat -c %Y file.name)" "+%a %d %b %Y %H:%M:%S"
Yes, that's all I wanted, as that is only what the original script returns.
+1 michaelk. -1 l0f4r0
Thanks to you both.

Carver
 
Old 11-13-2018, 04:19 PM   #9
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by L_Carver View Post
Yes, that's all I wanted, as that is only what the original script returns.
+1 michaelk. -1 l0f4r0
Thanks to you both.

Carver
If you would like to mark this thread as "Solved", please see "Thread Tools" at the top of the thread.
 
1 members found this post helpful.
  


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
[SOLVED] Older than $(date +"%m%d%Y" --date="14 days ago") script help Habitual Programming 10 04-06-2013 04:41 PM
insmod hello.ko: -1 Invalid module format ("vermagic" and "uname -r" are the same!) courteous Linux - Kernel 8 02-16-2011 11:09 PM
2 specific Sendmail questions about "delay_checks" and "Connect:" in access.db fast-reflexes Linux - Server 0 08-05-2010 09:33 AM
What date format DOES work with "touch -d"? SilversleevesX Programming 2 08-03-2010 04:08 AM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM

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

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