How to 'echo "" > x' on multiple files

What is the best way how to empty a bunch of files in bash? As far I've been doing this

echo "" > development.log
echo "" > production.log

I don't really want to delete those files, so rm is not possible. I've tried many things like

echo "" > *.log

but nothing worked.


Solution 1:

You don't need the echo. Just

>filename

will empty the file. To edit rassie...

for FILE in *.log
do
   >"${FILE}"
done

The quotes and brackets are preferred, as they will correctly handle files with spaces or special characters in them.

Solution 2:

Just for fun, another variation combining Eric Dennis' find with everybody else's redirection:

find . -name "*.log" -exec sh -c ">{}" \;