saving notes against a file on linux

I want to save notes against a file on linux. I want to save meta data about a file, because the file names are restricted in max length.

so how to save notes or comments about a file on linux so that it gets saved along with the file itself...

i used the notes tab in the file properties dialogbox.. but that way the notes stick to the file only on that OS only.. if i open that file in another linux os.. those comments/notes are gone...

please suggest me a way to embedd these notes into the file so that i dont lose them ever..

at lease a solution that makes this possible on switching linux distros. if its not portable enough that these notes stick b/w windows and linux its ok for me.. but atleast if i format my linux os.. atleast i shouldnt lose those important notes..and be able to access on newer linux..

and i also have no idea if this notes tab was implemented to be linked with the OS only.. i dont see much use of it.. and a normal user also has noway to know this.. i also came to know on superuser chat from a buddy.. @Sathya .. this thing is more useless especially if u use ubuntu which has 6 months timeline..and crazy people like me who are always eager to upgrade their os as soon a new one is available..

and any way i can search these notes from the terminal?? that would be awsome too..

kindly help.. Thanks.


Solution 1:

Linux filesystems support a feature called extended file attributes or "xattr".

You have to mount the filesystem with the user_xattr mount option, and if you do then any application that has the right to read/write the file can also read/write a bunch of metadata to it, including 'user' attributes with any name and value, though few applications will use them as they are not common.

The attr command can read and edit them - here's a bit of a tutorial. Don't know which GUI apps (nautilus?) will let you view or edit them though. Applications like beagle are aware of them, so you should be able to use that to search through them.

Note that if you copy the file between filesystems, not only do both filesystems need to be mounted with the user_xattr mount option, but the application doing the copying needs to be told to preserve them.

For cp, use:

--preserve=xattr

(-a won't do it).

For rsync, use:

--xattrs

(or -X).

It's not exactly something that everyone's doing.

Solution 2:

How about saving the notes in a free-form text file with a special extension along with the file?

I usually save 'exif' files along with a 'jpg' or 'raw' which starts with the basic EXIF information and can have additional notes.

1. File picture.jpg
2. jhead picture.jpg > picture.exif
3. vim picture.exif # Add annotations, notes, checksum, et al
4. Keep the jpg and exif files together

Of course, there will be other formats which handle meta data which would be more easy to handle. But, there is not much that will beat the portability and flexibility of this meta-file scheme.