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.

On Linux, I have some folders r1, r2, r3, etc. and I want to get the name of the folder with the largest number at the end. How do I get the name?

share|improve this question

2 Answers 2

up vote 0 down vote accepted
printf '%s\n' r[0-9]* | sort --version-sort | tail -n 1
share|improve this answer
    
Just for completeness: --version-sort doesn't exist on OS X (sort (GNU coreutils) 5.93) –  slhck Apr 20 '11 at 20:34
    
@slhck: Well, the question specifically mentions Linux, and we have coreutils 8.11 here. –  grawity Apr 20 '11 at 20:35
    
I know, that's why I said "just for completeness". –  slhck Apr 20 '11 at 20:36

My version of ls has ls -v

$ for i in {1..19}; do touch r$i; done
$ ls | tail -1
r9
$ ls -v | tail -1
r19
$ ls --version
ls (GNU coreutils) 8.10
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.