How to find multiple files with different ending in LInux using regex?

Issue

Let’s say that I have multiple files such as:

root.file991
root.file81
root.file77
root.file989

If I want to delete all of them, I would need to use a regex first, so I have tried:

find ./ - regex '\.\/root'

…which would find everything in root file, but how do I filter all these specific files?

Solution

You can use

find ./ -regextype posix-extended -regex '\./root\.file[0-9]+'

The regex will match paths like

  • \. – a dot
  • /root\.file – a /root.file text
  • [0-9]+ – ending with one or more digits.

Answered By – Wiktor Stribi┼╝ew

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published