Solved

List file modification date with Year

Posted on 2008-10-22
12
338 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 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 250 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 84

Expert Comment

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

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now