user1661677
user1661677

Reputation: 1272

How can I list files x to y in a directory (Bash)

This lists all svg files in a directory:

ls -1 *.svg

But how could I list say, the 50th svg through the 100th svg?

Thank you

Upvotes: 2

Views: 97

Answers (3)

Jeffrey Cash
Jeffrey Cash

Reputation: 1073

The other answers here work perfectly well, but I thought I'd contribute a purely bash-builtin solution:

declare -i x=50 y=100 i=0;
for f in *.svg; do
    ((++i>y)) && break;
    ((i>=x)) && echo "$f";
done;

Here it is again as a single, compact line:
declare -i x=50 y=100 i=0; for f in *.svg;do((++i>y))&&break;((i>=x))&&echo "$f";done

Upvotes: 0

Henry Duna
Henry Duna

Reputation: 54

Try:

ls -1 *.svg | awk "NR >= 50 && NR <= 100"

Upvotes: 3

Peddipaga
Peddipaga

Reputation: 74

This helps?

ls -1 *.svg | head -100 |tail -50

Upvotes: 0

Related Questions