How to clone/copy all file/directory attributes onto different file/directory?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
11
down vote

favorite
3












I want to copy the attributes (ownership, group, ACL, extended attributes, etc.) of one directory to another but not the directory contents itself.



This does not work:



cp -v --attributes-only A B
cp: omitting directory `A'


Note: It does not have to be cp.










share|improve this question



















  • 1




    You did not pass -r, so it is ignoring directories. But I guess you want to copy only the attributes, not the contents? I can think of only ugly hacks. Also note that install can preserve SELinux contexts.
    – lynxlynxlynx
    Jul 29 '12 at 20:03






  • 3




    possible duplicate of Clone ownership and permissions from another file?
    – Gilles
    Jul 30 '12 at 0:22






  • 1




    @Gilles, thank you for pointing to another topic. It solves part of problem: ownership and mode. What about extended attributes?
    – Grzegorz Wierzowiecki
    Jul 31 '12 at 13:13






  • 1




    @GrzegorzWierzowiecki I'm afraid very few tools support extended attributes. If they're important, use killermist's rsync suggestion.
    – Gilles
    Jul 31 '12 at 19:08










  • Btw. Here are nice examples where one may see xattrs in action: GUI of Dolphin in KDE: imgur.com/oguuJNm or URL from where file was downloaded set by browsers: references: gist.github.com/gwpl/a00e18bc150f1e3518335d13c5e46ad7 + freedesktop.org/wiki/CommonExtendedAttributes + vhanda.in/blog/2014/07/tagging-your-files
    – Grzegorz Wierzowiecki
    Dec 15 '17 at 22:55















up vote
11
down vote

favorite
3












I want to copy the attributes (ownership, group, ACL, extended attributes, etc.) of one directory to another but not the directory contents itself.



This does not work:



cp -v --attributes-only A B
cp: omitting directory `A'


Note: It does not have to be cp.










share|improve this question



















  • 1




    You did not pass -r, so it is ignoring directories. But I guess you want to copy only the attributes, not the contents? I can think of only ugly hacks. Also note that install can preserve SELinux contexts.
    – lynxlynxlynx
    Jul 29 '12 at 20:03






  • 3




    possible duplicate of Clone ownership and permissions from another file?
    – Gilles
    Jul 30 '12 at 0:22






  • 1




    @Gilles, thank you for pointing to another topic. It solves part of problem: ownership and mode. What about extended attributes?
    – Grzegorz Wierzowiecki
    Jul 31 '12 at 13:13






  • 1




    @GrzegorzWierzowiecki I'm afraid very few tools support extended attributes. If they're important, use killermist's rsync suggestion.
    – Gilles
    Jul 31 '12 at 19:08










  • Btw. Here are nice examples where one may see xattrs in action: GUI of Dolphin in KDE: imgur.com/oguuJNm or URL from where file was downloaded set by browsers: references: gist.github.com/gwpl/a00e18bc150f1e3518335d13c5e46ad7 + freedesktop.org/wiki/CommonExtendedAttributes + vhanda.in/blog/2014/07/tagging-your-files
    – Grzegorz Wierzowiecki
    Dec 15 '17 at 22:55













up vote
11
down vote

favorite
3









up vote
11
down vote

favorite
3






3





I want to copy the attributes (ownership, group, ACL, extended attributes, etc.) of one directory to another but not the directory contents itself.



This does not work:



cp -v --attributes-only A B
cp: omitting directory `A'


Note: It does not have to be cp.










share|improve this question















I want to copy the attributes (ownership, group, ACL, extended attributes, etc.) of one directory to another but not the directory contents itself.



This does not work:



cp -v --attributes-only A B
cp: omitting directory `A'


Note: It does not have to be cp.







filesystems backup file-copy xattr






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 31 '12 at 22:05









bahamat

23.7k14590




23.7k14590










asked Jul 29 '12 at 18:14









Grzegorz Wierzowiecki

5,0431260101




