On most Linux boxes, dbus-cleanup-sockets has nothing to do, and knowing why is more useful than running it. The command hunts for filesystem-backed D-Bus connection sockets left behind by a program that exited without closing its bus connection.
Allow about ten minutes. You need a shell and the dbus-bin package. The examples use the Ubuntu Noble package version 1.14.10-4ubuntu4.1. Run the checks as your ordinary user first. This guide does not use sudo, delete arbitrary files, restart D-Bus or change a service.
Start by checking that the command resolves to the packaged binary. This is read-only and needs no elevated privileges:
$ command -v dbus-cleanup-sockets
/usr/bin/dbus-cleanup-sockets
$ dpkg-query -W -f='${Package} ${Version}\n' dbus-bin
dbus-bin 1.14.10-4ubuntu4.1
$ /usr/bin/dbus-cleanup-sockets --version
D-Bus Socket Cleanup Utility 1.14.10
Use the absolute path when reproducing the result on a host where another D-Bus installation may appear earlier in PATH. A locally installed copy can have a different version and output.
Checkpoint: you have identified the executable and recorded its version before deciding whether to automate it.
The utility looks for unused, filesystem-backed D-Bus connection sockets. A socket can be left behind when a program exits abnormally without closing its D-Bus connection. The manpage describes the optional argument as a directory and gives /tmp as the usual default:
$ /usr/bin/dbus-cleanup-sockets --help
dbus-cleanup-sockets [--version] [--help] <socketdir>
That description does not mean every Unix socket in the directory is disposable. The command targets D-Bus socket names it recognises. Ordinary files, unrelated sockets and active D-Bus connections must not be treated as cleanup targets.
Linux changes the practical answer here. The default D-Bus session bus usually runs on an abstract socket, so ls /tmp will not show the connection and this utility cannot remove it. A successful run on a Linux host that reports zero cleaned sockets is not a failure, it is the expected result.
Run the packaged command with no argument to inspect the standard per-user session-bus directory. It can remove recognised stale entries, so read the output before using it on a shared or busy machine:
$ /usr/bin/dbus-cleanup-sockets
Cleaned up 0 sockets in /tmp; 0 sockets are still in use; 0 in unknown state
The exact counts depend on the host. "Still in use" means the utility found a socket that accepted a connection check, so it left it alone. "Unknown state" means it could not establish a safe classification. Neither count is a reason to delete the path by hand.
Do not run this from a root shell merely because /tmp is involved. The default session-bus directory belongs to the user session, and elevated execution can change which environment and bus you are examining.
A stale socket is usually harmless clutter, but a mistaken cleanup command can disrupt a program that is still using a filesystem socket. Before running it in a production job, identify the owning user and confirm the host actually uses filesystem-backed D-Bus sockets. Check the directory without changing it:
$ find /tmp -maxdepth 1 -type s -printf '%p\n' 2>/dev/null
$ ss -xl | sed -n '1,20p'
The first command lists Unix socket files visible in /tmp. The second shows listening Unix sockets known to the kernel. The two views are not identical, and an empty first result is normal on Linux. Stop if the directory contains a live application socket whose ownership or purpose you cannot explain.
Warning: do not replace this utility with find /tmp -type s -delete. That would remove sockets without checking whether they are active, and it could break unrelated services. There is no general undo for an unlinked socket; the affected service may need to recreate it or be restarted.
The documented form accepts an optional directory:
$ /usr/bin/dbus-cleanup-sockets /path/to/the/socket-directory
Replace the placeholder with a directory you have inspected and whose D-Bus socket ownership is understood. Do not paste a path supplied by an untrusted user. Quote paths containing spaces, and do not add sudo unless the directory's permissions genuinely require it and you have confirmed the files belong to the system service you intend to maintain.
There is a version-specific trap on this machine: the installed 1.14.10 binary's diagnostic still referred to /tmp when given an arbitrary test path. That is not evidence the requested directory was cleaned. Treat the output path and counts as verification data. If they do not name the directory you supplied, stop and do not schedule the command. Check the binary, package version and vendor updates before relying on its optional argument.
Checkpoint: only automate an explicit path after a harmless test on the exact host and binary shows the intended directory in the result.
For a one-off maintenance check, retain the output and status:
$ /usr/bin/dbus-cleanup-sockets 2>cleanup-errors.log
$ status=$?
$ printf 'cleanup exit status: %s\n' "$status"
cleanup exit status: 0
Status 0 means the utility completed its scan. It does not mean a socket was removed, that every entry was classifiable, or that D-Bus is healthy. A non-zero status or a warning in the output needs investigation before a retry. Keep the log if this runs under a maintenance account, but avoid recording unrelated contents of /tmp.
If a service lost its connection after a cleanup, stop repeating the command. Restore the service's normal socket by restarting that service through its documented systemd unit or service procedure, then investigate why the socket was classified incorrectly. Do not restart the whole D-Bus system bus as a first response.
/tmp.find ... -delete replacement.