Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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
share|improve this answer
    
Exactly what I was looking for. Thanks. :-) –  Jason Baker Sep 19 '09 at 14:46

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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