A
A
aar2016-09-14 22:19:22
linux
aar, 2016-09-14 22:19:22

How to display files by name in the terminal that have two-digit numbers or more?

For example, there are a number of files
test1212test.txt
test1211test.txt
test12test.txt
test21test.txt
test2121test.txt
test33test.txt
test1test.txt
test2test.txt
test3test.txt
For example, in order to display the files test1test.txt test2test.txt you need to type the following command in the terminal:
ls test[12]test.txt
The terminal will output the following:
test1test.txt test2test.txt
How to output through the ls files test1211test.txt test1212test.txt in the same way?
Through square brackets it is impossible - are limited to numbers 0-9.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
warnerbrowsers, 2016-09-14
@andranique

If you need to display files with 4 digits in the middle, you must specify
test\d{4}test.txt like this. If from 2 to 4 digits, then
test\d{2,4}test.txt. Further by analogy.
Or, abstractly, there are several characters between test and test.txt, no matter if they are numbers or letters. Then you can try this. Though ugly, but it works. 125bde4cb8424bd98f40bff6f6f747db.png
Or if you need to display the numbers in order, then something like this
87fa676ef99d4fb6b405a40afe8ff133.png

I
Ivanq, 2016-09-14
@Ivanq

Add a plus - ls test[1234567890]+test.txtor at all ls test\d+test.txt
(I'm not strong in bash myself, but it can work)
UPD What I took for a regular expression is bash expansion . Here you can use ls | egrep '^test\d+test.txt$'or something similar

D
Dmitry Shitskov, 2016-09-15
@Zarom

3fd004beeb8445a58564c1efe7f7c75d.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question