Is it possible to preserve my open tabs between closing and opening of Nautilus file manager?

Preferably even across different logouts and restarts.

  • 1
    Related: askubuntu.com/questions/52112/…
    – Parto
    Feb 24, 2016 at 12:50
  • 1
    In one session, or after restart / logout? Feb 24, 2016 at 13:32
  • @JacobVlijm preferably even persistent across restart / logout.
    – orschiro
    Feb 24, 2016 at 13:48
  • Unless Parto's link provides a solution, nautilus' command line options / integration is quite limited. There is no option to read the currently opened directory, nor to change it from the command line. Remembering what you cannot see seems impossible to me. Within one session a trick & cheat option would be possible though. Feb 24, 2016 at 14:10
  • @JacobVlijm mind explaining how to achieve the remembering within one session? That would be already a great thing to begin with. :)
    – orschiro
    Feb 25, 2016 at 10:25

4 Answers 4


(Very) limited command line options of nautilus

Unfortunately, nautilus does not offer command line options to read the opened directory of its windows, nor does it have any option to send an existing window to another directory. Since you cannot remember what you do not see, we are running out of options at first sight.


We do have xdotool, not to do what nautilus doesn't, but to at least fake the behaviour that you describe. We can do that in such a way that "you would believe it" if you didn't know how it is done.

Although the solution below does not survive a restart, "remembering" (possibly tabbed) window and all opened directories is very well possible within one session. Since you mentioned to be interested in that as a "second choice", here it is.

How it works; the process

Although We cannot close a window and preserve its tabs and opened directories, we can make an existing window seemingly (and completely) disappear, with the help of xdotool.

If we subsequently change the behaviour of the nautilus launcher in such a way that it first looks for possible unmapped windows to remap, before opening a new one, effectively we have exactly the same behaviour as if nautilus would remember the last used window(s).

How to set up

  1. Copy the script below into an empty file, save it as remember.py

    #!/usr/bin/env python3
    import subprocess
    import os
    app = "nautilus"
    wfile = os.environ["HOME"]+"/.unmapped_"+app
    def get(cmd):
        # simply a helper function
        return subprocess.check_output(cmd).decode("utf-8").strip()
    def check_windowtype(w_id):
        # check the type of window; only unmap "NORMAL" windows
        return "_NET_WM_WINDOW_TYPE_NORMAL" in get(["xprop", "-id", w_id])
    def get_pid(app):
        # (try to) get the pid of the application 
            return get(["pgrep", app])
        except subprocess.CalledProcessError:
    def get_matches(pid):
        # get the window list, select the valid (real) app's windows
        ws = get(["wmctrl", "-lpG"]).splitlines()
        matches = [w.split() for w in ws if pid in w]
        return [w for w in matches if check_windowtype(w[0]) == True]
        # try to read the file with unmapped windows
        wininf = [l.split() for l in open(wfile).readlines()]
    except FileNotFoundError:
        # if there are no, unmap the current app's windows
        filebrowserwins = get_matches(get_pid(app))
        if filebrowserwins:
            open(wfile, "wt").write(("\n").join((" ").join(l) for l in filebrowserwins))
            for w in [w[0] for w in filebrowserwins]:
                subprocess.Popen(["xdotool", "windowunmap", w])
            arg = "--new-window" if app == "nautilus" else "" 
            subprocess.Popen([app, arg])
        # re- map unmapped windows
        for w in wininf:
            wid = w[0]; geo = w[3:7]
            subprocess.call(["xdotool", "windowmap", wid])
            subprocess.Popen(["wmctrl", "-ir", wid, "-e", "0,"+(",").join(geo)])
  2. The script needs both wmctrl and xdotool:

    sudo apt-get install wmctrl xdotool
  3. Copy the nautilus launcher from /usr/share/applications to ~/.local/share/applications

    for 15.04 and later:

    cp /usr/share/applications/org.gnome.Nautilus.desktop ~/.local/share/applications

    for earlier Ubuntu versions:

    cp /usr/share/applications/nautilus.desktop  ~/.local/share/applications
  4. open the local copy with gedit:

    gedit ~/.local/share/applications/org.gnome.Nautilus.desktop

    (in case of 15.04 +)

    and look for the first line, starting with Exec=. Change it into:

    Exec=python3 /path/to/remember.py

    Save and close the file.

  5. Create a keyboard shortcut with the same command: Choose: System Settings > "Keyboard" > "Shortcuts" > "Custom Shortcuts". Click the "+" and add the command:

    python3 /path/to/remember.py
  6. Now log out and back in

How to use

The use is very simple:

  • To open a window, do as usual: click on the nautilus launcher. Tab the window as you like:

    enter image description here

  • To close a window definitively, close it by clicking on the window's "close" (x) box.

  • To preserve the window(s) + all its tabs:
    press the shortcut key. The window(s) will vanish (seemingly close).

    enter image description here

  • Next time when you click the launcher, the nautilus window(s) will appear exactly like the last time, even the window position(s) will be preserved.

    enter image description here

That's it


  • In the tests I ran, I couldn't find any downside (14.04). If you might run into any, please mention!
  • In the How to use -section, I suggested to click on the nautilus icon to remap possible unmapped windows. The shortcut key will do the same however, so you can see what works the most convenient for you. Also, if you opened a folder by double click after you unmapped on or more folders, unmapped folders still will be remapped by the shortcut.


Nemo users

Nemo users can equally use the solution above, but:

  • In the head section of the script, change:

    app = "nautilus"


    app = "nemo"
  • In point 3, use:

    cp /usr/share/applications/nemo.desktop ~/.local/share/applications
  • In point 4, use:

    gedit ~/.local/share/applications/nemo.desktop

Tested, proved to be working with nemo

  • Great working solution and well documented. Thank you very much!
    – orschiro
    Feb 26, 2016 at 12:12
  • @orschiro always fun if it works :) You're welcome! Feb 26, 2016 at 12:13

I recommend using other file manager instead if that's okay with you since Nautilus doesn't have that feature.

Here's one alternative app that does the trick: SpaceFM

Here's how to install it.

It has rich features such as, of course, reopen last tabs.

To make it the default file manager:

xdg-mime default spacefm.desktop inode/directory


Try out these scripts to save and restore tabs of nautilus file manager. https://github.com/susurri/nautilus_save_tabs/


The easiest way to access folders is bookmarking. You wont keep your tabs open but you can at least see the folders you want quickly (and if you think about it, the bookmarks act as tabs).

Just open a folder on Nautilus, go to Bookmark menu and add a bookmark.

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.