Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Advertise on
How-to: Add notes to your Linux files
New on LowEndTalk? Please read our 'Community Rules' by clicking on it in the right menu!

How-to: Add notes to your Linux files

farsighterfarsighter Member
edited September 2019 in Tutorials

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.

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 -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 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 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

Thanked by 1borales
Sign In or Register to comment.