How do I remove some sessions from the session list in Xubuntu

When logging in to Xubuntu, I get a selection list of saved sessions, most of them is outdated old stuff.

I hit the delete button in a sportive manner. I tried a click to the left, and just a click to the right - no deletion possible.

I went through system menus and menu sections (and the system section of the menu).

Note: Not related: How to remove session entries from LightDM? or Managing the login screen's sessions list which links to it - they handle session-classes like xubuntu vs. xfce, gnome, kde - not different xfce-sessions.

Note: I want to remove some sessions, not all of them. I don't want to start with the session-list deactivated. I have 5 entries and want to remove 3 of them.


Solution 1:

Go to $HOME/.cache/sessions and open the latest file with the name xfce-session-yourdesktopname in a text editor.

All your sessions are listed in the file by name in this format:

[Session: Default] 

or

[Session:somename]

Select the entire set of lines from [Session:somename] to the next blank line (including the [Session:somename] line and delete them. Save the file.

Solution 2:

Sagarchalise brought me on the right track, but only half the way.

The place, where to look in Xfce is indeed

$HOME/.cache/sessions

I found a lot of files there, including some empty Thunar- files, xfwm4- files and, interesting for us, xfce4-session-asux:0, where asux is the name of my local machine, the hostname.

:0 reminds of the way, the XServer enumerates different instances, which I used rarely, but I used it, so I have a xfce4-session-asux:1 file as well, and it is rather old, but different sessions aren't stored in different files, but in different sections inside the file.

Such a section looks like this:

[Session: 2010]
key1=value1
key2=value2
...
LastAccess=1315125649

So you can see the name ("2010" in this case) of the session, a bunch of key-value-pairs, and as last these pairs a LastAccess key. It stores the seconds since 1.1.1970 UTC. It's not short and easy to translate it to a human readable date with date or bash arithmetic (or tell me how in the comments). But at least the age in years is worth calculating:

echo $((1315125649/(365*24*60*60)))
41

So it is 41 years after 1.1.1970 (ignoring leap years and daylight saving time, and cutting the result to whole years) which is 2011. The other fields can be computed as well - I prefered to do it with scala by

scala> val d = new java.util.Date (1315125649*1000L)
d: java.util.Date = Sun Sep 04 10:40:49 CEST 2011

So I remove the whole section, and after relogin, this session is vanished from my list of sessions.

update:

I now know the much simpler solution for the date issue, simply put into the shell:

date -d @1315125649
So 4. Sep 10:40:49 CEST 2011

So this can be made into a simple script:

for f in  ~/.cache/sessions/xfce4-session-* 
do
   la=$(sed -n -r 's/LastAccess=(.*)/\1/p' "$f")
   echo -e $(date -d @$la) "\t$f"
done 

Fr 9. Mär 07:17:13 CET 2018     /home/stefan/.cache/sessions/xfce4-session-tux201t:0
Fr 9. Mär 07:16:03 CET 2018     /home/stefan/.cache/sessions/xfce4-session-tux201t:0.bak