5,0431260101







  • 1




    You did not pass -r, so it is ignoring directories. But I guess you want to copy only the attributes, not the contents? I can think of only ugly hacks. Also note that install can preserve SELinux contexts.
    – lynxlynxlynx
    Jul 29 '12 at 20:03






  • 3




    possible duplicate of Clone ownership and permissions from another file?
    – Gilles
    Jul 30 '12 at 0:22






  • 1




    @Gilles, thank you for pointing to another topic. It solves part of problem: ownership and mode. What about extended attributes?
    – Grzegorz Wierzowiecki
    Jul 31 '12 at 13:13






  • 1




    @GrzegorzWierzowiecki I'm afraid very few tools support extended attributes. If they're important, use killermist's rsync suggestion.
    – Gilles
    Jul 31 '12 at 19:08










  • Btw. Here are nice examples where one may see xattrs in action: GUI of Dolphin in KDE: imgur.com/oguuJNm or URL from where file was downloaded set by browsers: references: gist.github.com/gwpl/a00e18bc150f1e3518335d13c5e46ad7 + freedesktop.org/wiki/CommonExtendedAttributes + vhanda.in/blog/2014/07/tagging-your-files
    – Grzegorz Wierzowiecki
    Dec 15 '17 at 22:55













  • 1




    You did not pass -r, so it is ignoring directories. But I guess you want to copy only the attributes, not the contents? I can think of only ugly hacks. Also note that install can preserve SELinux contexts.
    – lynxlynxlynx
    Jul 29 '12 at 20:03






  • 3




    possible duplicate of Clone ownership and permissions from another file?
    – Gilles
    Jul 30 '12 at 0:22






  • 1




    @Gilles, thank you for pointing to another topic. It solves part of problem: ownership and mode. What about extended attributes?
    – Grzegorz Wierzowiecki
    Jul 31 '12 at 13:13






  • 1




    @GrzegorzWierzowiecki I'm afraid very few tools support extended attributes. If they're important, use killermist's rsync suggestion.
    – Gilles
    Jul 31 '12 at 19:08










  • Btw. Here are nice examples where one may see xattrs in action: GUI of Dolphin in KDE: imgur.com/oguuJNm or URL from where file was downloaded set by browsers: references: gist.github.com/gwpl/a00e18bc150f1e3518335d13c5e46ad7 + freedesktop.org/wiki/CommonExtendedAttributes + vhanda.in/blog/2014/07/tagging-your-files
    – Grzegorz Wierzowiecki
    Dec 15 '17 at 22:55








1




1




You did not pass -r, so it is ignoring directories. But I guess you want to copy only the attributes, not the contents? I can think of only ugly hacks. Also note that install can preserve SELinux contexts.
– lynxlynxlynx
Jul 29 '12 at 20:03




You did not pass -r, so it is ignoring directories. But I guess you want to copy only the attributes, not the contents? I can think of only ugly hacks. Also note that install can preserve SELinux contexts.
– lynxlynxlynx
Jul 29 '12 at 20:03




3




3




possible duplicate of Clone ownership and permissions from another file?
– Gilles
Jul 30 '12 at 0:22




possible duplicate of Clone ownership and permissions from another file?
– Gilles
Jul 30 '12 at 0:22




1




1




@Gilles, thank you for pointing to another topic. It solves part of problem: ownership and mode. What about extended attributes?
– Grzegorz Wierzowiecki
Jul 31 '12 at 13:13




@Gilles, thank you for pointing to another topic. It solves part of problem: ownership and mode. What about extended attributes?
– Grzegorz Wierzowiecki
Jul 31 '12 at 13:13




1




1




@GrzegorzWierzowiecki I'm afraid very few tools support extended attributes. If they're important, use killermist's rsync suggestion.
– Gilles
Jul 31 '12 at 19:08




@GrzegorzWierzowiecki I'm afraid very few tools support extended attributes. If they're important, use killermist's rsync suggestion.
– Gilles
Jul 31 '12 at 19:08












