Home > front end >  Unix: looking for an alternative command to exclude the semicolon in the end
Unix: looking for an alternative command to exclude the semicolon in the end

Time:11-24

I would like to know if there is an alternative to:

find -name "broken" -exec rm '{}' ';'

I want to avoid the semicolon in the end.

I'm looking for a solution to exclude the semicolon. When i just remove it it does not work. First I want to list certain files and let them be displayed before deleting them. This should work for all directories and subdirectories. And the "|" (i think its called pipe) and it does not work either.

CodePudding user response:

The ; is part of one of the two supported find -exec syntaxes so you cannot remove it:

-exec utility_name [argument ...] ;
-exec utility_name [argument ...] {}
     The end of the primary expression shall be punctuated by a <semicolon> or by a <plus-sign>. [...]

In certain cases (like yours) you might want to replace the semi-colon with a (see bellow).


First I want to list certain files and let them be displayed before deleting them

With GNU find:

find -name "broken" -print -delete

With standard find:

find . -name "broken" -print -exec rm -- {}  
  • Related