Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In zsh, there is the [m,n] glob qualifier which works as follows:

[beg[,end]]

specifies which of the matched filenames should be included in the returned list. The syntax is the same as for array subscripts. beg and the optional end may be mathematical expressions. As in parameter subscripting they may be negative to make them count from the last match backward. E.g.: ‘*(-OL[1,3])’ gives a list of the names of the three largest files.

So for example, if I type:

print *([2,10]) 

it will return the elements 2 to 10 matched by *.

My question is: How can I ask zsh to return the matched elements starting from element X to the end of the list?

For example say I have 2500 files in one folder, BUT I don't know this number, and I would like to match all files starting from file 160.

I have tried:

1) print -l *([160])

-> only matches file # 160.

2) print -l *([160,])

-> No matches found

3) print -l *~*([1,160])

-> No matches found

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

A negative number counts from the end. The last element is -1.

print -l *([160,-1])

If you wanted the last 42:

print -l *([-42,-1])
share|improve this answer
add comment

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.