Show drive free space directly on the drive

As you have probably gathered already, first of all, Linux means freedom, which comes with all of its pros and cons. :smiley:
I think you have made a very good suggestion to add such a feature to Dolphin settings as an option.
You can also make this more formal by visiting bugs.kde.org
Meanwhile, I have a suggestion that can be used until such a feature is available in Dolphin:
Use such a great and versatile plasmoid as Command Output to display all mounted devices with their space details on desktop or a sidebar-like panel with the following command, for example:
echo "Device\tUsed\tFree"; df -h | awk '$1 ~ /^\/dev\// {print $1 "\t" $3 "\t" $4}' | sed -e 's@/dev/@@' -e 's/nvme0n/ssd/' | sort -k1
I think I might even keep this in my desktop layout as seen in the screenshot below.:wink:

1 Like

that’s a handy widget, good find.

however your command code is not working on my machine using bash.

the first issue was your use of smart quotes throughout which i replaced with " and ' and that cleared up a lot of issues when running the command.

however the awk command is still having issues, perhaps you have some insight

echo "Device\tUsed\tFree"
df -h | awk '$1 ~ /^/dev// {print $1 "\t" $3 "\t" $4}' |
sed -e 's@/dev/@@' -e 's/nvme0n/ssd/' |
sort -k1

results in the output

Device\tUsed\tFree
awk: cmd. line:1: $1 ~ /^/dev// {print $1 "\t" $3 "\t" $4}
awk: cmd. line:1:              ^ unterminated regexp

Sorry, there was apparently a problem with copy & paste operations. I have now converted it from multi-line to one-liner, and also corrected the single and double quotes, which were automatically converted to smart ones before (edited in my previous post above).
PS: I use 4 instances of this wonderful Command Output widget, even including a simple mail notifier! :heart:

ah, the need for \ escapes within the quotes was the issue i was having.

thanks for clearing that up, nice bit of awk and sed jujitsu to make a nicely formatted output of the df command (its own formatting options are limited).

i might put the free space first (or change it to %) and device name last so that stuff running out of room comes to the top of the list.

can i assume this widget will run a script as well as command? or does it all need to be on a single line as your edit shows?

In deed, this widget runs scripts (with or without functions used as an option, for example, as different “Actions” ) as well as one-liner (and even multi-line) commands.
PS: Replacing sort -k1 with sort -k3 sorts the devices according to free space but it’s not usable without fixing the issue with decimals and units (G, M etc.), possibly with some complex command.

1 Like