0

I'm having a hard time figuring how to pass the output of one command to another as an argument.

Specificly, I want to pass the list the extended attributes of a file in FreeBSD, with lsextattr, and pass its output to rmextattr to remove all the extended attributes. Yes, I need to do this because rmextattr don't have a recursive option...

I'm trying something like this without luck:

# lsextattr -q user some_file.txt | rmextattr user "$1" some_file.txt 
rmextattr: some_file.txt: failed: Attribute not found

I think lsextattr is working correctly, but can't pass its output to rmextattr correctly!!

# lsextattr -q user some_file.txt
DosStream.com.apple.lastuseddate#PS:$DATA   DosStream.AFP_AfpInfo:$DATA

Please, help......

1

1 Answer 1

1

IIUC, rmextattr can only take one extended attribute at a time. So you will have to loop over the extended attributes that lsextattr returns and remove each one; something like this:

for attr in $(lsextattr -q user some_file.txt) ;do
    rmextattr user $attr some_file.txt
done

(untested - I don't have access to a FreeBSD system at the moment).

In response to the question in the comment:

for file in $(find ...) ;do
    for attr in $(lsextattr -q user $file) ;do
        rmextattr user $attr $file
    done
done

I don't know what your criteria are for the files you want to consider, but you can experiment with find until you get exactly the list you want and then plug the resulting command into the $(find ...) part of the outer loop.

2
  • YES! It works! Now, how can integrate this in a find command to check all files?
    – vicmarto
    Oct 19, 2017 at 22:56
  • Excellet, worked perfectly, thank you very very much!!
    – vicmarto
    Oct 20, 2017 at 5:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .