Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find the newest directory

Status
Not open for further replies.

kaisalhassani

Programmer
Sep 2, 2007
8
GB
Hi
I have a Unix directory which contains directories one or two or all (java6, java7 and java8).
I would like to know which is the latest java directory.
I can write a Unix script but I would like to know if there is a simplest way to do it in a Unix script.

If the directory contains Java6 only the answer is java6
Or
If the directory contains java6 and java7 the answer is java7
Or
If the directory contains java6, java7 and java8 the answer is java8
Or
If the directory contains java7 and java8 the answer is java8
Or
If the directory contains java8 only the answer is java8
Or
If the directory contains Java7 only the answer is java7

Thank you for your help.
 
Hi,
as long as the number is only one digit:
Bash:
ls -1d java* |sort |tail -1
 
You can specify how to sort:
Code:
ls -1d java* |sort -nk1.5 |tail -1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top