- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script to find most recent file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 03:35 AM
09-25-2000 03:35 AM
For example, if I have a dir called temp with the following files in it :
Sep 18 21:20 blue
Sep 19 21:19 green
Sep 21 21:19 yellow
I need a script to search this directory and list the most recent file it finds
in a format something like this :
Sep 21 21:19 /temp/yellow
The order of the above is not important as long as I can list the full path to
the file and the timestamp.
Is there a way of doing this?
Many thanks in advance for your support.
Regards,
Preet
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 03:52 AM
09-25-2000 03:52 AM
Re: Script to find most recent file
Did you try "ls -lt" ?
Thanks
R.Suresh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 03:53 AM
09-25-2000 03:53 AM
Re: Script to find most recent file
Try (assuming the directory you want was /tmp):
# ls -alst /tmp|awk -v pwd=`pwd` '{print $7,$8,$9, pwd"/"$10}'' > /tmp/results
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 03:55 AM
09-25-2000 03:55 AM
SolutionIt requires a single argument which is the directory that you want to list (default is the current directory) and only prints the first real 'file'.
#!/usr/bin/sh
DIR=${1:-.}
ls -lt ${DIR} | awk -v DIR=${DIR} '{if ($1 ~/^-/) {print $6 " " $7 " " $8 " "DIR
"/" $9;exit }}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 03:57 AM
09-25-2000 03:57 AM
Re: Script to find most recent file
Ooops, I lost part in pasting it:
# ls -alst /tmp|awk -v pwd=`pwd` '{print $7,$8,$9, pwd"/"$10}' > /tmp/results
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 04:01 AM
09-25-2000 04:01 AM
Re: Script to find most recent file
cd
ll -tr | tail -1 | awk -v pwd=`pwd` +'{print $6" "$7" "$8" "$9}'
This will give you the latest file modified. If you want the latest file accessed then use ll -ur instead of tr.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 04:08 AM
09-25-2000 04:08 AM
Re: Script to find most recent file
oops, problems pasting also, that should read;
ll -tr|tail -1|awk -v pwd=`pwd` '{print $6" "$7" "$8" "pwd"/"$9}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-25-2000 05:53 AM
09-25-2000 05:53 AM
Re: Script to find most recent file
Guys - many thanks to you all for your swift and quality responses - great stuff and much appreciated.