|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Finding latest dir based on it's name (yyyymmdd)
Hi Folks,
As part of my application I need to find out what the latest directory based on the name of that directory (not it's file system timestamp). Example: I have a directory which contains below directories (each of while contains files etc) 20120000/ 20120000/ latest (symbolic link to 20120000) So in this case the latest directory is latest and 20120000 If a new directory called 20130000 gets created here then that would be the latest directory. If another new directory called 20090000 gets created then that would NOT be the latest directory Is there a handy way (using grep / awk / find etc) to check the latest based on the "yyyymmdd" pattern of the directory name. Any advice would be great Thanks - Ro |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
ls | sort -r | grep -v latest | head -1 |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Would a simple sort suffice? Code:
ls -1|sort -n|tail -1 I hope that this helps. If not, then I'm not understanding what you actually want. Please elaborate, with listings if you have any. Robin Liverpool/Blackburn UK ---------- Post updated at 03:20 PM ---------- Previous update was at 03:19 PM ---------- In fact, if you are looking for the highest number, then just Code:
ls -1|tail -1 should work. |
|
#4
|
|||
|
|||
|
I think we need to stop ls finding the directory called "latest". Code:
ls -1d ????0000 | tail -1 |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Hey Folks,
Cheers, the below worked a treat for me: ls | sort -r | grep -v latest | head -1 Thanks! Ronan |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
May be, you want to put the result into a variable:
lastdirectory=`ls | sort -r | grep -v latest | head -1` echo $lastdirectory |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to pick only the latest files based on the timestamp? | win4luv | UNIX for Dummies Questions & Answers | 43 | 06-29-2011 01:30 AM |
| Finding the Latest file in a Dir | filter | Shell Programming and Scripting | 2 | 06-24-2011 11:54 AM |
| grep latest file based on date. | lweegp | Shell Programming and Scripting | 12 | 04-03-2009 03:10 AM |
| finding latest file having timestamp on it..... | kaushik25 | Shell Programming and Scripting | 1 | 08-06-2007 10:35 PM |
| finding latest file in Unix | nick12 | UNIX for Dummies Questions & Answers | 2 | 03-05-2005 01:27 AM |
|
|