The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


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 !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 08:23 AM
Command to find out "count" of running process ? MITESH KOTHARI Shell Programming and Scripting 4 04-01-2008 12:27 AM
grep for "exact word" bullz26 Shell Programming and Scripting 7 03-14-2008 02:00 AM
grep to find content in between curly braces, "{" and "}," keshav_rk Shell Programming and Scripting 4 08-09-2007 07:14 PM
How to combine "find" command in for each loop (tcsh) umen Shell Programming and Scripting 3 08-22-2005 01:07 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-10-2006
Registered User
 

Join Date: Apr 2006
Posts: 1
Exclamation 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.
Reply With Quote
Forum Sponsor
  #2  
Old 04-11-2006
spoodie's Avatar
Registered User
 

Join Date: Apr 2006
Posts: 14
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
Reply With Quote
  #3  
Old 04-11-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
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
Reply With Quote
  #4  
Old 04-11-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
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
Reply With Quote
  #5  
Old 04-11-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
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
Reply With Quote
  #6  
Old 04-11-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
hi

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

regards,
swapneel
Reply With Quote
  #7  
Old 04-11-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,613
See my script in this thread.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0