LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 02-01-2012, 07:23 PM   #1
patapout
LQ Newbie
 
Registered: Jan 2012
Posts: 25

Rep: Reputation: Disabled
Delete content of logs files without removing them


Hi
I want to delete just the full content of each file in /var/log but without deleting them, the general process is a loop that grabs the content of each file, remove it and leave the file empty and so one. But I don't figure how to do that since there is in this directory also some files with gz extension wich I don't think it isimportant to delete their content.

I want to delete the content because I was chocked by the huge size of my logs file, please don't tell me to just compress it because I remove the content from time to time of course.

Regards
 
Old 02-01-2012, 07:33 PM   #2
Dutch Master
Senior Member
 
Registered: Dec 2005
Posts: 1,686

Rep: Reputation: 124Reputation: 124
Use log-rotation. It automagically removes older log files for you.

Anyway, what you want can't be done. What you can do is write a script that reads the name of each file in a directory, removes it and then creates a new, empty file of the same name. Essentially, you're about 3/4 of a log-rotation tool if you get that working...
 
Old 02-01-2012, 08:22 PM   #3
patapout
LQ Newbie
 
Registered: Jan 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Hi Dutch
Some applications may probably need the existence of its associated log files like postgresql so for that reason i wouldn't like to just delete any file with .log extension on that directory and this is an easy task anyway. So better to remove only the content and leave the file empty or as you have suggested, read file name delete it and recreate a new empty one.
 
Old 02-01-2012, 09:13 PM   #4
toolbox1234
Member
 
Registered: Jan 2009
Posts: 32

Rep: Reputation: 0
Have you checked this?

http://www.linuxquestions.org/questi...debian-404616/
 
Old 02-02-2012, 07:36 AM   #5
patapout
LQ Newbie
 
Registered: Jan 2012
Posts: 25

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by toolbox1234 View Post
Hi toolbox1234
The last command didn't seem to work properly and I have read this topic before posting here. It toll that the 'do' is not expected. I will try manually clear some log files but I appriciate more confortable way.
 
  


Reply



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
Can I delete files in /mnt/tmp? and Files in the trash can will not delete? M$ISBS Slackware 15 10-02-2009 11:56 PM
Content Filter Logs [Endian Firewall] Qrius Linux - Newbie 0 04-08-2008 01:43 AM
delete file-content ovince Programming 6 04-17-2007 03:44 AM
How does one delete directories with content as the SU? Ferrell Ramey Linux - General 2 08-22-2002 07:16 PM
How to delete a dir and all it's content? ReSync Linux - Newbie 2 06-29-2002 06:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 02:39 PM.

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
Open Source Consulting | Domain Registration