Sorting and extracting of dirnames
There are a lot of directories named like
web001
web开发者_运维技巧002 ... web123 ...I want to extract a max-number from this set...
Something likenum="´find -name /dirname sort ... | tail´"
with extracting. I have no ideas...
Thank you
You can use tr -dc [0-9]
to get rid of all non-numbers. Note that this also gets rid of the newline but if you extract just a single line with tail
, that does not matter.
If you want just the number:
find -type d -name web\* | sort | tail -n 1 | cut -d'b' -f2
ls | sort | tail -n 1
Will tell you what the last folder sorted alphabetically is
精彩评论