How to reallocate the deleted logfile space?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to reallocate the deleted logfile space?
# 1  
Old 12-27-2014
How to reallocate the deleted logfile space?

Hi All,

I know this is a simple question but i am not sure the exact answer it.

Here is the question:
There is a huge log file , if we delete the log file ,how the corresponding occupied file memory relocate to Hard Disk.

Thanks
Srinivas
# 2  
Old 12-27-2014
Make sure there's no application/program that keeps the log file open even though it's deleted.
To release the disk space, don't delete the file but rewrite it with zero size.
# 3  
Old 12-30-2014
Yes, after you have deleted the file there is little you can do to recover the allocated space apart from killing and restarting the process(es) that have the file open.

As RudiC points out you are better off writing zero size to the logfile eg:

Code:
# truncate -s0 /var/log/httpd/access_log

Or

Code:
# :> /var/log/httpd/access_log

As a long-term solution you should consider using the logrotate daemon to keep your logfile sizes down.

Last edited by Chubler_XL; 12-30-2014 at 06:37 PM..
# 4  
Old 01-01-2015
Quote:
Originally Posted by Chubler_XL
Yes, after you have deleted the file there is little you can do to recover the allocated space apart from killing and restarting the process(es) that have the file open.

As RudiC points out you are better off writing zero size to the logfile eg:

Code:
# truncate -s0 /var/log/httpd/access_log

Or

Code:
# :> /var/log/httpd/access_log

As a long-term solution you should consider using the logrotate daemon to keep your logfile sizes down.
And don't be surprised if that doesn't work.

There are ways for applications to write to log files that create problems with that method. One of them is redirecting stderr/stdout by using ">>" shell redirection.

If those methods are used, filesystem-specific features can come into play.

There's a reason why operating systems provide robust, scalable logging facilities. Scalable logging is not something that can be done reliably without serious work.

So if your app is not well-designed, you may be stuck with "kill the app, clean up the log file, restart the app".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Files not getting deleted with rm & occupying space in filesystem

Hello, OS version is Red Hat Enterprise Linux Server release 6.5 (Santiago). In one of the filesystem some old files post clone are not getting removed even with 'rm' # ls -ltr | grep meagpd_62.dbf -rw-rw---- 1 oracle oinstall 34358697984 Sep 1 08:46 meagpd_62.dbf # rm... (7 Replies)
Discussion started by: saharookiedba
7 Replies

2. Shell Programming and Scripting

Logfile monitoring with logfile replacement

Bonjour, I've wrote a script to monitor a logfile in realtime. It is working almost perfeclty except for two things. The script use the following technique : tail -fn0 $logfile | \ while read line ; do ... some stuff done First one, I'd like a way to end the monitoring script if a... (3 Replies)
Discussion started by: Warluck
3 Replies

3. Shell Programming and Scripting

Logs from logfile

Hi Team, Have to write a shell script to pick only 1 hr logs from the generated logfile and send it to other logfile. Thanks & Regards, Indu (3 Replies)
Discussion started by: indira_s
3 Replies

4. UNIX for Advanced & Expert Users

figure out how part of a logfile got deleted

I there a way to figure out how part of a logfile got deleted? I know unix does not have a date created date so that makes things very difficult to tell if the file got deleted or not. Several thousand lines of my .bash_history somehow got deleted. I still have this in my .bashrc so I don't... (0 Replies)
Discussion started by: cokedude
0 Replies

5. Shell Programming and Scripting

xrealloc: cannot reallocate (23523666) bytes

Hi, I have a lengthy shell script and when I try to run it, It takes a lot of time and for about 25-30 mins and outputs this message xrealloc: cannot reallocate (23523666) bytes (0 bytes allocated). Along with this it is also displaying two other error messages. One is it is saying the... (3 Replies)
Discussion started by: nagin
3 Replies

6. UNIX for Dummies Questions & Answers

Reclaim deleted disk space

I have a disk space issue on one of my unix servers. it is showing 98% full.. i found the offending folder and removed it. but i have not reclaimed the disk space. is there another command that i need ? thank you in advance for any assistance. (4 Replies)
Discussion started by: JanSP
4 Replies

7. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

8. Shell Programming and Scripting

logfile

hi iam new of the ksh script.iwant in formation of how to call in logfile in ksh scripts. if the meaning in ksh. please help me thanks naveen.g (1 Reply)
Discussion started by: naveeng.81
1 Replies

9. Shell Programming and Scripting

last month's logfile

hi friends I need a shell script which will do the following Task Enter the month : if you enter 1 then it ll show you last 1 month's (starting from today).log file in the current directry. if you enter 4 then it ll show you last 4 month's (starting from today).log file in the current... (2 Replies)
Discussion started by: deep_kol
2 Replies

10. Shell Programming and Scripting

How to keep white space is being deleted using read

I am using Posix shell to write a script. The problem I am having is that when I use the read command to go through a file I lose the tabs. How can I keep this from happening? (1 Reply)
Discussion started by: keelba
1 Replies
Login or Register to Ask a Question