How to recursively delete multiple files with different extensions?

I am trying to write a command to recursively delete several files with different extensions (* .extension1, * .extension2, etc.) from the current directory and all its subdirectories.

So far, I got this command from another message , but I could not train how to adapt it to multiple files on the same command line:

find . -name "*.extension1" -type f -delete

Is it as simple as below?

find . -name "*.extension1";"*.extension2" -type f -delete

Just like a note , these are all output files that I do not need, but not all are necessarily output, so some of them may be missing. This is like a general cleaning command.

+4
source share
4 answers
find . \( -name "*.extension1" -o -name "*.extension2" \) -type f -delete

find documents (-name ".py" -o -name ".html") -exec file {} \;

OR

find . -regextype posix-egrep -regex ".*\.(extension1|extension2)$" -type f -delete
+8
source

Just add more options. A regular expression solution may also be applied, but it is better and safer.

find . \( -name '*.ext1' -or -name '*.ext2' \) -type f -delete

Edit: you'll probably need it -or. Before uninstalling, first check it without an option -delete. (2) Added pair ()suggested by gniourf_gniourf.

+2
source

, regexp

find . -regextype posix-awk -regex "(.*.ext1|.*.ext2)" -type f -delete
+1

1 extension2 . rm find . -name *.extension1 -o -name *.extentions2

0

Source: https://habr.com/ru/post/1543400/


All Articles