• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to reterive a file from specific path using unix script

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I want to take a file from specific path using unix shell script.

The file which i want, should take the file from the location given by using the following command in unix "$ls -ltr | tail -1". That is it should take the latest file in that path.

Below is my script. I can able to view the list of files in the path but i need to take the file into one specific location or into a variable.

Could some one help me on this. Thanks for your help in advance.

#!/bin/ksh
PATH= /www/a/logs/
if [ -d $PATH ]
then
echo "is a directory"
ls -ltr | tail -1
fi
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FILE=`ls -ltr | tail -1`

Or you can use the alternate evaluation notation, which goes something like this:

FILE=${{ ls -ltr | tail -1 }}
reply
    Bookmark Topic Watch Topic
  • New Topic