This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes how to reterive a file from specific path using unix script Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to reterive a file from specific path using unix script" Watch "how to reterive a file from specific path using unix script" New topic
Author

how to reterive a file from specific path using unix script

prasanna ganesh
Greenhorn

Joined: Jul 04, 2011
Posts: 9
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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

FILE=`ls -ltr | tail -1`

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

FILE=${{ ls -ltr | tail -1 }}

Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to reterive a file from specific path using unix script
 
Similar Threads
Executing shell script
Need help to Copy a File from Unix to Windows
any java method which can work like grep command in unix
Need help to schedule a job
How do I set environment variables in Ant