Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Get latest updated file from your Current Working Directory

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 23-11-2009
Member
 
Join Date: Nov 2009
Posts: 582
Get latest updated file from your Current Working Directory

Hi, I am student of BSC.I.T. and wanted to know more about UNIX. So, I am making R&D in unix shell script. So, can anyone explain me how to get the name of the file which is latest updated in that directory? Please give me the command and if possible explain it.
Reply With Quote
  #2  
Old 23-11-2009
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
Re: Get latest updated file from your Current Working Directory

Hi, I am also new to this UNIX programming and not interested in this. But, if you have interest in this then just try to use of internet and download books regarding it. As it may provide you more knowledge and commands regarding it. Or make search for the commands regarding what you want. You can buy book of Orelly to get more advanced knowledge. Just make use of it. So, that you can be able to know more.
Reply With Quote
  #3  
Old 23-11-2009
Member
 
Join Date: May 2008
Posts: 1,990
Re: Get latest updated file from your Current Working Directory

Hi, you want to get latest updated file from your current working directory, So if your CWD contains only files and directories. Then you can use following command:

Code:
cd <your existing folder>
filename=$(ls -1t|while read obj
do
echo $obj
break
done)
echo $filename
Reply With Quote
  #4  
Old 23-11-2009
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
Re: Get latest updated file from your Current Working Directory

Hi, I am not having that much information in Unix. But as you want to know the latest updated file from your current working directory you can use just following command which will solve your problem I think. Just try this.

Code:
latestfile=`ls -1tr | tail -n 1`
This would give the latest updated file from the directory in which you are currently and it will store that filename in the variable.
Reply With Quote
  #5  
Old 10-07-2010
Member
 
Join Date: Jul 2010
Posts: 1
Re: Get latest updated file from your Current Working Directory

hey, buddy the following line gives u latest updated file (it can be directory also)

LATEST_FILE=`ls -1tr | tail -n 1`

OR

LATEST_FILE=`ls -ltr | tail -1 | tr -s '[:space:]' '[\:*]' | cut -d ":" -f 10`

here the LATEST_FILE is a variable which contains latest updated file

Last edited by sumy : 10-07-2010 at 03:46 PM.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Get latest updated file from your Current Working Directory"
Thread Thread Starter Forum Replies Last Post
How to get the latest icons and folder shading on a updated Nokia N8? Antariksh Portable Devices 5 4 Weeks Ago 08:43 PM
Current Circuits been updated in Forza Motorsport 4 Chande Video Games 5 11-10-2011 12:20 PM
Is it possible to run latest video games with my current specification GoutamB Monitor & Video Cards 8 05-09-2011 11:18 PM
GTA IV latest updated addon Mario2 Video Games 3 31-03-2009 11:40 AM
How to get current directory Scott2580 Software Development 3 11-10-2008 04:40 PM


All times are GMT +5.5. The time now is 11:29 AM.