How to find out the exact year in "Last modified time" using ls command | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How to find out the exact year in "Last modified time" using ls command

UNIX for Dummies Questions & Answers


Tags
linux

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-11-2006
Dophlinne Dophlinne is offline
Registered User
 
Join Date: Apr 2006
Last Activity: 11 August 2006, 2:30 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Error How to find out the exact year in "Last modified time" using ls command

Hi,

I understand that the ls command with "-l" option generates the "last modified time" of specific directory.

However, some generated results displayed the "last modified time" with detail about the last modified year, for example:

-rwxrwxrwx+ 1 smith dev 10876 May 16 2005 part2

some results, on the other hand, only display the detail about the time but not the year, for example:

-rwxrwxrwx+ 1 smith dev 10876 May 16 9:42 part2

I would appreciate if anybody could tell me how to find out the last modified year if I got the latter result, i.e. output with last modified time only.

Thank you.
Sponsored Links
    #2  
Old 04-11-2006
spoodie's Avatar
spoodie spoodie is offline
Registered User
 
Join Date: Apr 2006
Last Activity: 18 January 2008, 7:49 AM EST
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Maybe I'm stating the bleeding obvious but I believe the year is displayed when the file was last modified in previous years, ie. not the current year. So you can assume that when the time is displayed the file/directory was modified in the current year.

If you're using Linux you can use the --time-style argument to force displaying of the year, but I'm not sure about UNIX:

Code:
ls -l --time-style=+%Y

Sponsored Links
    #3  
Old 04-11-2006
d_swapneel14 d_swapneel14 is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 13 October 2006, 11:13 AM EDT
Location: Mumbai,India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
hi

it does not work on unix. i dont know if there is any command for this query. As i m new to unix/linux/

here one logic im trying to use.. when we do ls-l
in resultant set -- update date/time - we have capital letter like Apr,Mar,Jan
if we are able to get that character -- and next max12 chracters.
then u can get the required year. like

-rwxrwxrwx 1 aaamart 901 176 Mar 29 15:12 casetest.sh
-rwxrwxrwx 1 aaamart 901 2 Apr 10 10:03 cronsettings

here M- Mar and A- Apr and then if ":" exists then year is current year or the specified year.


regards,
swapneel
    #4  
Old 04-11-2006
d_swapneel14 d_swapneel14 is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 13 October 2006, 11:13 AM EDT
Location: Mumbai,India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
hi

try this

ls -lg | awk '//
{
if(length($7)==4)
{
print $8,$7
}
else
{
print $8, system("date +%Y")
}
}'

it will prints file name and year - if exists otherwise it will print
file name and current year.

it also returns ls -lg output i dont know how to avoid that

might be someone from foroum willhelp us

regards,
swapneel
Sponsored Links
    #5  
Old 04-11-2006
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 5 July 2014, 11:14 AM EDT
Location: classification algos
Posts: 3,203
Thanks: 19
Thanked 30 Times in 27 Posts

Code:
#! /usr/bin/ksh

curr=`date +%Y`
ls -l | while read file
do
if [ `echo $file | nawk '{print gsub(/:/," ",$0)}'` -eq 1 ]
then
	echo $file $curr | nawk '{print $9"---"$10}'
else
	echo $file | nawk '{print $9"---"$8}'
fi
done

exit 0

it would display output something like
if its a current file
file1---2006
and probably for an old file from 2004 then
oldfile1---2004
Sponsored Links
    #6  
Old 04-11-2006
d_swapneel14 d_swapneel14 is offline
Registered User
 
Join Date: Mar 2006
Last Activity: 13 October 2006, 11:13 AM EDT
Location: Mumbai,India
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
hi

it also returns ls -lg output i dont know how to avoid that
can u guide me on same.

regards,
swapneel
Sponsored Links
    #7  
Old 04-11-2006
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 19 September 2014, 2:05 PM EDT
Location: Ashburn, Virginia
Posts: 9,925
Thanks: 60
Thanked 435 Times in 260 Posts
See my script in this thread.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"ps -ef" command and exact matching aoussenko Shell Programming and Scripting 3 11-04-2011 12:37 PM
Problem with "find" and "grep" command pstein Shell Programming and Scripting 5 09-30-2011 10:04 AM
awk command to replace ";" with "|" and ""|" at diferent places in line of file shis100 Shell Programming and Scripting 7 03-16-2011 08:59 AM
command for recently modified files - "find" command not working joe.mani UNIX for Advanced & Expert Users 1 08-16-2010 01:49 AM
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 11:23 AM



All times are GMT -4. The time now is 11:55 PM.