Discussion Locked

Emptying a file used by another Process

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have a file that is being updated by a process. I try to empty it using the command:
echo > filename
When I do this and do a df -k ., it shows that the space occupied has reduced after the operation. But when I do a ls -l on that file, I find that the file size is the same. Can somebody please explain how this happens. Is there any other ways of emptying a file that is used by another process?

5 replies

by blue_throat1

Poster rated this answer.
Thanks for your quick response.
I tried doing what you had suggested. If I do a df -k after this, it shows that the space has reduced, but when I do an ls -lrt it gives the same old previous size.

by black panther

What type of file is it??

type in file filename

ie see below example

I create a file called junk in the /tmp directory

prontoprd:/tmp >ls -l junk
-rw-rw-r-- 1 root pronto 20 Aug 12 07:39 junk

prontoprd:/tmp >file junk
junk: commands text

prontoprd:/tmp >cat /dev/null >junk

prontoprd:/tmp >ls -l junk
-rw-rw-r-- 1 root pronto 0 Aug 12 07:40 junk

If it's a data file then you may have to flat-file the information and import it - depending on where/how it is used an what application?

by techrepublic

A number of processes - especially loggers and apache will need to have a HUP sent to them, to start writing to a new file...

There are auto log rotation scripts out therre that can automate this.

This discussion is closed to new replies.