0

I want to delete all .ppm and .png files under current directory. So after checking some web pages about the usage of "find" command on the Internet, I typed the command below:

find . -type f \( -iname ".png" -o -iname ".ppm \) -exec rm {} \;

but the Terminal just showed a

>

and did not do anything. What was wrong with it?

Zanna
  • 70,465

2 Answers2

3

You just forgot to close the quoted string with a " after ".ppm.

The > you see is Bash's secondary prompt, as defined by the $PS2 environment variable. You get it when you input a command fragment that is supposed to continue (like e.g. because it has an unclosed quoted string or a missing done or fi keyword...) but press Enter to make a line break.

Another thing is that -iname ".png" would only (case insensitively) match files with the exact name ".png". What you want is to match all files ending with ".png", so the condition must be -iname "*.png" instead. Same for ".ppm" of course.

So the correct find command would be:

find . -type f \( -iname "*.png" -o -iname "*.ppm" \) -exec rm {} \;

However, I'd usually recommend dry-running it without the -exec rm {} \; first and check the list of files again for correctness, before actually letting it delete stuff without further confirmation.

Also, as correctly pointed out in the comments, you can and probably should replace -exec rm {} \; with -delete to let find handle the deletion internally.

Byte Commander
  • 107,489
0

You don't need find for this. Instead, you can run

rm *{.png,.ppm}

in the directory.