I have a directory in which I have numerous files with names like work1, work2, work3, work4 ... workn (where n is any number). I want to only list the files which has work as the prefix after that only 1, 2, 3, 4 or 5.
For example: It should list down work1 work2 work3 work4 work5 . So my logic was ls -al | grep work but it will list work6, work7 etc too. How do proceed?
There is no need to parse the output of ls. Just use a range expression when calling ls:
ls -al work[1-5]
This will match any file whose name matches the pattern work[1-5]. That is, any file whose name is work1, ..., work5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With