Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Aug 2017 13:34:25 +0100
From:      RW <rwmaillists@googlemail.com>
To:        freebsd-questions@freebsd.org
Subject:   Re: Wildcard on redirection
Message-ID:  <20170805133425.56aed83f@gumby.homeunix.com>
In-Reply-To: <25f022f4-4778-3f28-8d78-1f1b292f849e@cloudzeeland.nl>
References:  <25f022f4-4778-3f28-8d78-1f1b292f849e@cloudzeeland.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
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


 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170805133425.56aed83f>