General discussion

Locked

Emptying a file used by another Process

By blue_throat1 ·
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?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Black Panther In reply to Emptying a file used by a ...

Try this instead

cat /dev/null >filename

Collapse -

by blue_throat1 In reply to

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 <file Name> it gives the same old previous size.

Collapse -

by Black Panther In reply to Emptying a file used by a ...

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?

Collapse -

by techrepublic In reply to Emptying a file used by a ...

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.

Collapse -

by blue_throat1 In reply to
Back to Linux Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums