Operating System - HP-UX
1761394 Members
2880 Online
108901 Solutions
New Discussion юеВ

I want to trim all files in a directory to 0 bytes....

 
SOLVED
Go to solution
pap
Respected Contributor

I want to trim all files in a directory to 0 bytes....

How do I do the same. I have 100 files in a directory and I want to trim it to zero bytes each. Please let me know if any script is needed for that.

-pap
"Winners don't do different things , they do things differently"
6 REPLIES 6
Carlos Fernandez Riera
Honored Contributor

Re: I want to trim all files in a directory to 0 bytes....

asuming no drectories:

for file in *
do
> $file
done
unsupported
Jeff Schussele
Honored Contributor

Re: I want to trim all files in a directory to 0 bytes....

Hi Pap,

Do the following

for i in /dir_name
do
> $i
done

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
David Burgess
Esteemed Contributor

Re: I want to trim all files in a directory to 0 bytes....

How about :-

for file in $(ls -1)
do
cat /dev/null > $file
done

Regards,

Dave.
MANOJ SRIVASTAVA
Honored Contributor

Re: I want to trim all files in a directory to 0 bytes....

Hi Pap


#!/usr/bin/ksh

for i in /dirname
do
> $i
done


all the best.


Manoj Srivastava
H.Merijn Brand (procura
Honored Contributor

Re: I want to trim all files in a directory to 0 bytes....

And the perl way

perl -e 'for(<*>){truncate$_,0}'

or even shorter with newer perls

perl -e 'truncate$_,0 for<*>'
Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor
Solution

Re: I want to trim all files in a directory to 0 bytes....

Hi Pap:

Assuming that there might be subdirectories and/or pipes subordinate to your directory:

# cd /dir
# for X in `ls -l | awk '/^-/ {print $9}'`
> do
> cat /dev/null > $X
> done

Regards!

...JRF...