Search code examples
regexlinuxbashfind

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


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.