Default File Manager in Gnome

Introduction

The default file manager in Ubuntu is Nautilus. Some people prefer other file managers. Unfortunately, it's difficult to make other file managers the default, especially since Nautilus manages the desktop icons in Gnome (Ubuntu's desktop environment).

Disclaimer

The first version of this script has been written by a non-programmer. It has been tested and works but, as you can see from the comments in the script, it could still be tweaked to be "better". The "Manual Method", below, actually has fewer steps and used no imported bash scripts, but possibly might not work for all cases. There are a lot of file managers.

Script to change Thunar to be the default file manager

To run this script, paste this block of code into a text file and save it as a file named defaultthunar in your home folder.

   1 #!/bin/bash
   2 
   3 ## Originally written by aysiu from the Ubuntu Forums
   4 ## This is GPL'ed code
   5 ## So improve it and re-release it
   6 
   7 ## Define portion to make Thunar the default if that appears to be the appropriate action
   8 makethunardefault()
   9 {
  10 ## I went with --no-install-recommends because
  11 ## I didn't want to bring in a whole lot of junk,
  12 ## and Jaunty installs recommended packages by default.
  13 echo -e "\nMaking sure Thunar is installed\n"
  14 sudo apt-get update && sudo apt-get install thunar --no-install-recommends
  15 
  16 ## Does it make sense to change to the directory?
  17 ## Or should all the individual commands just reference the full path?
  18 echo -e "\nChanging to application launcher directory\n"
  19 cd /usr/share/applications
  20 echo -e "\nMaking backup directory\n"
  21 
  22 ## Does it make sense to create an entire backup directory?
  23 ## Should each file just be backed up in place?
  24 sudo mkdir nonautilusplease
  25 echo -e "\nModifying folder handler launcher\n"
  26 sudo cp nautilus-folder-handler.desktop nonautilusplease/
  27 
  28 ## Here I'm using two separate sed commands
  29 ## Is there a way to string them together to have one
  30 ## sed command make two replacements in a single file?
  31 sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-folder-handler.desktop
  32 sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-folder-handler.desktop
  33 echo -e "\nModifying browser launcher\n"
  34 sudo cp nautilus-browser.desktop nonautilusplease/
  35 sudo sed -i -n 's/nautilus --no-desktop --browser/thunar/g' nautilus-browser.desktop
  36 sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-browser.desktop
  37 echo -e "\nModifying computer icon launcher\n"
  38 sudo cp nautilus-computer.desktop nonautilusplease/
  39 sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-computer.desktop
  40 sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-computer.desktop
  41 echo -e "\nModifying home icon launcher\n"
  42 sudo cp nautilus-home.desktop nonautilusplease/
  43 sudo sed -i -n 's/nautilus --no-desktop/thunar/g' nautilus-home.desktop
  44 sudo sed -i -n 's/TryExec=nautilus/TryExec=thunar/g' nautilus-home.desktop
  45 echo -e "\nModifying general Nautilus launcher\n"
  46 sudo cp nautilus.desktop nonautilusplease/
  47 sudo sed -i -n 's/Exec=nautilus/Exec=thunar/g' nautilus.desktop
  48 
  49 ## This last bit I'm not sure should be included
  50 ## See, the only thing that doesn't change to the
  51 ## new Thunar default is clicking the files on the desktop,
  52 ## because Nautilus is managing the desktop (so technically
  53 ## it's not launching a new process when you double-click
  54 ## an icon there).
  55 ## So this kills the desktop management of icons completely
  56 ## Making the desktop pretty useless... would it be better
  57 ## to keep Nautilus there instead of nothing? Or go so far
  58 ## as to have Xfce manage the desktop in Gnome?
  59 echo -e "\nChanging base Nautilus launcher\n"
  60 sudo dpkg-divert --divert /usr/bin/nautilus.old --rename /usr/bin/nautilus && sudo ln -s /usr/bin/thunar /usr/bin/nautilus
  61 echo -e "\nRemoving Nautilus as desktop manager\n"
  62 killall nautilus
  63 echo -e "\nThunar is now the default file manager. To return Nautilus to the default, run this script again.\n"
  64 }
  65 
  66 restorenautilusdefault()
  67 {
  68 echo -e "\nChanging to application launcher directory\n"
  69 cd /usr/share/applications
  70 echo -e "\nRestoring backup files\n"
  71 sudo cp nonautilusplease/nautilus-folder-handler.desktop .
  72 sudo cp nonautilusplease/nautilus-browser.desktop .
  73 sudo cp nonautilusplease/nautilus-computer.desktop .
  74 sudo cp nonautilusplease/nautilus-home.desktop .
  75 sudo cp nonautilusplease/nautilus.desktop .
  76 echo -e "\nRemoving backup folder\n"
  77 sudo rm -r nonautilusplease
  78 echo -e "\nRestoring Nautilus launcher\n"
  79 sudo rm /usr/bin/nautilus && sudo dpkg-divert --rename --remove /usr/bin/nautilus
  80 echo -e "\nMaking Nautilus manage the desktop again\n"
  81 nautilus --no-default-window &
  82 
  83 ## The only change that isn't undone is the installation of Thunar
  84 ## Should Thunar be removed? Or just kept in?
  85 ## Don't want to load the script with too many questions?
  86 }
  87 
  88 
  89 
  90 ## Make sure that we exit if any commands do not complete successfully.
  91 ## Thanks to nanotube for this little snippet of code from the early
  92 ## versions of UbuntuZilla
  93 set -o errexit
  94 trap 'echo "Previous command did not complete successfully. Exiting."' ERR
  95 
  96 
  97 ## This is the main code
  98 ## Is it necessary to put an elseif in here? Or is
  99 ## redundant, since the directory pretty much
 100 ## either exists or it doesn't?
 101 ## Is there a better way to keep track of whether
 102 ## the script has been run before?
 103 if [[ -e /usr/share/applications/nonautilusplease ]]; then
 104 
 105 restorenautilusdefault
 106 
 107 else
 108 
 109 makethunardefault
 110 
 111 fi;
 112 