Btw. Here are nice examples where one may see xattrs in action: GUI of Dolphin in KDE: imgur.com/oguuJNm or URL from where file was downloaded set by browsers: references: gist.github.com/gwpl/a00e18bc150f1e3518335d13c5e46ad7 + freedesktop.org/wiki/CommonExtendedAttributes + vhanda.in/blog/2014/07/tagging-your-files
– Grzegorz Wierzowiecki
Dec 15 '17 at 22:55





Btw. Here are nice examples where one may see xattrs in action: GUI of Dolphin in KDE: imgur.com/oguuJNm or URL from where file was downloaded set by browsers: references: gist.github.com/gwpl/a00e18bc150f1e3518335d13c5e46ad7 + freedesktop.org/wiki/CommonExtendedAttributes + vhanda.in/blog/2014/07/tagging-your-files
– Grzegorz Wierzowiecki
Dec 15 '17 at 22:55











5 Answers
5






active

oldest

votes

















up vote
12
down vote



accepted










After quite a bit of trial and error on the commandline, I think I've found the answer. But it isn't a cp-related answer.



rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir



This does:



-p, --perms preserve permissions
-t, --times preserve modification times
-o, --owner preserve owner (super-user only)
-g, --group preserve group
-d, --dirs transfer directories without recursing
-A, --acls preserve ACLs (implies --perms)
-X, --xattrs preserve extended attributes
--no-recursive disables recursion


For reference



 --no-OPTION turn off an implied OPTION (e.g. --no-D)
-r, --recursive recurse into directories





share|improve this answer






















  • That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
    – killermist
    Jul 31 '12 at 18:50











  • The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
    – jw013
    Jul 31 '12 at 18:51











  • @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
    – killermist
    Jul 31 '12 at 18:58











  • My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
    – Gilles
    Jul 31 '12 at 19:11










  • @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
    – killermist
    Aug 1 '12 at 17:04

















up vote
0
down vote













chmod --reference=first-dir second-dir





share|improve this answer
















  • 2




    This won't work recursively, and I believe it will not copy ACLs or extended attributes.
    – Mat
    Nov 29 '12 at 17:17










  • It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
    – ShadSterling
    Oct 6 '16 at 12:51

















up vote
0
down vote













cp -rfp from_dir to_dir



  • -r - recursive


  • -f - force


  • -p - preserve attributes: mode, ownership, timestamps





share|improve this answer






















  • Also need --attributes-only
    – smremde
    Oct 14 '17 at 21:11

















up vote
0
down vote













