INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Find the newest directory

Find the newest directory

(OP)
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.

RE: Find the newest directory

Hi,
as long as the number is only one digit:

CODE --> bash

ls -1d java* |sort |tail -1 

RE: Find the newest directory

(OP)
Hi
Thank you for that.
The digit could be more than one.

RE: Find the newest directory

You can specify how to sort:

CODE

ls -1d java* |sort -nk1.5 |tail -1 

RE: Find the newest directory

(OP)
Hi
Thank it has worked

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close