Then paste these commands into the terminal

chmod +x defaultthunar
./defaultthunar

Restoring Nautilus as a default

Just run the script again

./defaultthunar

Script to change Dolphin to be the default file manager

To do later when the Thunar script has been improved upon

Alternative method

Same thing can be done adding the new .desktop files to ~/.local/share/applications/ instead of modifying the installation files in /usr/share/applications.

Using Midnight Commander

First copy this script to /usr/local/bin/mcterm

   1 #!/usr/bin/env python
   2 # mcterm 1.0
   3 # Daniel Gonzalez Gasull <daniel@djansoft.com>
   4 # License: GPL
   5 #
   6 # Handles packages with Midnight Commander.
   7 # Opens a gnome-terminal with Midnight Commander in it.
   8 # mcterm can be used inside Firefox in Edit -> Preferences -> Aplications
   9 # with zip files, bz2 files, rar files and 7z files.
  10 import os
  11 import subprocess
  12 import sys
  13 
  14 
  15 def main():
  16     if len(sys.argv) > 1:
  17         filename = sys.argv[1]
  18         file_output, dummy = subprocess.Popen('/usr/bin/file -b %s' % filename,
  19                 shell=True, stdout=subprocess.PIPE).communicate()
  20         filetype = file_output.strip().split()[0]
  21         # switch statement
  22         try:
  23             dirname = {
  24                     'Zip': lambda: '%s#uzip' % filename,
  25                     'gzip': lambda: '%s#utar' % filename,
  26                     '7-zip': lambda: '%s#u7z' % filename,
  27                     'RAR': lambda: '%s#urar' % filename,
  28                     'bzip2': lambda: '%s#utar' % filename,
  29                     }[filetype]()
  30         except KeyError:
  31             dirname = filename
  32     else:
  33         dirname = ''
  34     os.system('gnome-terminal --hide-menubar -x mc -s %s' % dirname)
  35 
  36 
  37 if __name__ == "__main__":
  38     main()
  39 

Give yourself permission to execute the script:

sudo chmod 755 /usr/local/bin/mcterm

Now copy this file to ~/.local/share/applications/nautilus-browser.desktop

[Desktop Entry]
Encoding=UTF-8
Name=File Browser
Comment=Browse the file system with the file manager
TryExec=mcterm
Exec=mcterm %U
Icon=system-file-manager
Terminal=false
StartupNotify=true
Type=Application
NoDisplay=true
Categories=GNOME;GTK;System;Utility;Core;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=2.28.1
X-Ubuntu-Gettext-Domain=nautilus

This other file to ~/.local/share/applications/nautilus-folder-handler.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Open Folder
TryExec=mcterm
Exec=mcterm %U
NoDisplay=true
Terminal=false
Icon=folder-open
StartupNotify=true
Type=Application
MimeType=x-directory/gnome-default-handler;x-directory/normal;inode/directory;application/x-gnome-saved-search;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=2.28.1
X-Ubuntu-Gettext-Domain=nautilus

And this last file to ~/.local/share/applications/nautilus-home.desktop:

[Desktop Entry]
Encoding=UTF-8
Name=Home Folder
Comment=Open your personal folder
TryExec=mcterm
Exec=mcterm
Icon=user-home
Terminal=false
StartupNotify=true
Type=Application
Categories=GNOME;GTK;Core;
OnlyShowIn=GNOME;
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=nautilus
X-GNOME-Bugzilla-Component=general
X-Ubuntu-Gettext-Domain=nautilus

Manual Method

Introduction

While many of you may be comfortable with just running the script above to fix your problem (I don't know if it works because I haven't tried it), others might want to know what needs to be done to solve it so that when they understand they can apply the solution to their specific need.

For example, I'm not using GNOME at all, I'm using Openbox and AWN but GNOME and all it's components are still installed so when I use applets in the Dock they open Nautilus where I'd rather have them use Thunar or Xfe. It's unlikely (although possible) that someone has the exact same setup as me but with this explanation hopefully you'll be able to solve your problem.

IconsPage/note.pngTo follow along you can use either the command-line or a graphical interface.

I like using the Terminal and the editor Vim to manipulate files but you might prefer to use the file browser Nautilus and the editor Gedit.

