![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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
if its a current file file1---2006 and probably for an old file from 2004 then oldfile1---2004 |
|
#6
|
|||
|
|||
|
hi
it also returns ls -lg output i dont know how to avoid that can u guide me on same. regards, swapneel |
|
#7
|
||||
|
||||
|
See my script in this thread.
|
||||
| Google The UNIX and Linux Forums |