Steve Robbins
Steve Robbins

Reputation: 13822

Clear multiple files

How can I clear/empty multiple files using bash?

For a single file you can use

> foo.log

But I've tried

> *.log;
find . -maxdepth 1 -name "*.log" | xargs >;

But they don't seem to work. How can I do this?

Upvotes: 0

Views: 54

Answers (2)

michael501
michael501

Reputation: 1482

try this , it works :

 find . -maxdepth 1 -name "*.log" | xargs -t -n1 -I '{}' perl -e "open(I,'>{}')"

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799520

The redirection must be performed in a shell, one at a time.

... -exec sh -c "> {}" \; ...

...

for f in *.log
do
  > "$f"
done

Upvotes: 1

Related Questions