Hi,
Could someone give me a hand with a search for files with two possible extensions, please. The requirement is simple - I need to issue a single ls command searching for files with the suffix of, say, *.txt and *.log.
I've tried to use ls *.txt *.log which works if there are both file-types, however raises an error if only one file-type is there.
Many thanks for any help,
Neil
ls *.log *.txt 2>/dev/null
Thanks Danmero - unfortunately, this doesn't give what I need. I'm doing further processing at this point, and suppressing errors stops other elements working.
Incidentally, I was thinking a regular expression could be used, as it's simple to do this in grep, however I'm not sure how this could be done using ls?
Thanks,
Neil
ls | grep -E '(.*\.log$|.*\.txt$)'
1 Like
That works perfectly. Thanks very much, verdepollo.