I do not understand because it seems to work for others, but the rsync method fails for me on FreeBSD with ZFS. Nothing happens. However Jean-François Dockes’s method works. (see: https://www.lesbonscomptes.com/pxattr/ ) Source directory = A & destination directory = B, from the original question.



pxattr -lR A > tmp.EAs


(edit the first line of tmp.EAs to change the A directory to B, s/A/B/)



pxattr -S tmp.EAs





share|improve this answer








New contributor




cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    -3
    down vote













    You need the "-r" for copying a directory.






    share|improve this answer
















    • 2




      I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
      – tripledes
      Jul 29 '12 at 20:38










    • -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
      – Grzegorz Wierzowiecki
      Jul 29 '12 at 21:20










    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f44253%2fhow-to-clone-copy-all-file-directory-attributes-onto-different-file-directory%23new-answer', 'question_page');

    );

    Post as a guest






























    5 Answers
    5






    active

    oldest

    votes








    5 Answers
    5






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    12
    down vote



    accepted










    After quite a bit of trial and error on the commandline, I think I've found the answer. But it isn't a cp-related answer.



    rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir



    This does:



    -p, --perms preserve permissions
    -t, --times preserve modification times
    -o, --owner preserve owner (super-user only)
    -g, --group preserve group
    -d, --dirs transfer directories without recursing
    -A, --acls preserve ACLs (implies --perms)
    -X, --xattrs preserve extended attributes
    --no-recursive disables recursion


    For reference



     --no-OPTION turn off an implied OPTION (e.g. --no-D)
    -r, --recursive recurse into directories





    share|improve this answer






















    • That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
      – killermist
      Jul 31 '12 at 18:50











    • The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
      – jw013
      Jul 31 '12 at 18:51











    • @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
      – killermist
      Jul 31 '12 at 18:58











    • My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
      – Gilles
      Jul 31 '12 at 19:11










    • @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
      – killermist
      Aug 1 '12 at 17:04














    up vote
    12
    down vote



    accepted










    After quite a bit of trial and error on the commandline, I think I've found the answer. But it isn't a cp-related answer.



    rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir



    This does:



    -p, --perms preserve permissions
    -t, --times preserve modification times
    -o, --owner preserve owner (super-user only)
    -g, --group preserve group
    -d, --dirs transfer directories without recursing
    -A, --acls preserve ACLs (implies --perms)
    -X, --xattrs preserve extended attributes
    --no-recursive disables recursion


    For reference



     --no-OPTION turn off an implied OPTION (e.g. --no-D)
    -r, --recursive recurse into directories





    share|improve this answer






















    • That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
      – killermist
      Jul 31 '12 at 18:50











    • The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
      – jw013
      Jul 31 '12 at 18:51











    • @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
      – killermist
      Jul 31 '12 at 18:58











    • My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
      – Gilles
      Jul 31 '12 at 19:11










    • @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
      – killermist
      Aug 1 '12 at 17:04












    up vote
    12
    down vote



    accepted







    up vote
    12
    down vote



    accepted






    After quite a bit of trial and error on the commandline, I think I've found the answer. But it isn't a cp-related answer.



    rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir



    This does:



    -p, --perms preserve permissions
    -t, --times preserve modification times
    -o, --owner preserve owner (super-user only)
    -g, --group preserve group
    -d, --dirs transfer directories without recursing
    -A, --acls preserve ACLs (implies --perms)
    -X, --xattrs preserve extended attributes
    --no-recursive disables recursion


    For reference



     --no-OPTION turn off an implied OPTION (e.g. --no-D)
    -r, --recursive recurse into directories





    share|improve this answer














    After quite a bit of trial and error on the commandline, I think I've found the answer. But it isn't a cp-related answer.



    rsync -ptgo -A -X -d --no-recursive --exclude=* first-dir/ second-dir



    This does:



    -p, --perms preserve permissions
    -t, --times preserve modification times
    -o, --owner preserve owner (super-user only)
    -g, --group preserve group
    -d, --dirs transfer directories without recursing
    -A, --acls preserve ACLs (implies --perms)
    -X, --xattrs preserve extended attributes
    --no-recursive disables recursion


    For reference



     --no-OPTION turn off an implied OPTION (e.g. --no-D)
    -r, --recursive recurse into directories






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 31 '12 at 18:45









    jw013

    35.2k698123




    35.2k698123










    answered Jul 31 '12 at 16:20









    killermist

    939922




    939922











    • That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
      – killermist
      Jul 31 '12 at 18:50











    • The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
      – jw013
      Jul 31 '12 at 18:51











    • @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
      – killermist
      Jul 31 '12 at 18:58











    • My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
      – Gilles
      Jul 31 '12 at 19:11










    • @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
      – killermist
      Aug 1 '12 at 17:04
















    • That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
      – killermist
      Jul 31 '12 at 18:50











    • The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
      – jw013
      Jul 31 '12 at 18:51











    • @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
      – killermist
      Jul 31 '12 at 18:58











    • My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
      – Gilles
      Jul 31 '12 at 19:11










    • @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
      – killermist
      Aug 1 '12 at 17:04















    That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
    – killermist
    Jul 31 '12 at 18:50





    That last edit is definitely a hit there. With or without a / on the second-dir, that finally does exactly what is asked, it looks like.
    – killermist
    Jul 31 '12 at 18:50













    The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
    – jw013
    Jul 31 '12 at 18:51





    The trailing slash only makes a difference on the first argument, not the second. It's explained in the 3rd or 4th paragraph of the USAGE section of the rsync(1) man page.
    – jw013
    Jul 31 '12 at 18:51













    @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
    – killermist
    Jul 31 '12 at 18:58





    @jw013 After reading the rsync documentation repeatedly, months ago, my conclusion was that the trailing slashes were an implied "into", whether in the first (second, third, etc) or last argument. But then again, I often end my commands with a / on the last argument to imply/demand an "into" affect.
    – killermist
    Jul 31 '12 at 18:58













    My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
    – Gilles
    Jul 31 '12 at 19:11




    My gut feeling to copy all directory attributes and no regular file would be rsync -a -AX --include='*/' --exclude='*'. I haven't tested.
    – Gilles
    Jul 31 '12 at 19:11












    @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
    – killermist
    Aug 1 '12 at 17:04




    @jw013 Thanks on helping get this answer dialed in. I tried SO many options on my little sandbox test environment, and kept coming close, but having some part of it not work right.
    – killermist
    Aug 1 '12 at 17:04












    up vote
    0
    down vote













    chmod --reference=first-dir second-dir





    share|improve this answer
















    • 2




      This won't work recursively, and I believe it will not copy ACLs or extended attributes.
      – Mat
      Nov 29 '12 at 17:17










    • It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
      – ShadSterling
      Oct 6 '16 at 12:51














    up vote
    0
    down vote













    chmod --reference=first-dir second-dir





    share|improve this answer
















    • 2




      This won't work recursively, and I believe it will not copy ACLs or extended attributes.
      – Mat
      Nov 29 '12 at 17:17










    • It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
      – ShadSterling
      Oct 6 '16 at 12:51












    up vote
    0
    down vote










    up vote
    0
    down vote









    chmod --reference=first-dir second-dir





    share|improve this answer












    chmod --reference=first-dir second-dir






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 29 '12 at 15:23









    Etienne Dublé

    11




    11







    • 2




      This won't work recursively, and I believe it will not copy ACLs or extended attributes.
      – Mat
      Nov 29 '12 at 17:17










    • It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
      – ShadSterling
      Oct 6 '16 at 12:51












    • 2




      This won't work recursively, and I believe it will not copy ACLs or extended attributes.
      – Mat
      Nov 29 '12 at 17:17










    • It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
      – ShadSterling
      Oct 6 '16 at 12:51







    2




    2




    This won't work recursively, and I believe it will not copy ACLs or extended attributes.
    – Mat
    Nov 29 '12 at 17:17




    This won't work recursively, and I believe it will not copy ACLs or extended attributes.
    – Mat
    Nov 29 '12 at 17:17












    It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
    – ShadSterling
    Oct 6 '16 at 12:51




    It's not supposed to be recursive: The OP asked for "not the directory contents itself", and the accepted answer tells rsync --no-recursive. The problem with this answer is that it doesn't do ACLs or XATTRs.
    – ShadSterling
    Oct 6 '16 at 12:51










    up vote
    0
    down vote













    cp -rfp from_dir to_dir



    • -r - recursive


    • -f - force


    • -p - preserve attributes: mode, ownership, timestamps





    share|improve this answer






















    • Also need --attributes-only
      – smremde
      Oct 14 '17 at 21:11














    up vote
    0
    down vote













    cp -rfp from_dir to_dir



    • -r - recursive


    • -f - force


    • -p - preserve attributes: mode, ownership, timestamps





    share|improve this answer






















    • Also need --attributes-only
      – smremde
      Oct 14 '17 at 21:11












    up vote
    0
    down vote










    up vote
    0
    down vote









    cp -rfp from_dir to_dir



    • -r - recursive


    • -f - force


    • -p - preserve attributes: mode, ownership, timestamps





    share|improve this answer














    cp -rfp from_dir to_dir



    • -r - recursive


    • -f - force


    • -p - preserve attributes: mode, ownership, timestamps






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 4 '14 at 13:48









    slm♦

    240k66499668




    240k66499668










    answered Jul 4 '14 at 13:36









    burtsevyg

    1112




    1112











    • Also need --attributes-only
      – smremde
      Oct 14 '17 at 21:11
















    • Also need --attributes-only
      – smremde
      Oct 14 '17 at 21:11















    Also need --attributes-only
    – smremde
    Oct 14 '17 at 21:11




    Also need --attributes-only
    – smremde
    Oct 14 '17 at 21:11










    up vote
    0
    down vote













    I do not understand because it seems to work for others, but the rsync method fails for me on FreeBSD with ZFS. Nothing happens. However Jean-François Dockes’s method works. (see: https://www.lesbonscomptes.com/pxattr/ ) Source directory = A & destination directory = B, from the original question.



    pxattr -lR A > tmp.EAs


    (edit the first line of tmp.EAs to change the A directory to B, s/A/B/)



    pxattr -S tmp.EAs





    share|improve this answer








    New contributor




    cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote













      I do not understand because it seems to work for others, but the rsync method fails for me on FreeBSD with ZFS. Nothing happens. However Jean-François Dockes’s method works. (see: https://www.lesbonscomptes.com/pxattr/ ) Source directory = A & destination directory = B, from the original question.



      pxattr -lR A > tmp.EAs


      (edit the first line of tmp.EAs to change the A directory to B, s/A/B/)



      pxattr -S tmp.EAs





      share|improve this answer








      New contributor




      cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.



















        up vote
        0
        down vote










        up vote
        0
        down vote









        I do not understand because it seems to work for others, but the rsync method fails for me on FreeBSD with ZFS. Nothing happens. However Jean-François Dockes’s method works. (see: https://www.lesbonscomptes.com/pxattr/ ) Source directory = A & destination directory = B, from the original question.



        pxattr -lR A > tmp.EAs


        (edit the first line of tmp.EAs to change the A directory to B, s/A/B/)



        pxattr -S tmp.EAs





        share|improve this answer








        New contributor




        cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        I do not understand because it seems to work for others, but the rsync method fails for me on FreeBSD with ZFS. Nothing happens. However Jean-François Dockes’s method works. (see: https://www.lesbonscomptes.com/pxattr/ ) Source directory = A & destination directory = B, from the original question.



        pxattr -lR A > tmp.EAs


        (edit the first line of tmp.EAs to change the A directory to B, s/A/B/)



        pxattr -S tmp.EAs






        share|improve this answer








        New contributor




        cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer






        New contributor




        cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered 12 mins ago









        cira

        1




        1




        New contributor




        cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        cira is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















            up vote
            -3
            down vote













            You need the "-r" for copying a directory.






            share|improve this answer
















            • 2




              I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
              – tripledes
              Jul 29 '12 at 20:38










            • -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
              – Grzegorz Wierzowiecki
              Jul 29 '12 at 21:20














            up vote
            -3
            down vote













            You need the "-r" for copying a directory.






            share|improve this answer
















            • 2




              I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
              – tripledes
              Jul 29 '12 at 20:38










            • -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
              – Grzegorz Wierzowiecki
              Jul 29 '12 at 21:20












            up vote
            -3
            down vote










            up vote
            -3
            down vote









            You need the "-r" for copying a directory.






            share|improve this answer












            You need the "-r" for copying a directory.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jul 29 '12 at 19:59









            tripledes

            1,01779




            1,01779







            • 2




              I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
              – tripledes
              Jul 29 '12 at 20:38










            • -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
              – Grzegorz Wierzowiecki
              Jul 29 '12 at 21:20












            • 2




              I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
              – tripledes
              Jul 29 '12 at 20:38










            • -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
              – Grzegorz Wierzowiecki
              Jul 29 '12 at 21:20







            2




            2




            I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
            – tripledes
            Jul 29 '12 at 20:38




            I think I misunderstood you, you don't need the contents, just the xattr. If it was for SELinux, you could use chcon referencing the original directory (A).
            – tripledes
            Jul 29 '12 at 20:38












            -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
            – Grzegorz Wierzowiecki
            Jul 29 '12 at 21:20




            -r implies copy of all subdirectories and files in them... I do not want to copy whole tree... I want to copy attributes for only one and only one directory - without affecting it's contents.
            – Grzegorz Wierzowiecki
            Jul 29 '12 at 21:20

















             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f44253%2fhow-to-clone-copy-all-file-directory-attributes-onto-different-file-directory%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)