MIME Types

A quick word on MIME/Content Types because they're relevant. You can read more about about them at Wikipedia but basically they define what type of file a file is. There is a directory /usr/share/applications that contains a whole load of .desktop files; "shortcuts" to programs. If you copied one of them to your desktop you could double-click it to start the program. In the same directory is a file defaults.list, which lists which of those programs to use (via their shortcut) for every MIME Type or type of file. That's how Ubuntu knows which program to use to open a file when you double-click the file's icon. It also has Types for browsing directories, which is what we're interested in right now.

There's a similar file mimeapps.list in ~/.local/share/applications. See below for a way to change just that file for a single user change, rather than a multi-user change for all users on the system.

Changing Your Default File Manager

This is the recommended method because it doesn't mess around with the files that were installed by your package manager. Also, if it is a shared computer (eg. family, library or lab computer) then this method is your only option.

Default system settings in Ubuntu are overridden by settings in hidden files in a user's home directory (~), if you want to change settings, this is the place to do it. The files in ~/.local/share/applications override the files in /usr/share/applications (mentioned above in MIME Types). If the directory does not exist, create it. To change the default File Manager you'll have to edit the file defaults.list (or mimeapps.list) found in this directory but first we have to find the right .desktop file for the program you want to use.

getting the right .desktop file

You have read-access to /usr/share/applications so navigate to that directory and search through the .desktop files to find the one for your desired File Manager, for example the one for Xfe is xfe.desktop.

To search for files in Nautilus start typing the name of the file. To search for files from the command line you can list the contents of the directory and search the output for the name of the file:

ls /usr/share/applications | grep xfe

If you find it you can move on to the next step, otherwise, if it doesn't exist we'll have to create one. As far as I know there is no .desktop file for Thunar so we'll make one for that. Navigate to ~/.local/share/applications, make a file thunar.desktop and write the following in it:

[Desktop Entry]
Name=Open Folder
TryExec=thunar
Exec=thunar %U
NoDisplay=true
Terminal=false
Icon=folder-open
StartupNotify=true
Type=Application
MimeType=x-directory/gnome-default-handler;x-directory/normal;inode/directory;application/x-gnome-saved-search;

There are lots of other things you can add if you want to but this should be enough. If you're making a file for another file manager replace the command thunar at Exec and TryExec to the command for your file manager and name it whateverfilemaneger.desktop.

Just to remind you one last time this file is in sub-directory of your home directory (~), not somewhere in /usr!

editing the defaults.list or mimeapps.list file

If you're not in the directory ~/.local/share/applications then navigate to it now and edit the defaults.list file. You can double-click it in Nautilus to open it with Gedit or from the commandline:

editor defaults.list

It shouldn't contain much because it's only for the MIME Types which you're overriding. Add the following 2 lines to the file:

inode/directory=thunar.desktop
x-directory/normal=thunar.desktop

Replace thunar.desktop with whateverfilemaneger.desktop according to the file you found/created in the previous step.

And that should take care of it. No need to reboot, changes should take effect immediately!

Using the above Manual Method on Ubuntu Raring (13.04) to Use the nemo file manager:

Install the nemo file managerand give it a spin. I installed nemo using these instructions. See if you like it.

In ~/.local/share/applications, Ubuntu raring has mimeapps.list:

  1. Create nemo.desktop, similar to the above thunar.desktop.

    1. Use a text editor to change both exec mentions of 'thunar' to be 'nemo', without the quotes.
  2. Open mimeapps.list (instead of 'defaults.list') and add those 2 lines on to the end of the file. With 'thunar.desktop' changed to 'nemo.desktop', of course.

This works. So far, it works perfectly and immediately.

Changing the System-wide Default File Manager

IconsPage/warning.png This method is not recommended because it requires root access!!!

If you are the system administrator and you want to change the default file manager for all users of the system then follow this method otherwise it's recommended you follow the method above which will change your default file manager without affecting the rest of the system.

The method for this is the same as the previous method except that files are created/modified in the /usr/share/applications directory (requires root access privileges for write-access) instead of in `~/.local/share/applications/ (in your home directory where you yourself have read/write access).

By default you can not login as root in Ubuntu (because it's considered dangerous) so use the sudo command to gain root privelages:

sudo -i

It will prompt you for your password before allowing you access. Now you can navigate to the applications directory:

cd /usr/share/applications

edit the defaults list to include the 2 lines shown in the previous method:

editor defaults.list

and if necessary create a .desktop file for your file manager:

editor yourfilemanager.desktop

with the contents shown in the previous method.

If you're not comfortable with using the terminal you can do this using Nautilus too. To gain root access type (either in a terminal or in the run dialogue Alt+F2):

gksu nautilus

Type your password and you can perform the above tasks using mouse-clicks and the gedit file editor.

One more way - for "mousemonkeys", like me

Just do in terminal

exo-preferred-applications

then switch to Utilities tab and select File Manager you prefer. And that's all!


CategoryThirdPartySoftware CategorySoftwareDefault

DefaultFileManager (last edited 2013-12-13 21:04:35 by knome)