Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

List file modification date with Year

Posted on 2008-10-22
12
Medium Priority
?
347 Views
Last Modified: 2013-12-26
I am doing ls -lt and this command sometime lists the year of modification but sometime just lists, Month, Day and the time. I need the Month, Day and the Year of the last modification.

ls -lt file.txt | nawk '{print $6-$7-$8}'

Would like the result to be: Oct-22-2008

Thanks for your help.
0
Comment
Question by:infa007
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22777756

You don't see the year when less than 6 months (ca.) passed.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22777798
Hi again,I just saw that gnu ls behaves differently. Try it!
It's in GNU coreutils>
http://ftp.gnu.org/gnu/coreutils/
Norbert
 
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 22777869
GNU docs concerning ls timestamps>

The following option changes how file timestamps are printed. --time-style=style List timestamps in style style. The style should be one of the following: +format List timestamps using format, where format is interpreted like the format argument of date (see date invocation). For example, --time-style="+%Y-%m-%d %H:%M:%S" causes ls to list timestamps like 2002-03-30 23:45:56. As with date, format's interpretation is affected by the LC_TIME locale category.
If format contains two format strings separated by a newline, the former is used for non-recent files and the latter for recent files; if you want output columns to line up, you may need to insert spaces in one of the two formats.
full-iso List timestamps in full using ISO 8601 date, time, and time zone format with nanosecond precision, e.g., 2002-03-30 23:45:56.477817180 -0700. This style is equivalent to +%Y-%m-%d %H:%M:%S.%N %z.
This is useful because the time output includes all the information that is available from the operating system. For example, this can help explain make's behavior, since GNU make uses the full timestamp to determine whether a file is out of date.
long-iso List ISO 8601 date and time in minutes, e.g., 2002-03-30 23:45. These timestamps are shorter than full-iso timestamps, and are usually good enough for everyday work. This style is equivalent to +%Y-%m-%d %H:%M.
iso List ISO 8601 dates for non-recent timestamps (e.g., 2002-03-30 ), and ISO 8601 month, day, hour, and minute for recent timestamps (e.g., 03-30 23:45). These timestamps are uglier than long-iso timestamps, but they carry nearly the same information in a smaller space and their brevity helps ls output fit within traditional 80-column output lines. The following two ls invocations are equivalent: newline=' ' ls -l --time-style="+%Y-%m-%d $newline%m-%d %H:%M" ls -l --time-style="iso"  
0
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 
LVL 48

Expert Comment

by:Tintin
ID: 22780908
What Unix/Linux flavour are you running?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 22827186
depending on your OS try one of:

ls -E
ls --full-time
ls --time-style=full-iso
0
 

Author Comment

by:infa007
ID: 22867982
Neither of them works :(
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 750 total points
ID: 22868051
Hi,
do you have GNU coreutils?
If no, get it here -
http://ftp.gnu.org/gnu/coreutils/ 
 
If yes, try
ls -l --time-style="+%b-%d-%Y"
 
wmp
0
 
LVL 48

Expert Comment

by:Tintin
ID: 22869541
Define what you mean by not working.

Do you get any errors?

What Unix/Linux flavour are you trying to run this on?
0
 

Author Comment

by:infa007
ID: 22869844
Well i did a uname -a, got AIX
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 750 total points
ID: 22869892
Hi,
 so you probably will have to install GNU coreutils from the Linux Toolbox for AIX.

If you don't have the CD, get the rpm here:
http://www-03.ibm.com/systems/p/os/aix/linux/toolbox/download.html

If you need some hints, please post!

wmp
 
0
 
LVL 85

Expert Comment

by:ozo
ID: 22870628
perldoc perlref
perldoc perllol
0
 
LVL 85

Expert Comment

by:ozo
ID: 22870634
Sorry, posted to wrong question
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question