15

Can I use find to find all files which have extended attributes set? Let's say, I want to find all files with +i, immutable attribute in /foo and its subfolders.

I could not find any, mention of extended attributes in man find.

Is there any other way to find all files with attributes

I am using Debian Wheezy

Martin Vegter
  • 358
  • 75
  • 236
  • 411
  • 2
    @DopeGhoti, I was about to provide the link to Gille's answer. It uses find method. The link to Gille's answer is this one. – Ramesh Oct 15 '14 at 20:56
  • 10
    BSD find (the same that comes with Mac OS) has both -xattr and -xattrname options to deal with extended attributes. To find files that have extended attributes set you can just use something like find . -xattr -exec xattr -v {} \;. Use -xattrname to search for specific attributes. – Claudio Floreani Oct 07 '16 at 09:49
  • To delete an attribute by name for example: find ~/some-path/ -xattrname com.apple.FinderInfo -exec xattr -d com.apple.FinderInfo {} \; – Benno Jan 08 '18 at 07:45
  • @ClaudioFloreani Do you have a source for that? I can't find -xattr in any manpage from MacOS, FreeBSD or OpenBSD. – Artefact2 Aug 29 '18 at 13:11
  • 1
    there is now a fresh utility that wraps find and supports this for any POSIX compliant OS, you can find it at https://github.com/Cbhihe/findxattr – Gregor Oct 03 '22 at 20:19
  • Immutability is a file attribute (Linux) or file flag (BSDs), not necessarily an extended attribute. Some systems store file attributes as extended attributes but extended attributes are generic key/value stores. My rawhide (rh) program can search for both. To find immutable files do rh / immutable. To find files with a particular extended attribute (name or value) do rh / '"*pattern*".ea'. It's at https://github.com/raforg/rawhide. – raf Aug 29 '23 at 03:25

1 Answers1

4

find itself doesn't support extended atttribute but you can use such as:

find ~/ -type f  -iname "*" -exec lsattr {} + | grep  -v -- '-------------'
Marcus
  • 961
PersianGulf
  • 10,850