Pete's Linux Advent Calendar 2007
The 13th day
File Metadata with extended attributes
Metadata of files is a nice feature. Your (ext3) filesystem has to be
mounted with the option user_xattr. With
getfattr(1) you can view the the attributes
and with setfattr(1) you can set them.
Here is a little script that you can integrate into your
filemanager to set a comment to a selected file:
#!/bin/bash
# editattributes - edit extended file attribute "user.comment"
file="$1"
oldcomment=$(getfattr -n user.comment --only-values -- "${file}" 2>/dev/null)
comment=$(kdialog --inputbox "Enter comment for \"${file##*/}\"" "$oldcomment")
retval=$?
if [ $retval -ne 0 ]; then
exit 0
fi
setfattr -n user.comment -v "$comment" -- "$file"
As I use KDE I also use kdialog. To add the action
to konqueror create a .desktop file in
~/.kde/share/apps/konqueror/servicemenus/xattributes.desktop:
[Desktop Entry]
Actions=EditAttributes
ServiceTypes=all/allfiles
[Desktop Action EditAttributes]
Exec=$HOME/bin/editattributes %u
Name=Edit extended attributes
then you wil find the Action "Edit extended attributes"
under the right mouse button Actions menu. I am sure you
will find more advanced usage for this.