Wildcard on redirection
RW
rwmaillists at googlemail.com
Sat Aug 5 12:34:32 UTC 2017
On Sat, 5 Aug 2017 13:58:50 +0200
Jos Chrispijn wrote:
> I have this number of .log files which I would like to empty.
>
> Using
>
> echo > *.log
> unfortunately doesn't work so I created
>
> foreach file in (/myfiles/log/*log)
> echo "" > $file
> end
>
> but that sequence is not recognized at all.
Assuming you are using /bin/sh or another bourne shell
for file in /myfiles/log/*.log ;do
echo "" > $file
done
Strictly speaking
echo "" > $file
doesn't leave an empty file because it writes a newline to the file.
If that matters you can use one of:
echo -n "" > $file
printf "" > $file
:> $file
More information about the freebsd-questions
mailing list