maolingzhi
maolingzhi

Reputation: 691

how to process linux find command didn't has result

find . -name "*.pyc" -print0| xargs -0 rm

i use this command delete python compiled file but if current directory didn't have any *.pyc file this cmd will not work print out the error with rm command need operator args

how to handle this work if current directory didn't have *.pyc file this situation?

Upvotes: 1

Views: 113

Answers (2)

Josh Cartwright
Josh Cartwright

Reputation: 801

If you can assume GNU find, then you can use find . -name '*.pyc' -delete.

Alternatively, find . -name '*.pyc' -exec rm -rf {} '+'.

Upvotes: 0

perreal
perreal

Reputation: 97918

Using find -exec:

find -name '*.pyc' -exec rm {} \;

or the discard output technique:

find . -name "*.pyc" -print0| xargs -0 -I{} rm {} &> /dev/null

Upvotes: 1

Related Questions