Can you show/list all extended-attributes and how?
4 Answers
In Linux, independent of filesystem command to view file extended attributes is
getfattr -d -m '' -- <filename>
At last it show Selinux attributes.
getfattr -d -- <filename>
Show only user.* attributes.
- 2,008
- 16
- 13
-
4I'd suggest `getfattr -d -m ^ -R --
` – Mikko Rantalainen Jul 02 '19 at 07:19 -
@MikkoRantalainen why? Sorry, never used that before. – Yaroslav Nikitenko Sep 13 '22 at 21:11
-
1The `-m ^` matches start of any string without need for escaping the parameter and double dash `--` is needed as a separator in case the filename or directory starts with a dash. – Mikko Rantalainen Sep 14 '22 at 14:22
-
This is technically not correct. Try using `getfattr` to list xattrs in the `system` namespace on an NTFS filesystem mounted via the ntfs-3g driver. Even as root they are not listed. However, one can get the value of the xattr, eg. `system.ntfs_acl`, if specifying the name of the xattr explicitly via the `-n` parameter. I've yet to see a way to have the `system` xattrs listed. – crass Oct 21 '22 at 22:45
-
1`getfattr -d -m ''
` also appears to list all xattrs, as an empty regex matches every string. – Markus Kuhn Feb 01 '23 at 16:45
On a MacOs the Unix flavor is Darwin which is derived from BSD. In this version of Unix, use the command xattr to list (or create, write, or clear) the extended attributes.
xattr <filename> will just list the names of the attributes
xattr -l <filename> will list their names and values
xattr -h for a more succinct help message
man xattr for a detailed help message (ZZ to exit the help)
I found this command at https://en.wikipedia.org/wiki/Extended_file_attributes#macOS
- 141
- 2
getfattr is not present in my debian distribution. I use this instead:
lsattr <filename>
- 179
- 1
- 1
-
7That is different attributes. "lsattr" lists "file attributes" which is a specific set of attributes available on ext* file systems. "getfattr" lists "extended attributes" which is a kind of name-value pairs available on several file systems. See the respective manual pages for details. – Göran Uddeborg May 31 '20 at 21:46
-
3This is misleading. The `getfattr` command is an official part of Ubuntu, and presumably Debian, but is in the `attr` package, which is not installed by default. Use `apt install attr` to get it. And it is indeed different than `lsattr` as noted by Göran. – nealmcb Dec 07 '20 at 17:03
-
1`I-node flags (ext2 extended file attributes)` is derived from the `ext2` file system, but nowadays it is also available on other file systems. A minor supplement to @GöranUddeborg's comment. – Steve Lau Oct 13 '22 at 03:13
The command to list all extended attributes is ls -l@.
An example (from my mac, linux/BSD will look different):
felixphew-mbp:/ felixphew$ ls -l@
total 45
drwxrwxr-x+ 63 root admin 2142 27 Dec 17:49 Applications
drwxr-xr-x+ 62 root wheel 2108 16 Nov 06:25 Library
drwxr-xr-x@ 2 root wheel 68 10 Sep 06:47 Network
com.apple.FinderInfo 32
drwxr-xr-x+ 4 root wheel 136 1 Nov 14:02 System
drwxr-xr-x 6 root admin 204 28 Dec 07:36 Users
drwxrwxrwt@ 3 root admin 102 30 Dec 06:40 Volumes
com.apple.FinderInfo 32
drwxr-xr-x@ 39 root wheel 1326 11 Nov 07:06 bin
com.apple.FinderInfo 32
drwxrwxr-t@ 2 root admin 68 10 Sep 06:47 cores
com.apple.FinderInfo 32
dr-xr-xr-x 3 root wheel 4306 30 Dec 06:40 dev
lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:56 etc -> private/etc
com.apple.FinderInfo 32
dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 home
-rw-r--r--@ 1 root wheel 313 1 Oct 16:12 installer.failurerequests
com.apple.FinderInfo 32
dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 net
drwxr-xr-x@ 3 root wheel 102 12 Aug 07:19 opt
com.apple.FinderInfo 32
drwxr-xr-x@ 6 root wheel 204 1 Nov 14:05 private
com.apple.FinderInfo 32
drwxr-xr-x@ 59 root wheel 2006 18 Nov 07:46 sbin
com.apple.FinderInfo 32
drwxr-xr-x@ 3 root wheel 102 22 Dec 07:46 srv
com.apple.FinderInfo 32
lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 tmp -> private/tmp
com.apple.FinderInfo 32
drwxr-xr-x@ 13 root wheel 442 23 Nov 11:20 usr
com.apple.FinderInfo 32
lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 var -> private/var
com.apple.FinderInfo 32
The same dir in ls -l:
felixphew-mbp:/ felixphew$ ls -l
total 45
drwxrwxr-x+ 63 root admin 2142 27 Dec 17:49 Applications
drwxr-xr-x+ 62 root wheel 2108 16 Nov 06:25 Library
drwxr-xr-x@ 2 root wheel 68 10 Sep 06:47 Network
drwxr-xr-x+ 4 root wheel 136 1 Nov 14:02 System
drwxr-xr-x 6 root admin 204 28 Dec 07:36 Users
drwxrwxrwt@ 3 root admin 102 30 Dec 06:40 Volumes
drwxr-xr-x@ 39 root wheel 1326 11 Nov 07:06 bin
drwxrwxr-t@ 2 root admin 68 10 Sep 06:47 cores
dr-xr-xr-x 3 root wheel 4306 30 Dec 06:40 dev
lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:56 etc -> private/etc
dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 home
-rw-r--r--@ 1 root wheel 313 1 Oct 16:12 installer.failurerequests
dr-xr-xr-x 2 root wheel 1 30 Dec 06:40 net
drwxr-xr-x@ 3 root wheel 102 12 Aug 07:19 opt
drwxr-xr-x@ 6 root wheel 204 1 Nov 14:05 private
drwxr-xr-x@ 59 root wheel 2006 18 Nov 07:46 sbin
drwxr-xr-x@ 3 root wheel 102 22 Dec 07:46 srv
lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 tmp -> private/tmp
drwxr-xr-x@ 13 root wheel 442 23 Nov 11:20 usr
lrwxr-xr-x@ 1 root wheel 11 1 Nov 13:57 var -> private/var
- 141
- 6
-
27The `@` argument given to `ls` is an `invalid option` on linux. I looked up the `@` option and this is specific to mac OS-X. This question is specific to linux. – Trevor Boyd Smith Dec 29 '14 at 20:18
-
1