- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Question about "ls -ltr"
Categories
Company
Local Language
Forums
Discussions
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp
Knowledge Base
Discussions
Forums
Discussions
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
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
05-10-2007 06:50 AM
05-10-2007 06:50 AM
I have the following out from the "ls -ltr" output :
prot@atstb:/appl/tst/test/smt> ls -ltr |grep "prot.*"
drwxr-xr-x 3 atm tst 512 Sep 12 2005 prot.0221
drwxr-xr-x 3 atm tst 512 Dec 28 2005 prot.dec05
drwxr-xr-x 3 atm tst 512 Feb 21 2006 prot.0607
drwxr-xr-x 3 atm tst 512 Jun 7 2006 prot.0410
drwxr-xr-x 4 atm tst 512 Apr 12 16:25 prot.0412
drwxr-xr-x 4 atm tst 512 Apr 13 12:21 prot.0413
drwxr-xr-x 3 atm tst 512 Apr 13 12:23 prot.0416
drwxr-xr-x 4 atm tst 512 Apr 17 15:53 prot.0417
drwxr-xr-x 4 atm tst 512 May 10 12:43 prot.0510
drwxr-xr-x 3 atm tst 512 May 10 12:45 prot
Requirement :
I need to get the penultimate value of the listing ( in this case prot.0510) , which can vary each time I do an install of the prot module and out of that I need to save 0510 in a variable. How do I achieve that . Please help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 06:54 AM
05-10-2007 06:54 AM
Re: Question about "ls -ltr"
If you want the most recent first, drop the '-r' switch:
# ls -lt
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 06:55 AM
05-10-2007 06:55 AM
Re: Question about "ls -ltr"
VAR=$(ls -ltr prot.* | awk -F . '{print $2)')
Try the statement on the command line before assigning to a variable.
# ls -ltr prot.* | awk -F . '{print $2)'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 06:57 AM
05-10-2007 06:57 AM
Re: Question about "ls -ltr"
# ls -ltr prot.* | tail -1 | awk -F . '{print $2}'
To assign to a variable:
VAR=$(ls -ltr prot.* | tail -1 | awk -F . '{print $2}')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 07:02 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 07:03 AM
05-10-2007 07:03 AM
Re: Question about "ls -ltr"
OK, try this:
# ls -lt /path|awk '{if (NR==2) {split($NF,a,".");print a[2]}}'
This skips the line beginning with "total" and extracts the most recent file's name where the suffix follows a "." character.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 07:11 AM
05-10-2007 07:11 AM
Re: Question about "ls -ltr"
Asking for help and assigned zero points to an attempt is not conducive to getting help in the future.
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 07:52 AM
05-10-2007 07:52 AM
Re: Question about "ls -ltr"
thanks,
hunki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 08:07 AM
05-10-2007 08:07 AM
Re: Question about "ls -ltr"
Hope this helps!
Regards
Torsten.
__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.
__________________________________________________
No support by private messages. Please ask the forum!
If you feel this was helpful please click the KUDOS! thumb below!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 08:26 AM
05-10-2007 08:26 AM
Re: Question about "ls -ltr"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 09:13 AM
05-10-2007 09:13 AM
Re: Question about "ls -ltr"
...and did you actually try mine?
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 07:54 PM
05-10-2007 07:54 PM
Re: Question about "ls -ltr"
VAR=$(ls -ltr prot.*|awk -F . 'END {print $2}')
HTH,
Art
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2007 09:15 PM
05-10-2007 09:15 PM
Re: Question about "ls -ltr"
since the prot.* arguments are directories:
ls -dt prot.* | awk -F. '{print $NF;exit}' | read myval
mfG Peter