Sort Directories First in Gnome (GTK)
The Issue
I am using Pop_OS! for my system and the default behavior of the file explorer Nautilus is to sort everything by name, regardless of it being a file or a folder. I grew up with Windows and became very accustomed to the fact that folders are always sorted first, then all files are sorted below that, both by name.
The Solution (I Thought)
The simplest way to change that in Pop_OS! (22.04 with Gnome 42.9) is to go into the preferences menu of Nautilus and activate the setting Sort Folders Before Files
. But some apps (in my case Chromium) didn’t seem to respect that setting when it comes to the regular “Open File” dialogue. It turns out there is one more setting I had to change.
The Actual Solution
With Gnome installed you should have access to the gsettings
command, which is the administration command for all the different Gnome settings. You can list all the existing settings with gsettings list-recursively
. The setting we are looking for is called org.gtk.Settings.FileChooser sort-directories-first
, which is either set to true or false. That is the setting we can change directly from Nautilus. But there is a second entry for that setting called org.gtk.gtk4.Settings.FileChooser sort-directories-first
and that is what Chromium is apparently using.
As an alternative to this solution you can also install dconf-editor (sudo apt install dconf-editor
), navigate to org.gtk.gtk4.settings.file-chooser
and set the sort-directories-first setting to true
there. But it’s possible to set it on the terminal too, if you prefer not to install a program for editing settings.
Depending on your system and your version of Gnome, you might have the second entry with gtk3
instead of gtk4
, but we can easily check that with the following command:
gsettings list-recursively | grep sort-directories-first
That will list all settings with sort-directories-first
, so in the next step we can change all of them to true
.
In my case, the output of the above command was
org.gtk.Settings.FileChooser sort-directories-first true
org.gtk.gtk4.Settings.FileChooser sort-directories-first false
I could then set the gtk4
setting to true
with the following command:
gsettings set org.gtk.gtk4.Settings.FileChooser sort-directories-first true
After that, all apps using the gtk4
setting specifically should also sort all directories before all files. It even works right away, no new session or restart required, close and reopen the file dialogue if you have one open.
And that’s it. Finally there is an end to scrolling down to the files and not finding it only because it begins with “A” and was above all the folders.