How to prevent gettin lots of .serverauth.$$ files in the HOME directory on OS X 10.8?

($$ is a pid number).


You can prevent these from accumulating if you always exit the X11 server gracefully. That means logging out gracefully and shutting down gracefully. No way you can always do that though, so about all you can do is delete these every now and then. You could write a script to find and remove the ones not in use and run it manually or schedule it to run routinely via cron. Below is an example script:

cd || {
  echo "Unable to cd to home." >&2
  exit 1
Candidates=$(echo .serverauth.*)
if [ -z "$Candidates" ];then
for Candidate in $Candidates ; do
  kill -0 $Candidate 2>&-
  if [ $? != 0 ];then # The PID is not currently active
    printf "Removing orphaned xserverauth file \"$Candidate\".\n";
    rm $Candidate || {
      printf "Failed to remove file \"$Candidate\".\n" >&2.

In Terminal:

rm .serverauth.*

Or, if you want to remove from every home dir:

sudo rm /Users/*/.serverauth.*
  • Sorry if I wasn't clear... I need to prevent these from reappearing there, anyone know how to delete files. – sorin Jul 21 '13 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .