How-to: Add notes to your Linux files

You'll need to install attr (extended file attributes) through your package manager.

Attr will let you (among other things) set your own file attributes in the 'user' namespace and add any text to them.

Examples:
This will assign user.memo attribute the value you set in -v option:

$ setfattr -n user.memo -v "write here some note" filename

Another one:

$ setfattr -n user.author.name -v "write here your name" filename

(n=name, v=value)

To dump all user attributes of a file and their values:

$ getfattr -d filename

To show a single attribute of a file and its value:

$ getfattr -n user.xxx filename

To show only values (will skip attribute names) of all attributes of a file:

$ getfattr --only-values filename

To dump all attributes and their values of all files in a directory (recursively):

$ getfattr -R -d /home/john

To have getfattr output text in different languages charsets just add the following option to above getfattr examples:

-e "text"

To delete an attribute:

$ setfattr -x user.xxx filename

To copy a file and preserve its attributes (will work on supported filesystems) use the -p (preserve) flag:

$ cp -p filename dir 

If you're moving your files to another filesystem (e.g. for backup) where attributes aren't supported, you can easily backup your attributes for later restoration (or just for reference).

To backup all attributes and values from current dir onwards into a file:

$ getfattr -d -R . > data

To restore everything from above backup file (must run from same dir where backup was taken) :

$ setfattr --restore=data

Top News