search

Home  >  Q&A  >  body text

Please tell me how to filter by regular expression using find command in linux?

I want to find files in the current directory that match the format: integer_integer.zip, find and delete them.
For example, a file name like this: 234_23444.zip

How to write the command? Thank you, Daniel!

仅有的幸福仅有的幸福2777 days ago916

reply all(1)I'll reply

  • 迷茫

    迷茫2017-06-17 09:18:46

    You can use the option -regex to use regular expressions:

    find . -regex '\./[0-9]+_[0-9]+\.zip'

    If you need to delete the found files, use xargs (please make sure before deleting):

    find . -regex '\./[0-9]+_[0-9]+\.zip'|xargs rm -f

    If you not only want to delete but also get the number of deletions, you can do this:

    find . -regex '\./[0-9]+_[0-9]+\.zip'|tee >(wc -l 1>&2)|xargs rm -f

    reply
    0
  • Cancelreply