My .xsession-errors file is growing steadily (which is apparently a common phenomenon) and not unexpected (I still have to address some issues on my system).

Question: Is there a specific threshold when the system saves .xsession-errors as .xsession-errors.old and starts a new file? And if there is some kind of logrotate for it, can this limit be changed and how?

.xsession-errors has now the size of about 1.2 GB and I think this should be enough.

Thanks for your advice!

  • 1
    I don't think that it's ever turned into an ~/.xsession-errors.old. Try adding a /etc/X11/Xsession.d/10trim-xsession-errors file with this content: err=$HOME/.xsession-errors; tail -n2000 "$err" > "$err.new" && mv "$err.new" "$err" && exec >>"$err" 2>&1. Adjust the 2000 to how many lines you want to keep from the output from the old sessions and the stuff run in this session before that script. Not giving you a complete answer because I'm using a highly modified X11 setup, and I have very little love for those initialization scripts ;-) – mosvy Feb 5 at 19:16
  • That would probably also works if added to the per-user ~/.xsessionrc; just try this first. – mosvy Feb 5 at 19:21
  • Thanks, @mosvy, I created the aforementioned file with said content and adjusted the -n to 1000000 (the current .xsession-errors has 6652785 lines and is still adding). However, I am not sure how your suggestion works, I don't see any difference. – it's not a bug- it's a feature Feb 6 at 10:39
  • Try with something small like 25 lines, and login & out a couple of times to check if it really works ;-) – mosvy Feb 6 at 10:41
  • 1
    Create an ~/old-sessions directory, and from an Xsession.d startup script or ~/.xsessionrc, run mv "$HOME/.xsession-errors" "$HOME/old-xsessions/$(date +%Y%m%d%H%M%S)" instead of truncating it. – mosvy Feb 18 at 20:20

GG, look in /etc/logrotate.d there may be a logrotate file doing the work and then you can manipulate the number of days and file size to rotate and many other things.

File name probably called xsession or similar. Let us know what you find in /etc/logrotate.d

Added after Edit

If you find nothing you could create a new logrotate

You can add a file to create a new logrotate in /etc/logrotate.d Here is something I have used variations of many times. copy this to /etc/logrotate.d/xsessionerrors (new file)

#Rotates "$HOME/.xsession-errors" daily if not empty AND over 20M. 
#Creates a file as root and compresses it with gz 
#only saves 5 copies or previous day of logs. 
$HOME/.xsession-errors {
size 20M 
create 0600 root root 
rotate 5

Logrotate has many variables but this will get you going with some obvious settings you can tweek.

| improve this answer | |
  • I cannot comment on others posts yet due to rating. – Mark Stewart Feb 5 at 0:34
  • Thanks, @Mark Stewart, logrotate is installed and apparently works fine with syslog and other logs; however, .xsession-errors does not seem to be covered by it. /etc/logrotate.d/ contains only files for alternatives, apt, aptitude, btmp, cups-daemon, dpkg, ppp, rsyslog, speech-dispatcher, unattended-upgrades as well as wtmp. – it's not a bug- it's a feature Feb 5 at 2:17
  • I tried to upvote your answer, but got the message Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score. Sorry about that! -- EDIT: Now it worked! – it's not a bug- it's a feature Feb 5 at 2:21
  • 1
    you may have special characters in the file. Logrotate will not work with CRLF or other special characters. Did you edit this file in VIM (any linux command line editor) or a Windows app? Try dos2unix -b /etc/logrotate.d/xsession-errors to strip the special chars. – Mark Stewart Feb 19 at 12:48
  • 1
    Yes, that was it! I had used a plain text editor (KWrite or Kate) and saved it now via nano. Despite the identical content the filesize was reduced by 5 bytes (I wonder why exactly 5 bytes as the file has 7 lines). Anyway, everything works fine now, thanks a lot! – it's not a bug- it's a feature Feb 19 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.