User Tools

Site Tools


list_files_within_a_specific_range

list files within a specific range

In bash, we can use a sequence expression to list files within a specific range. For example

$ echo file{18..21}.txt
file18.txt file19.txt file20.txt file21.txt

The sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. It is part of Bash's brace expansion feature.

Ref:

Possible use cases:

  • To list files
    ls file{18..21}.txt
  • Use a for loop to run a command on each of them
    for file in file{18..21}.txt
    ...

tags | list file names with a range

list_files_within_a_specific_range.txt · Last modified: 2022/04/22 16:45 by raju