Previous part: Linux Mint tutorial part 5 - Linux applications.
Following is a list of issues that I have encountered, that will probably be solved in feature updates.
Contents
- Nemo
- ext4 file system - free ext4 reserved blocks using tune2fs
- Nvidia: no resume from sleep black screen
- Linux custom sorting order in file manager
Nemo
I had issues with nemo-share plugin that is used to share folders over SMB withing the Nemo file manager. While browsing local folders sometimes there was a considerable delay of ~5 seconds until the folder content was listed. The debugging revealed that the issue is related with Samba share. Can't remember the error message but probably was do to a misconfiguration and that the drive was NTFS.
To debug Nemo start it from the terminal:
nemo -q
followed by
NEMO_DEBUG=Application NEMO_BENCHMARK_LOADING=1 nemo --debug
ext4 file system - free ext4 reserved blocks using tune2fs
As a security measure the ext3 and ext4 file system reserves 5% of device space for administrative processes. This protects the system by allowing root processes to continue using the disk if a user process runs wild and fills it up. With today’s larger disk capacities, 5% equates into gigabytes of arguably wasted space. Thankfully with the tune2fs command you can reduce this percentage and free most if not all of the reserved space.
You can run tune2fs on the ext4 partition with the ‘-l‘ option to show all the filesystem details. The important information are the “Reserved block count” and “Block size” lines. Multiply these together to see how many bytes are currently reserved on the filesystem.
sudo tune2fs -l /dev/sda1
Replace /dev/sda1 with your drive location. In my case for the system
drive the Reserved block count was 1443187 and Block size 4096 which equals
5911293952 bytes that is 5.9 Gigabytes. Total partition size is 118 GB, so the
5.9 GB represents 5% of reserved space.
The reserved space can be reduced or set to 0. I don't recommend that for the
partition where the operating system is installed. I set the reserved space to
0 only on backup partitions.
To see the current used space run the df command:
df -h
To change the reserved block percentage run the tune2fs command with
the ‘-m‘ option that sets the new reserved percentage.
sudo tune2fs -m 0 /dev/sda1
In this example I am setting the percentage to 0 and completely removing the
reserved space. This will effectively disable the security feature but free
the most space. You may choose to reduce the reserved percentage instead in
order to preserve the security benefit while still freeing some space.
Source:
https://wiredrevolution.com/system-administration/free-ext3-reserved-blocks-with-tune2fs.
Nvidia: no resume from sleep black screen
You need to add a line in the following file:
sudo nano /usr/bin/nvidia-sleep.sh
Then under this lines:
if [ ! -f /proc/driver/nvidia/suspend ]; then
exit
0
fi
Add:
exit 0
Then press CTRL + S to save and CTRL + X to exit the editor.
Linux custom sorting order in file manager
I didn't like how files where sorted in Linux. The way Windows sorts files makes more sense to me and after searching online for a solution, I found dozens of other people with the same question. After few hours of research and tinkering I managed to make a custom file sorting. The testing was done in Nemo file manager but probably will work in other file explorers, although some have their own custom file sorting that you can choose from. I believe this is called natural sorting.
Sorting order is affected by your locales set by this file: /etc/default/locale. There are multiple flags that start with LC_. The one that affects sorting order is LC_COLLATE that you need to add it if doesn't exist. LC_ALL overrides all flags but with a custom locale there were some applications that didn't like that, so I recommend using LC_COLLATE.
With LC_COLLATE set to C the sorting order is numbers first then symbols then capital letters are sorted before small letters:
With LC_COLLATE set to en_US_UTF-8 the sorting order is numbers first and symbols are ignored:
Here is the sorting order on Windows 10 - symbols first, then numbers, then letters:
And here is the sorting order with a custom locale file - numbers first, then symbols, then letters:
For most people the default sorting order is not an issue. For me it was
because I have NTFS formatted drives and in Linux the $RECYCLE.BIN is
visible. Also if you use GoodSync the _gsdata_ folder is visible and
with symbols being ignored it looked messy.
How to customize the file sorting order in Linux
Open a Terminal by pressing CTRL + ALT + T then:
cd /usr/share/i18n/locales
to change the active directory. Here if you wish you can use the ls command to list all the locale files.
Make a copy of the en_US locale named en_US_edited:
sudo cp en_US en_US_edited
Make a copy of iso14651_t1 file, that is imported by en_US:
sudo cp iso14651_t1 iso14651_t1_edited
Finally, make a copy of iso14651_t1_common that is used by
iso14651_t1:
sudo cp iso14651_t1_common iso14651_t1_common_edited
The file iso14651_t1_common_edited is where we will make changes. The file iso14651_t1_common is used by all UTF-8 locales if I'm not mistaken. You could modify the original file but some updates will reset that so that's why we create our own locale based on en_US one.
Before continuing I recommend installing the gedit text editor using:
sudo apt install gedit
You can use vim or nano but I prefer gedit for this.
Update: now I recommend using xed which is the default text
editor in Linux Mint and it has a more powerful search and replace
functionality. So if you want to use xed just replace gedit with xed in the
following lines of code.
Next, open en_US_edited in a text editor:
sudo gedit en_US_edited
and find the line where you see copy "iso14651_t1". Change that to
"iso14651_t1_edited" and save the file with CTRL + S then ALT + F4 to
close the text editor.
Then, open iso14651_t1_edited:
sudo gedit iso14651_t1_edited
Find the line that reads copy "iso14651_t1_common". Change that to "iso14651_t1_common_edited" and save.
To add the new locale open /etc/locale.gen in a text editor:
sudo gedit /etc/locale.gen
and add this line at the beginning after the comments:
en_US_edited.UTF-8 UTF-8
Save and run the following commands to compile and verify the new locale.
sudo locale-gen
validlocale en_US_edited.UTF-8
Source: http://svmiller.com/blog/2019/07/notes-to-self-new-linux-installation-r-ubuntu/#bettersort.
Up to this point we have created a custom locale named en_US_edited that is using the iso14651_t1_common_edited file. Before editing the file let's set the new locale by opening this file:
sudo gedit /etc/default/locale
Add this line to the end:
LC_COLLATE=en_US_edited.utf-8
then save, close the file and restart the computer so the new locale takes
effect. Logging out then on again also worked for me.
Now that we have a custom locale setup and active, we can modify the iso14651_t1_common_edited file to adjust the file sorting order. The easiest way is to download the iso14651_t1_common_edited file that I modified and use that if you like that sorting order. Just place the file in the Documents folder then use this commands:
cd /usr/share/i18n/locales
sudo cp ~/Documents/iso14651_t1_common_edited
iso14651_t1_common_edited
sudo locale-gen
Restart Nemo for the changes in sorting to take effect.
That was the easy way but if you want customize and modify the file you need
to have a general idea on hot it works. I'm not an expert by far but I will
explain what I know and include some links from where I got this
information.
Understanding the sorting order in file iso14651_t1_common
Let's take for example the underscore or low line symbol '_' and suppose you want it to appear before letters. The Unicode for it is U005F. You can use an online converter like https://www.coderstool.com/unicode-text-converter to find the code. Once you have the code press CTRL + F to search the line with the symbol and use the up/down arrows in the search box to navigate. The code must be in this format: U005F (in this example) or S005F.
Notice that all symbols have IGNORE in 3 places:
<U005F> <IGNORE>;<IGNORE>;<IGNORE>;<U005F> % LOW LINE
But what this 3 places represent? There are three IGNORE statements because
letters can be compared multiple times in case of ties. To understand this,
consider lowercase a and uppercase A (which are part of a group
of characters that actually get compared four times):
<U0061> <a>;<BAS>;<MIN>;IGNORE # 198 a
<U0041> <a>;<BAS>;<CAP>;IGNORE # 517 A
Having multiple rounds of comparison allow files that start with "a" and "A" to be grouped together because both are compared as <a> during the first pass, with the next letter determining the ordering. If all of the following letters are the same (e.g. a.txt and A.txt), the third pass will put a.txt first because the collating symbol for lowercase letters <MIN> appears on line 3467, before the collating symbol for uppercase letters <CAP> (line 3488).
The IGNORE statements specify that the character will be ignored when ordering
words alphabetically. To include the symbol in the sorting process, change
IGNORE to a collating symbol that comes before all other characters.
Collating symbols are defined by lines like:
collating-symbol <RES-1>
collating-symbol <MIN>
collating-symbol <CAP>
and they are ordered by the appearance of the line.
So to include the underscore U005F in the sorting process, replace the first IGNORE with it's code but change the U with S like this:
<U005F> <S005F>;<IGNORE>;<IGNORE>;<U005F> % LOW
LINE
Why S? If you search for S005F up above you can find other symbols and above them the First-level weight assignments category is specified. In the first level it is decided what is first when sorting. For example a comes before b because appears earlier in line order. Replacing first IGNORE with S005F instead of RES-1 allows us to decide the order of the symbols in relation to each other not just place them before letters. So to make $ appear before ! just cut and copy the line with $ and paste it above the line with !. To find the desired symbols you need to search by their Unicode with S in front. For example S005F for underscore _.
Inspired from:
https://unix.stackexchange.com/a/361006.
Secondary weight
The secondary weight is used to compare diacritics. For instance, in that
en_US.UTF-8
GNU locale, E
, é
,
e
, É
all have the same primary weight.
Stéphane
and Stephanie
are decomposed in
<S><t><é><p><h><a><n> <e>
<S><t><e><p><h><a><n>
<i><e>
collating elements (here, one per character).
Up to n
, the collating elements of the two strings have the same
primary weight, but i
's primary weight is greater that
e
's, so Stephanie
sorts after
Stéphane
and the secondary weight doesn't even have to be
considered.
Now, for Stephane
vs Stéphane
, when comparing
primary weights, they sort the same, so the secondary weight has to be
considered.
In the file iso14651_t1_common
you see:
<BAS> # 15
[...]
<ACA> # 18
[...]
<U0065> <e>;<BASE>;<MIN>;IGNORE # 259 e
<U00E9> <e>;<ACA>;<MIN>;IGNORE # 260 é
The base character (BASE
) sorts before the one with acute accent
(ACA
). So Stéphane
sorts after
Stephane
. To compare STÉPHANE
against
Stéphane
, we'd have to go up to the third weight where upper case
sorts after lower case in English (contrary to Estonian for instance).
Source:
https://unix.stackexchange.com/a/426369.
Third weight
Take a look at how a
and A
are ordered based on
their entries in iso14651_t1_common
:
<U0061> <a>;<BAS>;<MIN>;IGNORE # 198 a
<U0041> <a>;<BAS>;<CAP>;IGNORE # 517 A
b
and B
are similar:
<U0062> <b>;<BAS>;<MIN>;IGNORE # 233 b
<U0042> <b>;<BAS>;<CAP>;IGNORE # 550 B
We see that on the first pass, both a
and A
have the
collating symbol <a>
, while both b
and
B
have the collating symbol <b>
. Since
<a>
appears before <b>
in
iso14651_t1_common
, a
and A
are tied
before b
and B
. The second pass doesn't break the
ties because all four characters have the collating symbol
<BAS>
, but during the third pass the ties are resolved
because the collating symbol for lowercase letters
<MIN>
appears on line 3467, before the collating symbol for
uppercase letters <CAP>
(line 3488). So the sort order ends
up as a
, A
, b
, B
.
Source:
https://unix.stackexchange.com/a/361021.
After modifying the iso14651_t1_common_edited file you have to run the sudo locale-gen command then restart Nemo file manager to see the changes in file sorting. It is preferred to have two Terminals open: one for the file that is edited and one for updating the locales.
The thing that I haven't figure it out is how to make symbols appear before numbers. If anyone knows how please leave a comment.
No comments:
Post a Comment