by Paul Arnote (parnote)
In the previous Xfce Power User Tips, Tricks & Tweaks articles, we learned how to work with graphics files, archive files, multimedia files, and document files. Where these tips really shine, though, is in the file utility area -- so much so, that I'll need to break this up into two articles. This first part deals with the only deficiency/annoyance of Thunar that I can find -- the improper reporting of file sizes.
Show Correct File Sizes In Thunar
It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity, it was the season of Light, it was the season of Darkness, it was the spring of hope, it was the winter of despair, we had everything before us, we had nothing before us ... -- Charles Dickens, A Tale Of Two Cities.
I almost called this section "A Tale Of Two (Or More) File Managers." It's a perfect description of the only real "problem" I've encountered with Thunar. Indulge me while I bring you up to speed on how I discovered that Thunar isn't reporting the correct file sizes.
It's no secret that my favorite Linux desktop is Xfce. I love its simplicity, and find it to be a much more "mature" desktop than LXDE. Xfce has been around longer than LXDE, so it's understandable that it has had more time to "grow up." For me, it has "just enough" plugins available to allow me to tailor my desktop how I want, without getting weighed down with a bunch of unnecessary (and CPU cycle hogging) eye candy. My "love affair" for Xfce started when I discovered how nicely it ran on my older computers. As a result, I run Xfce on most of my computers -- even on my newest computer with a six core AMD FX-8100 processor. I do have ONE computer that uses the KDE desktop.
Every month, as you already know, I prepare each new issue of The PCLinuxOS Magazine and oversee the announcement of each new issue. For several months in a row, Old-Polack would write me back to tell me that I had listed the "wrong" file size in my monthly release notice. As an example, the file size for the June 2013 issue of The PCLinuxOS Magazine was reported as 10.7 MB by Thunar. However, checking the file size of the magazine PDF file in KDE's Dolphin file manager, the file size was reported as 10.2 MB -- a whole 0.5 MB difference! I also discovered that the PCManFM and Nautilus file managers also report the correct 10.2 MB file size.
As another example, in the image below, a video of one of our sonograms is highlighted. Thunar reports its file size as 105.9 MB, but every other file manager in existence reports is as 100.98 MB. Even if the file size is rounded up to 101.0 MB, that represents a whopping 4.9 MB discrepancy between what Thunar reports and the actual file size!
So I decided to file a "bug" report on the Xfce Bugzilla page. Read the entire entry for yourself, below.
Bug 9887 - Thunar displays incorrect file size information in Thunar status bar
Status: RESOLVED WONTFIX
Platform: PC (x86) Linux
Reported: 2013-03-03 18:09 CET by Paul Arnote
Modified: 2013-05-01 16:35 CEST (History)
CC List: 1 user (show)
Description Paul Arnote 2013-03-03 18:09:25 CET
Thunar is displaying the incorrect file size for a single selected file, or a group of multiple files selected. Thunar is reporting the MiB of the file as the number of KiB/1000, which is the method that hard drive manufacturers use to dupe us into believing we're getting a larger hard drive than we actually get.
The MiB file sizes should be based on the KiB/1024 measurement, which is how the OS sees a MiB. By using a simple hand calculator, I can take the total number of bytes listed in the file properties dialog and divide by 1024. The result is the same number of MiB that are reported by other file managers, such as Dolphin under KDE, and by Firefox when I download that same file. The larger the file, the larger the discrepancy between what is reported by Thunar as the file size and how every other application sees the file size.
Comment 1 Paul Arnote 2013-03-03 18:13:13 CET
BTW, I've found this same behavior on Thunar versions 1.4.0 and 1.6.0.
Comment 2 Nick Schermer 2013-05-01 16:35:50 CEST
Yes, and that is the correct thing to do:
explains why Thunar uses G_FORMAT_SIZE_DEFAULT.
Well, DRATS! OK ... I used somewhat different verbiage, but you get the idea. Seriously? For whatever reason, the Xfce developers are singularly interpreting that GFormatSizeFlags should be based on the 1,000 byte divisor, instead of the 1024 byte divisor -- as everyone else does. I find it funny that the Xfce developers are the only ones adhering to the stated GNOME standard. The last time I used Nautilus, the GNOME file manager, even it was reporting file sizes properly. Basically, using the 1,000 byte divisor describes more or less how much hard drive space a file is using (disregarding disk sector sizes), as opposed to how big the file actually is.
You could compile a custom version of Thunar, with the source code corrected to display the proper file size, but that is something that is far beyond the capabilities or knowledge of a typical user. In fact, I wouldn't recommend this "fix" for anyone but the most experienced user with a programming background. Fortunately, we can correct this error with a Thunar Custom Action. The custom action becomes the second best option, and for most users, the only acceptable option.
To start with, open a plain text editor and type in (or copy) the following bash script. Preferably, save it to a location somewhere in your path. I store mine in my ~/Scripts directory, and call it file-size.sh. Special thanks to Pete Kelly, a.k.a. critter, for his assistance with this script. Don't forget to make the file "executable."
for file in $@; do
if [ ! -e $file ]; then
b1=`ls -l $file | cut -d" " -f5`
let "b += b1"
k=`echo -e "scale=2; $b/$kb" | bc`
m=`echo -e "scale=2; $b/$mb" | bc`
zenity --info --title="Actual File Size" --width=300 --height=100 --text="$b bytes\n$k KB\n$m MB"
Provide a name and description for your new custom action. I entered "Actual File Size" on the first line for the name, and "Report the ACTUAL file size" on the second line for the description. On the third line, enter the following command:
Select an icon for your new Thunar Custom Command. Under the "Appearance Conditions" tab, place a checkmark in front of every file type, and keep the "File pattern" set to the default * value. Now, whenever you select "Actual File Size" from Thunar's right click context menu, you will see a dialog box similar to the one shown below. You can select a single file or directory, or multiple files or directories. If you select multiple "items," the total file size will be calculated for all of the files, added together.
Enjoy the reporting of proper file sizes in Thunar. This custom action should be in the arsenal of every Xfce user, if you care at all about knowing the proper size of your files. In the next Xfce Power User Tips, Tricks & Tweaks article, I'll show you several more file utilities you can employ.