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.
You don't need the echo. Just
will empty the file. To edit rassie...
The quotes and brackets are preferred, as they will correctly handle files with spaces or special characters in them.
Just for fun, another variation combining Eric Dennis'
find
with everybody else's redirection:Note that if you really want the files to be emptied you have to use no echo at all, see above, or pass echo the -n flag (echo -n)
Or, if you want to recurse:
A loop could do:
Solution:
echo -n | tee *.log
Explanation:
echo -n
echoes an empty string to stdout; whiletee *.log
writes stdout to mutiple files with widecard like you wished.This will also work.