LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-27-2014, 06:46 AM   #1
Srinivas Gadi
LQ Newbie
 
Registered: Dec 2012
Posts: 22

Rep: Reputation: Disabled
How to reallocate the deleted logfile space


Hi There,

I know, this is very simple question , but not able to figure out the perfect answer.

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

Thanks
Srinivas
 
Old 12-27-2014, 06:57 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,905

Rep: Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921Reputation: 2921
I'm sorry, but do not understand. The file will be removed from the disk, not from the memory (using the command rm)
 
Old 12-27-2014, 07:34 AM   #3
Srinivas Gadi
LQ Newbie
 
Registered: Dec 2012
Posts: 22

Original Poster
Rep: Reputation: Disabled
Let me explain you clearly

suppose there is log file : /var/log/messages and it occupies the 1G.
and I just deleted it through rm -f /var/log/messages , and the file is no more in the on disk.
but the occupied memory has not been released.

My question is , How to make use of these space with out system reboot?

Hope I am clear now.
 
Old 12-27-2014, 07:44 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
First of all you should not be deleting log files but using 'logrotate' (see 'man logrotate'). Secondly if you manually delete a log file that's currently being written to it remains opened on the file descriptor of the application. The solution is to restart the service (usually a 'kill -HUP' will do).
 
Old 12-27-2014, 03:51 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,714

Rep: Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280Reputation: 1280
Depending on your distribution, I believe that what you actually did was delete an open file.

The space will be reclaimed when the file is closed.

One way of doing that is to restart syslog.

An easier way is to identify the syslogd daemon (ps, it is likely called rsyslogd) and use "kill -1 $(cat /var/run/rsyslogd.pid)".

You can check the rsyslogd manpage for details:

Code:
SIGNALS
       Rsyslogd  reacts  to a set of signals.  You may easily send a signal to
       rsyslogd using the following:

              kill -SIGNAL $(cat /var/run/rsyslogd.pid)

       Note that -SIGNAL must be replaced with the actual signal you are  try‐
       ing to send, e.g. with HUP. So it then becomes:

              kill -HUP $(cat /var/run/rsyslogd.pid)

       HUP    This  lets rsyslogd perform close all open files.  Also, in v3 a
              full restart will be done in order to read changed configuration
              files.   Note  that  this means a full rsyslogd restart is done.
              This has, among others, the consequence that TCP and other  con‐
              nections  are  torn down. Also, if any queues are not running in
              disk assisted mode or are not set to persist data  on  shutdown,
              queue  data  is  lost. HUPing rsyslogd is an extremely expensive
              operation and should only be done when actually necessary. Actu‐
              ally,  it  is a rsyslgod stop immediately followed by a restart.
              Future versions will remove this restart  functionality  of  HUP
              (it  will  go  away in v5). So it is advised to use HUP only for
              closing files, and a  "real  restart"  (e.g.  /etc/rc.d/rsyslogd
              restart) to activate configuration changes.
As stated above, the "logrotate" script will do this for you, and you can use its configuration file to limit the size of log files, having various daemons close their log files as well automatically.

Last edited by jpollard; 12-27-2014 at 03:54 PM.
 
Old 12-27-2014, 05:12 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
There's actually no need to "believe" an open file was deleted when one can simply make sure by checking:
Code:
lsof|grep dele
*Bonus points for making lsof quicker and narrowing things down knowing the location where the log file resides:
Code:
lsof -Pln -a +D/var/log|grep dele
 
  


Reply

Tags
linux, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to reallocate space between partitions/devices ? foampile Linux - Newbie 16 02-26-2009 07:24 PM
FDISK! /var too big; / too small, reallocate disk space pauljtester Linux - General 2 08-05-2004 09:10 PM
How to resize a partition or reallocate space? Avatar Linux - Newbie 12 04-22-2004 05:11 PM
I need to reallocate drive space from mount point / to /boot decampbell1 Linux - Newbie 7 01-08-2004 03:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration