I have a set of directories on my linux box that have names like this:

bulk-load_20090918-162100

The latter part is a timestamp. Is there any way that I can access the directory with the greatest timestamp from zsh?

What would be ideal is if there were a way to configure zsh's tab-completions to find the greatest directory.

link|improve this question

80% accept rate
feedback

2 Answers

up vote 4 down vote accepted

The sort command should help you with this: http://www.computerhope.com/unix/usort.htm

depending on if you do a regular sort or reverse sort, the directory with the highest timestamp could be at the top or bottom. Check the output first, then you can use the head or tail linux command to take the top or bottom entry (example: head -n 1) then pass it to xargs with the cd command. An example is like this:

ls | sort | head -n 1 | xargs cd
link|improve this answer
Exactly what I was looking for. Thanks. :-) – Jason Baker Sep 19 '09 at 14:46
feedback

The directory with the latest timestamp would also be numerically largest value and get sorted to the last position. Is that what you want?

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.