Re: [newbie] deleting contents of a file

2001-07-10 Thread Dan Ray

Craig--

 Many people suggested removing the file and then recreating a new empty
 file. While not difficult, that does take a little more time. Your method
 is much simpler and very quick. I just tried it on a log file and it works
 great.

 Can anyone give me a reason why this method might cause problems?

Well, it's just been pointed out that it doesn't actually EMPTY the file per 
se. It actually creates a one-byte file. I believe that the 'echo' command 
prints the string argument given it, plus a newline on the end. That newline 
gets into the new file, so you actually have a file that isn't empty, but 
contains a single newline character.

As long as you don't actually need this file to be totally emptied to zero 
bytes, and don't mind a blank line at the top of the file, this should work 
fine. I haven't seen the permissions issue that Jose mentions at all, in all 
my fooling with this the permissions are preserved. So maybe he's seeing 
something we're not.


-- 
Dan Ray
Director Custom Applications
Triangle Research, Inc.
http://www.triangleresearch.com




Re: [newbie] deleting contents of a file

2001-07-10 Thread Dan Ray

JOse--

 #tail oldfile  oldfile

Clever! Although, of course, the question was EMPTYING the file, not cutting 
it down to the last 10 ines...

Actually, I don't see why redirecting output from tail would have any 
different effect on the target file than redirecting output from echo. 
Shouldn't both be simple stdout redirects into oldfile? Shouldn't both have 
the same effect on oldfile's permissions?

-- 
Dan Ray
Director Custom Applications
Triangle Research, Inc.
http://www.triangleresearch.com




Re: [newbie] deleting contents of a file

2001-07-10 Thread Jan Wilson

* Dan Ray [EMAIL PROTECTED] [010710 06:14]:
 Well, it's just been pointed out that it doesn't actually EMPTY the file per 
 se. It actually creates a one-byte file. I believe that the 'echo' command 
 prints the string argument given it, plus a newline on the end. That newline 
 gets into the new file, so you actually have a file that isn't empty, but 
 contains a single newline character.
 
 As long as you don't actually need this file to be totally emptied to zero 
 bytes, and don't mind a blank line at the top of the file, this should work 
 fine. I haven't seen the permissions issue that Jose mentions at all, in all 
 my fooling with this the permissions are preserved. So maybe he's seeing 
 something we're not.

As Ray says, the

echo  myfile

method works fine regarding ownership and permissions, but leaves a
newline in the file. If you want a zero-length file, why not:

echo -n  myfile

this tells 'echo' not to follow the (empty) string with a newline, so
the resulting file is zero length.  I just tested this on Mdk 8.0 to
be sure.

-- 
Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
Corozal Junior College   |  |:'  corozal.com corozal.bz
Corozal Town, Belize |  /'  chetumal.com  linux.bz
Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML





Re: [newbie] deleting contents of a file

2001-07-10 Thread Dan Ray

Jan--

 echo -n  myfile

 this tells 'echo' not to follow the (empty) string with a newline, so
 the resulting file is zero length.  

Aha! Just what I didn't know I was looking for!

This command is my new nominee for best way to do it.

-- 
Dan Ray
Director Custom Applications
Triangle Research, Inc.
http://www.triangleresearch.com




Re: [newbie] deleting contents of a file

2001-07-09 Thread Tim Holmes

Bascially you want a file, like a log, that had tons of data in it, to have all
the data removed, but there still be a log file there?  Does that sound about
right?

What I would do, would be delete the file

rm -f file.log

And then to get the file there again, with the bit size of 0 (zero) I'd use the
touch command.

touch file.log

If you then get a ls -la on the file, it will give you this.

[timh@r2d2 timh]$ touch file.log
[timh@r2d2 timh]$ ls -la file.log
-rw-r--r--1 timh timh0 Jul  9 08:09 file.log


That's how I would go about it.  Others would open the file in NEdit and then
just delete everything and save it.  All depends on how ya want to go about
doing it.
tdh

--
T. Holmes
-
UNIXTECHS.org
[EMAIL PROTECTED]
-
Real Men Us Vi!

Uptime:
  
 8:08AM  up 4 days, 11:15, 5 users, load averages: 0.01, 0.05, 0.02
  
Your Fortune
Of course it's the murder weapon.  Who would frame someone with a fake?

| * Craig Westerman [EMAIL PROTECTED] [010708 23:47]:
| Is there a linux command that will remove the contents of a file, but
| leave the file name?
| 
| To empty a text file named file.txt, I would do:
| 
| $ cp /dev/null file.txt
| 
| There are probably quite a few other ways to do it.
| 
| -- 
| Jan Wilson, SysAdmin _/*];  [EMAIL PROTECTED]
| Corozal Junior College   |  |:'  corozal.com corozal.bz
| Corozal Town, Belize |  /'  chetumal.com  linux.bz
| Reg. Linux user #151611  |_/   Network, SQL, Perl, HTML
| 
| 
  -- 




Re: [newbie] deleting contents of a file

2001-07-09 Thread Dan Ray

Craig--

On Monday 09 July 2001 01:20 am, Craig Westerman wrote:
 Is there a linux command that will remove the contents of a file, but leave
 the file name?

Echo an empty string into it:

$ echo ''  filename.txt

That '' is a pair of single-quotes, incidentally. It's sort of hard to see 
that in some fonts...


-- 
Dan Ray
Director Custom Applications
Triangle Research, Inc.
http://www.triangleresearch.com




RE: [newbie] deleting contents of a file

2001-07-09 Thread Franki

There probably is, but I don't know it..

I use :

rm filename
touch filename

that removes the file and recreates it...

regards

Frank
  -Original Message-
  From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Craig Westerman
  Sent: Monday, 9 July 2001 1:21 PM
  To: Mandrake Newbie
  Subject: [newbie] deleting contents of a file


  Is there a linux command that will remove the contents of a file, but
leave the file name?

  Thanks

  HW





RE: [newbie] deleting contents of a file

2001-07-09 Thread Jose M. Sanchez


Using echo effectively creates a new file with new permissions.

My preference is to use tail to tail the file over itself.


I.E.

#tail oldfile  oldfile

This preserves all existing permissions and ownerships.

-JMS


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]] On Behalf Of Craig Westerman
Sent: Monday, July 09, 2001 11:27 PM
To: Mandrake Newbie; [EMAIL PROTECTED]
Subject: RE: [newbie] deleting contents of a file


Dan,

Many people suggested removing the file and then recreating a new empty
file. While not difficult, that does take a little more time. Your
method is much simpler and very quick. I just tried it on a log file and
it works great.

Can anyone give me a reason why this method might cause problems?

Thanks

Craig 
[EMAIL PROTECTED]




Craig--

On Monday 09 July 2001 01:20 am, Craig Westerman wrote:
 Is there a linux command that will remove the contents of a file, but
leave
 the file name?

Echo an empty string into it:

$ echo ''  filename.txt

That '' is a pair of single-quotes, incidentally. It's sort of hard to
see that in some fonts...


--
Dan Ray
Director Custom Applications
Triangle Research, Inc.
http://www.triangleresearch.com






[newbie] deleting contents of a file

2001-07-08 Thread Craig Westerman



Is there a 
linux command that will remove the contents of a file, but leave the file 
name?

Thanks

HW