Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
$ ls -v | tail -1
$ ls --version
ls (GNU coreutils) 8.10
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .