On Nov 12, 2007 6:00 PM, मनीष <[EMAIL PROTECTED]> wrote:
> On Nov 12, 2007 5:13 PM, ankIT WALiA <[EMAIL PROTECTED]> wrote:
> > Can anyone tell me, how to get latest created file from a folder to be
> > used in shell script?
> >
>
> Try this:
>
> getLatestFile(){
> if [ $# -eq 1 ]; then
> ls -tr $1 | tail -1
> else
> echo "usage: getLatestFile <dir>"
> fi
> }
>
> ex.
> $ getLatestFile ~
> $ getLatestFile .
> $ getLatestFile /tmp
>
Gora> Well, you can't get the time of creation of a file, as that is
Gora> not stored. You can get various other times, such as the time
Gora> of modification, time of access (unless this has been turned off
Gora> at the filesystem level), and time of modification of file status.
@Ankit, Gora is right, file creation time is not stored. What above
code gives you is the latest `modified' (not necessarily created)
file.
--
Manish
_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Next Event: http://freed.in - February 22/23, 2008
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
http://www.mail-archive.com/[email protected]/