linux – assign variables to a file or directory

setfattr -n user.name -v “Vitalijus” testdir
echo “some test” > testdir/testfile
setfattr -n user.test -v “Test file” testdir/testfile
getfattr -d -R testdir > xattr.attr

rm -rf testdir
mkdir testdir ; echo “xaxaxa” > testdir/testfile
setfattr –restore=xattr.attr
getfattr -d -R testdir

Extended attributes are properties organized in (name, value) pairs, optionally set to files or directories in order to record information which cannot be stored in the file itself. They are supported by operating system.

On Linux, specifically, four categories of extended attributes have been defined :

  • trusted : to record properties which should only be accessed by the kernel,
  • security : to record security properties of a file,
  • system : to record other system related properties on which the file owner has some control,
  • user : to record properties defined by applications.

Leave a Reply

Your email address will not be published. Required fields are marked *