System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

a log file has a so big size ! even large then the filesystem!

 
SOLVED
Go to solution
timber
Occasional Advisor

a log file has a so big size ! even large then the filesystem!

Hi All
bdf show:
Filesystem kbytes used avail %used Mounted on
/dev/vgfile/lvmsg 20480000 4309873 15159596 22% /msg
and in the directory ll show:
total 6905078
-rw-r--r-- 1 msg users 131288693050 May 12 09:15 queue_10.err

Now ,I've known the file is a sparse file for du -sk show the true size about 4G+,and xd show large of "0" from head of the file.

What I want to know is:
1.How can i reduce the file,or make the ll's show as nomal
2.The admin have clear the file by #>quwue_10.err. Is this a right way?
May Force be with you !
13 REPLIES
Robert-Jan Goossens
Honored Contributor

Re: a log file has a so big size ! even large then the filesystem!

Hi Timber,

If you do not need the to keep a copy of the data, you can zeroing the file;

# > /full_path_to_file/queue_10.err
or
# cp /dev/null /full_path_to_file/queue_10.err

Regards,
Robert-Jan
avizen9
Esteemed Contributor

Re: a log file has a so big size ! even large then the filesystem!

hi,

#>quwue_10.err. Is this a right way?

this will balnk whole file and remain same attribute, if you feel this file doesnt require can do this, yes this is correct way, thanks,
Ganesan R
Honored Contributor

Re: a log file has a so big size ! even large then the filesystem!

Hi,

You can use this as well.

#cat /dev/null > /path of the the file
Best wishes,

Ganesh.
timber
Occasional Advisor

Re: a log file has a so big size ! even large then the filesystem!

Additional:
My doubt:the admin use > clear a 5G file but when app reopen the file ,the size increase begin from 5G!So a 5G true size file maybe show us 10G by ls -l.and so on
the file will bigger and bigger....
Is this possble?
May Force be with you !
Suraj K Sankari
Honored Contributor

Re: a log file has a so big size ! even large then the filesystem!

Hi,

The correct way of trimming any type of log file is
# > filename
It will trim your file to 0 (zero) bytes.

Suraj
Michal Kapalka (mikap)
Honored Contributor

Re: a log file has a so big size ! even large then the filesystem!

hi,

no because when the file will be reopen the size will be zero.

mikap
Ganesan R
Honored Contributor

Re: a log file has a so big size ! even large then the filesystem!

Hi,

In that case terminate the process which uses the space using lsof then restart the process.

The space will be released by the process only after it terminates.
Best wishes,

Ganesh.
Jozef_Novak
Respected Contributor

Re: a log file has a so big size ! even large then the filesystem!

Hello,

use the trimming by "> filename" only if it contains plain text. Doing this to a binary file (for example /var/adm/wtmp) can corrupt the file so that it will no more be readable by the process that uses it.

J.
timber
Occasional Advisor

Re: a log file has a so big size ! even large then the filesystem!

Unfortunately,after i user "msg" account do the >file clear,but size of file still shown 130G+
May Force be with you !
avizen9
Esteemed Contributor

Re: a log file has a so big size ! even large then the filesystem!

HI,
can you please post bdf output,

what is output for file quwue_10.err
Ganesan R
Honored Contributor

Re: a log file has a so big size ! even large then the filesystem!

Hi,

Could you try to kill the process which is using the file if it is not impact anything?

#fuser -ku quwue_10.err
Best wishes,

Ganesh.

Re: a log file has a so big size ! even large then the filesystem!

>1. How can I reduce the file, or make the ll show as normal

Why? The sparse file is working fine.
Note: doing xd on the file will expand it.
Matti_Kurkela
Honored Contributor
Solution

Re: a log file has a so big size ! even large then the filesystem!

If a program writes into a log file, it should always perform a "fseek(file, 0, SEEK_END);" or a similar operation before each write, as the administrator may have truncated the log file between the writes. Closing the file after each write and re-opening it only when needed would work too.

If the program does not do this operation and the sysadmin truncates the log file, it will result in exactly what you've experienced.

A file with 131 GB of zero bytes at the beginning is inconvenient to process: some text manipulation tools may give up because the file is just too big to handle.

Some programs include a way of signaling them to indicate that its log files have been truncated. See the documentation of your program: if your program has this feature, use it immediately after truncating the file (unless the documentation suggests a different procedure).

If there is no way to tell the program that the file has been cleared, the only way to fix this is:
1.) Stop the program that writes into the file.
2.) Clear the file (just as before, using # > queue_10.err or similar)
3.) Restart the program.

When the program opens the file after the restart, it will read the new size of the file. After that the file should again work normally, without a long string of zero bytes in the beginning.

MK
MK