LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-30-2004, 02:00 AM   #1
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,440

Rep: Reputation: 52
Save last modified to a variable


Hello all,

As you can tell I'm a bit new when it comes to bash scripting. Is it possible to write a bash script that will list and then save the most recent modified file (in only 1 path) to a variable? Please shed some light to me thanks!

-twantrd
 
Old 03-30-2004, 07:45 AM   #2
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Sure, just use something like:

Code:
PATH=/your/path/here
GREATEST_MTIME=0
STAT=/usr/bin/stat

for FNAME in $PATH/*; do
    if [ `$STAT -c %Y $FNAME` -gt $GREATEST_MTIME ]; then
        MOST_RECENT_MODIFIED=$FNAME;
    fi;
done

export MOST_RECENT_MODIFIED
Note: untested, but should either work as is or be pretty close.

Last edited by Strike; 03-30-2004 at 07:51 AM.
 
Old 03-31-2004, 03:57 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Code:
file=$(ls -1t|head -1)
billy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set environment variable when can't save changes into disk? happy_maoron Linux - Newbie 1 10-17-2005 03:01 AM
how to cat a text file and save it as a variable mrobertson Programming 37 07-05-2005 08:20 AM
Find variable in template file replace w/date+ and save as jmanjohn61 Linux - General 14 12-13-2004 06:49 AM
vi won't save modified file. mimsmall Linux - General 1 03-26-2004 10:04 PM
How to get 'Window' variable from a 'Widget' variable bordel Programming 0 11-19-2003 03:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration