16

New versions of Nautilus are cool, because they skip nonalphanumeric letters at the beginning of any file name and sort files according to the first alphanumeric letter (if any). But how to name a file in order to sort it before 0? Assume I have a folder with these files:

0apple.conf
apricot.xml
banana
camel.so
cat.py
dog.tar.bz

and I want to add a one or two letter prefix to the cat.py in order to sort it before 0apple.conf file. I don't want to change the name, just add a prefix. I also don't want to change others' names. I've already tried:

  1. #cat.py and .cat.py names and Greek alphabet prefixes sort file to the end (after dog.tar.bz file; . changes also visibility)
  2. any of ,-";:-–\_(?)*+%=<>! prefixes sorts the file between camel.so and dog.tar.bz (like without any prefix).

Yes, there is an option to add more zeros to be near the beginning, but I want the file name as shortest as possible and at the very first position.

PS: My language is czech (therefore the collation should be something like cs, cz, czech or cs_CZ).

7
+50

The prefix 0 already makes the file to be sorted at very first in Nautilus. What can come before the very first file? No files could, except directories. This is true regardless of locale in use.

File naming

In the following example, I first created an empty text file named apple.txt then made multiple copies and rename each of the files by adding single character prefix. I have used only most compatible alphanumeric characters: 0 A á _ - and (space). This means I have created 7 files in total, plus a directory named apple for reference.

Note that á is the second letter of Czech, which is found in this article section on Wikipedia. The first letter seems to be same as English: A and a.

File sorting

How will Nautilus sort these files in different locale environment? Turns out that it is similar but slightly different. See the following screenshot for comparison.

Nautilus in English and Czech environment

Nautilus sorted files in English environment en_US.UTF-8 like this:

apple <-- directory
0apple.txt
Aapple.txt
áapple.txt
apple.txt <-- original file without prefix
 apple.txt
_apple.txt
-apple.txt

Nautilus sorted files in Czech environment cs_CZ.UTF-8 like this:

apple <-- directory
0apple.txt
Aapple.txt
áapple.txt
 apple.txt
apple.txt <-- original file without prefix
-apple.txt
_apple.txt

In both locales, there is no change in order of directory and top 3 files when viewing as list in Nautilus. This already shows that no alphanumeric character can appear before 0apple.txt.

Workaround 1

One way is to create files with name other than existing "apple" with same prefix 0 that precedes the existing one. Creating 0aaa.txt will come before 0apple.txt and so forth.

Using this workaround, the files are sorted like this:

0.txt
0a.txt
0aaa.txt
0apple.txt
...

This way, the file 0.txt would be the very first file to appear in Nautilus. No other files can come before 0.txt, unless user want to create a file name .txt (using only a space character).

Workaround 2

Say if apple is already the very first file that can exist and user insists to not rename apple, there is another way: Rename the existing file with higher number prefix from 0apple.txt to 9apple.txt. This will allow other files with lower number prefix 0* to 8* to appear before 9apple.txt.

Using this workaround, the files are sorted like this:

0mango.txt
1kiwi.txt
2orange.txt
...
9apple.txt
...

Workaround 2 is unsuitable, if the 0apple.txt as whole cannot be renamed for whatever reason. Workaround 1 will be more effective since 0.txt will always appear before 0mango.txt or other file names that user can think of.

How did I test

In my testing, only essential locale packages were installed to prepare Czech environment for running Nautilus in Ubuntu. The quick way to run program in other locale by LANG=<LOCALENAME> nautilus command didn't work. Hence, the following steps.

  • Install these packages language-pack-gnome-cs language-pack-gnome-cs-base language-pack-cs language-pack-cs-base via APT in Terminal

  • Go to System Settings > Language and Support

  • In Language - Language for menus and windows, drag the entry named čeština (word for "Czech" noted by Wikipedia) to above English

  • Log out and log in again to take effect

Tested using Nautilus 3.14.3 in Ubuntu 16.04 LTS (Live).

TL;DR Filename with prefix 0 makes the very first file in Nautilus. No other files, except directories can appear before the very first file.

  • Regarding Nautilus sorting behaviour insanity and disrespect against environmental variable, refer to this older post. – clearkimura Jun 29 '16 at 10:33
  • 1
    As a native Czech person, I must correct you: Á or á is the second letter in the Czech alphabet after A or a. Look at the left column in the linked Wikipedia table. The right column is spelling of the letter in the left column. – Melebius Jun 29 '16 at 10:35
  • @Melebius Corrected accordingly. My bad, I had misread in "Name" column instead of "Letter" in the table. – clearkimura Jun 29 '16 at 10:42
  • Another minor thing is that Á or á is not the same as A or a. But you answerred most of my question, thanks – aleskva Jun 29 '16 at 12:26
  • I intended to use a letter from Czech that may supercede typical roman letters or even numbers, but I misread the table on Wikipedia. I'm ashamed of my silly mistake... I haven't tried with other locale, though. – clearkimura Jun 29 '16 at 17:22
2

Have you tried space zero as a prefix?

[ 0cat.py]

The other characters you mentioned does not work for me too but space zero works fine.

You can also try other combinations of spacial chars and zero, things like: -0cat.pay, _0cat.py, etc. these should work too.

  • Cool, but is this good if I want to operate with that file using terminal? – aleskva Jun 25 '16 at 19:57
  • I think I should encode the filename and the autocomplete wouldn't work, which is not so convenient. – aleskva Jun 25 '16 at 19:59
  • I also can not rename any file to this name in Nautilus (I can do this only with terminal), which is also not so convenient. – aleskva Jun 25 '16 at 20:02
  • 2
    Try another combination of spacial chars and zero, something like -0cat.py or !0cat.py or anything else, these should work too. I edited my answer. – Ravexina Jun 25 '16 at 21:20
  • For me not, 00apple.conf is still before -0cat.py :/ – aleskva Jun 26 '16 at 7:32
0

I have success with naming files using the prefix aa. Say the original file name is info.txt - the name would be aa.info.txt. One could extend this with "aaa." or "bb." etc. I would avoid special characters and spaces, some of which could make composition of scripts undully complicated.

  • This does not answer the OP's question. – edwinksl Jun 28 '16 at 22:50
  • How about, referring to his exampe, aa.00apple.conf? – Roger Jun 28 '16 at 23:40
  • What about 000apple.conf ? – userDepth Jun 29 '16 at 0:51
  • The bad thing is 00apple is after 0apple and if you add another zeros, you are not at the beginning – aleskva Jun 29 '16 at 0:57

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.