Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

List file modification date with Year

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
infa007
Asked:
infa007
  • 5
  • 2
  • 2
  • +2
2 Solutions
 
woolmilkporcCommented:

You don't see the year when less than 6 months (ca.) passed.
0
 
woolmilkporcCommented:
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
 
woolmilkporcCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
TintinCommented:
What Unix/Linux flavour are you running?
0
 
ahoffmannCommented:
depending on your OS try one of:

ls -E
ls --full-time
ls --time-style=full-iso
0
 
infa007Author Commented:
Neither of them works :(
0
 
woolmilkporcCommented:
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
 
TintinCommented:
Define what you mean by not working.

Do you get any errors?

What Unix/Linux flavour are you trying to run this on?
0
 
infa007Author Commented:
Well i did a uname -a, got AIX
0
 
woolmilkporcCommented:
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
 
ozoCommented:
perldoc perlref
perldoc perllol
0
 
ozoCommented:
Sorry, posted to wrong question
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now