LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 05-07-2021, 04:57 AM   #1
Doga Ozer
LQ Newbie
 
Registered: May 2021
Posts: 3

Rep: Reputation: Disabled
Question Which /var/log files can I remove to make space on my drive?


Hi all,

My question is quite general and not quite specific on which log files I'm pointing out to.

But does anybody know how I can determine the old .log.1 or .gz files that are listed in my /var/log directory?

I wanted to backup all of the log files onto a USB partition, but don't know if that's possible on Linux.

Could you perhaps give me suggestions regarding this question I have please?

Thank alot for your support in advance guys!

Kind Regards,

Doga
 
Old 05-07-2021, 05:14 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
any .gz can be removed, if you do not need them.
 
Old 05-07-2021, 05:26 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,128

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
See the manpage for ls - something like "ls -ltr" might be a good start. Start deleting from the top (reverse time ordered).
 
Old 05-07-2021, 05:38 AM   #4
Doga Ozer
LQ Newbie
 
Registered: May 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
any .gz can be removed, if you do not need them.
oh thanks a lot! will definitely do that! appreciate it!
 
Old 05-07-2021, 05:42 AM   #5
Doga Ozer
LQ Newbie
 
Registered: May 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
See the manpage for ls - something like "ls -ltr" might be a good start. Start deleting from the top (reverse time ordered).
Thanks! so according to the list of months top to bottom, from oldest to latest sort of thing?

And for backup, I'm not sure if there's any backup for the logs. Some of the logrotate files are misconfigured so I have changed the rotate from 4 to 1 on /etc/logrotate.conf configuration file, so that it doesn't clog up much space for next time rotating more than 4 log files, if that's what the purpose for that is? that is from what Iv'e understood.

Last edited by Doga Ozer; 05-07-2021 at 05:44 AM.
 
Old 05-07-2021, 08:38 AM   #6
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,601

Rep: Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546Reputation: 2546

Log files should not be occupying a great deal of space. If your aim is to free up space you probably want to look elsewhere.

You can confirm their combined size using with "sudo du -sh /var/log" - if they do happen to be taking up excessive space, you should investigate if you have any applications configured with overly verbose/debug log settings that you can revert back to standard levels.

 
Old 05-07-2021, 10:34 PM   #7
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
If the log rotate is misconfigured I would suspect it is because of changes someone has made from the default.

I don't know the reason you are looking at purging log files which happens automatically during a proper log rotate, but suspect it may be due to running out of disk space. The suggestion has already been made to check space used with du.

Maybe the output of a simple "df" would tell us more about what is happening.

Also, if logrotate is not properly rotating logs then the purge that normally happens may not, and if that is the case then the logrotate config needs fixed or the manual purge you are trying to do now will just happen again and again until logrotate is fixed.
 
Old 05-08-2021, 01:05 AM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Doga Ozer View Post
Hi all,

My question is quite general and not quite specific on which log files I'm pointing out to.

But does anybody know how I can determine the old .log.1 or .gz files that are listed in my /var/log directory?

I wanted to backup all of the log files onto a USB partition, but don't know if that's possible on Linux.
Backing up the log files won't (IMHO) do much good if you're never going to look at them.

Questions I would ask myself:
  1. How quickly will I be responding to incidents that appear in the log files?
  2. Do I even know what to look for in the log files?
If you only find the time to look at the log files on, say, the weekend, and respond to what they contain, you might want to configure logrotate to retain logs (compressed logs if you're not already compressing them) for 10-15 days. That would give you plenty of time to look through logs and deal with what you see in them. Once you get into a habit of looking at the logs, or you've established an automated means of looking through them and generating a report, you can cut down that retention period.
What to look for? Go through a few of the logs and see what looks suspicious: failed root logins and stuff like that. Start by cutting-n-paste some of the strings you see in the messages file and add them to a file named, say, "suspicious_messages.txt" then you could create a short shell script to grep for those strings and email the results to be read. Something like:
Code:
$ sudo grep -f suspicious_messages.txt /var/log/messages | mailx -s "Interesting stuff in messages file" my-account-name
You could set this up in cron to run just before midnight to you get a summary of today's interesting events. (If sudo is always prompting you for a password, you will find it easier to run this command in root's crontab.) If you're worried about missing something important in the last minute or so of the day, you could schedule the command to be run just after midnight though this means a scheduling a simple command won't be as easy as you'll need to picked the correct, by then, compressed log file (see "xz -dc", "bzip2 -dc", etc. to get to the raw log file). Play around with:
Code:
$ date --date='yesterday' +%Y%m%d
and see how that might help you track down the correct compressed log file.

As I mentioned above, log files shouldn't be a cause for disk space problems. Unless your system is under a serious attack, the size of your log files shouldn't be excessively large. But... if disk space has become an issue, please:
Code:
df
sudo su - root -c "cd /; du -s * | sort -n
In both cases, post the results in code tags. The first command will give LQ folks a clue as to your disk/filesystem layout. The second will provide info regarding which directory tree is using the most disk space. (My guess would be NOT /var.)

Cheers...
 
Old 05-14-2021, 01:33 AM   #9
craigevil
Senior Member
 
Registered: Apr 2005
Location: OZ
Distribution: Debian Sid/RPIOS
Posts: 4,886
Blog Entries: 28

Rep: Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533Reputation: 533
Or just say the heck with log files and put them in tmpfs.

I use this in my /etc/fstab
Code:
# Added 4 lines to use RAM instead of SSD for temp and log files
tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,noatime,mode=1777 0 0
tmpfs /var/log tmpfs defaults,noatime,mode=0755 0 0
tmpfs /var/spool tmpfs defaults,noatime,mode=1777 0 0
 
Old 05-14-2021, 09:13 AM   #10
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
I'd be more concerned with your partition size personally. If it is so small that a few log files cause a problem with space then you need to fix that first. It shouldn't really be an issue on a typical system.
 
Old 05-14-2021, 09:16 AM   #11
Klen
LQ Newbie
 
Registered: May 2021
Posts: 2

Rep: Reputation: Disabled
Thanks to all for sharing the useful info
 
  


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
How to log internal-sftp chroot jailed users access log to /var/log/sftp.log file LittleMaster Linux - Server 0 09-04-2018 03:45 PM
[SOLVED] iptables troubleshooting icmp and best place to log /var/log/messages or /var/log/iptables JockVSJock Linux - Security 18 02-12-2016 12:31 AM
/var/log/messages and /var/log/cron not working sigkill Linux - Software 6 08-09-2008 01:08 PM
Can Samhain log my entries in /var/log/secure and /var/log/mesage to a central server abefroman Linux - Software 2 04-13-2008 04:13 PM
/var/log/packages and /var/log/setup sunny_5252 Slackware 4 05-17-2007 08:17 PM

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

All times are GMT -5. The time now is 07:52 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