Purpose of cp -x (stay on file system)?











up vote
24
down vote

favorite
2












If I wanted to stay on the same file system, couldn't I just specify an output path for the same file system?



Or is it to prevent accidentally leaving the current file system?










share|improve this question


















  • 1




    -x in a different context: unix.stackexchange.com/a/358331/30851 but same for cp: -x skips things, if you are migrating filesystems and would like it to be a complete copy, consider mounting in a way that gives you the full picture.
    – frostschutz
    Nov 28 at 13:51






  • 1




    You could ask the same about many flags, eg -i: "why not just specify a destination that doesn't exist"?
    – JigglyNaga
    Nov 28 at 14:58






  • 1




    @JigglyNaga I was thinking that as well. But -x was not phrased well in the documentation and far less obvious.
    – neverMind9
    Nov 28 at 18:53

















up vote
24
down vote

favorite
2












If I wanted to stay on the same file system, couldn't I just specify an output path for the same file system?



Or is it to prevent accidentally leaving the current file system?










share|improve this question


















  • 1




    -x in a different context: unix.stackexchange.com/a/358331/30851 but same for cp: -x skips things, if you are migrating filesystems and would like it to be a complete copy, consider mounting in a way that gives you the full picture.
    – frostschutz
    Nov 28 at 13:51






  • 1




    You could ask the same about many flags, eg -i: "why not just specify a destination that doesn't exist"?
    – JigglyNaga
    Nov 28 at 14:58






  • 1




    @JigglyNaga I was thinking that as well. But -x was not phrased well in the documentation and far less obvious.
    – neverMind9
    Nov 28 at 18:53















up vote
24
down vote

favorite
2









up vote
24
down vote

favorite
2






2





If I wanted to stay on the same file system, couldn't I just specify an output path for the same file system?



Or is it to prevent accidentally leaving the current file system?










share|improve this question













If I wanted to stay on the same file system, couldn't I just specify an output path for the same file system?



Or is it to prevent accidentally leaving the current file system?







command-line files filesystems cp data






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 at 13:02









neverMind9

497113




497113








  • 1




    -x in a different context: unix.stackexchange.com/a/358331/30851 but same for cp: -x skips things, if you are migrating filesystems and would like it to be a complete copy, consider mounting in a way that gives you the full picture.
    – frostschutz
    Nov 28 at 13:51






  • 1




    You could ask the same about many flags, eg -i: "why not just specify a destination that doesn't exist"?
    – JigglyNaga
    Nov 28 at 14:58






  • 1




    @JigglyNaga I was thinking that as well. But -x was not phrased well in the documentation and far less obvious.
    – neverMind9
    Nov 28 at 18:53
















  • 1




    -x in a different context: unix.stackexchange.com/a/358331/30851 but same for cp: -x skips things, if you are migrating filesystems and would like it to be a complete copy, consider mounting in a way that gives you the full picture.
    – frostschutz
    Nov 28 at 13:51






  • 1




    You could ask the same about many flags, eg -i: "why not just specify a destination that doesn't exist"?
    – JigglyNaga
    Nov 28 at 14:58






  • 1




    @JigglyNaga I was thinking that as well. But -x was not phrased well in the documentation and far less obvious.
    – neverMind9
    Nov 28 at 18:53










1




1




-x in a different context: unix.stackexchange.com/a/358331/30851 but same for cp: -x skips things, if you are migrating filesystems and would like it to be a complete copy, consider mounting in a way that gives you the full picture.
– frostschutz
Nov 28 at 13:51




-x in a different context: unix.stackexchange.com/a/358331/30851 but same for cp: -x skips things, if you are migrating filesystems and would like it to be a complete copy, consider mounting in a way that gives you the full picture.
– frostschutz
Nov 28 at 13:51




1




1




You could ask the same about many flags, eg -i: "why not just specify a destination that doesn't exist"?
– JigglyNaga
Nov 28 at 14:58




You could ask the same about many flags, eg -i: "why not just specify a destination that doesn't exist"?
– JigglyNaga
Nov 28 at 14:58




1




1




@JigglyNaga I was thinking that as well. But -x was not phrased well in the documentation and far less obvious.
– neverMind9
Nov 28 at 18:53






@JigglyNaga I was thinking that as well. But -x was not phrased well in the documentation and far less obvious.
– neverMind9
Nov 28 at 18:53












2 Answers
2






active

oldest

votes

















up vote
57
down vote



accepted










It limits where files are copied from, not where they’re copied to. It’s useful with recursive copies, to control how cp descends into subdirectories. Thus



cp -xr / blah


will only copy the root file system, not any of the other file systems mounted.



See the cp -x documentation (although its distinction is subtle).






share|improve this answer

















  • 3




    Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
    – mckenzm
    Nov 29 at 4:23






  • 1




    @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
    – slebetman
    2 days ago










  • Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
    – Lassi
    2 days ago






  • 3




    It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
    – Stephen Kitt
    2 days ago


















up vote
25
down vote













The -x flag to cp is a GNU extension. When copying a single file, this option will have no effect, but when copying a whole file hierarchy, the -x option prevents the copying of files and directories that do not live on the same filesystem as the original source.



For example, on a filesystem with mount points at /usr and /usr/local, using cp -xR /usr /some-dest would not copy the hierarchy under /usr/local.



There are other utilities with an -x option with similar semantics, such as du and find (the flag is called -xdev for find), and rsync.






share|improve this answer























    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: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f484655%2fpurpose-of-cp-x-stay-on-file-system%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    57
    down vote



    accepted










    It limits where files are copied from, not where they’re copied to. It’s useful with recursive copies, to control how cp descends into subdirectories. Thus



    cp -xr / blah


    will only copy the root file system, not any of the other file systems mounted.



    See the cp -x documentation (although its distinction is subtle).






    share|improve this answer

















    • 3




      Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
      – mckenzm
      Nov 29 at 4:23






    • 1




      @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
      – slebetman
      2 days ago










    • Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
      – Lassi
      2 days ago






    • 3




      It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
      – Stephen Kitt
      2 days ago















    up vote
    57
    down vote



    accepted










    It limits where files are copied from, not where they’re copied to. It’s useful with recursive copies, to control how cp descends into subdirectories. Thus



    cp -xr / blah


    will only copy the root file system, not any of the other file systems mounted.



    See the cp -x documentation (although its distinction is subtle).






    share|improve this answer

















    • 3




      Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
      – mckenzm
      Nov 29 at 4:23






    • 1




      @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
      – slebetman
      2 days ago










    • Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
      – Lassi
      2 days ago






    • 3




      It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
      – Stephen Kitt
      2 days ago













    up vote
    57
    down vote



    accepted







    up vote
    57
    down vote



    accepted






    It limits where files are copied from, not where they’re copied to. It’s useful with recursive copies, to control how cp descends into subdirectories. Thus



    cp -xr / blah


    will only copy the root file system, not any of the other file systems mounted.



    See the cp -x documentation (although its distinction is subtle).






    share|improve this answer












    It limits where files are copied from, not where they’re copied to. It’s useful with recursive copies, to control how cp descends into subdirectories. Thus



    cp -xr / blah


    will only copy the root file system, not any of the other file systems mounted.



    See the cp -x documentation (although its distinction is subtle).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 28 at 13:06









    Stephen Kitt

    159k24354430




    159k24354430








    • 3




      Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
      – mckenzm
      Nov 29 at 4:23






    • 1




      @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
      – slebetman
      2 days ago










    • Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
      – Lassi
      2 days ago






    • 3




      It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
      – Stephen Kitt
      2 days ago














    • 3




      Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
      – mckenzm
      Nov 29 at 4:23






    • 1




      @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
      – slebetman
      2 days ago










    • Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
      – Lassi
      2 days ago






    • 3




      It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
      – Stephen Kitt
      2 days ago








    3




    3




    Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
    – mckenzm
    Nov 29 at 4:23




    Oh yes, you might not want to copy network shares under /mnt. Nor a remote RCS repository mounted under your home drive.
    – mckenzm
    Nov 29 at 4:23




    1




    1




    @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
    – slebetman
    2 days ago




    @mckenzm Also because /mnt is only a human convention sometimes enforced by a distro's setup but not a requirement of the OS. I sometimes have network filesystems mounted under /var/somewebsite/www/sessions to implement load balancing web servers
    – slebetman
    2 days ago












    Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
    – Lassi
    2 days ago




    Indeed, this kind of flag prevents accidentally copying huge network shares or removable media that you forgot you had mounted. And you don't need to give --exclude options to manually block each of them. Very useful with rsync.
    – Lassi
    2 days ago




    3




    3




    It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
    – Stephen Kitt
    2 days ago




    It also avoids copying file systems such as /dev, /proc, /sys etc. which you typically don’t want to read “en masse”.
    – Stephen Kitt
    2 days ago












    up vote
    25
    down vote













    The -x flag to cp is a GNU extension. When copying a single file, this option will have no effect, but when copying a whole file hierarchy, the -x option prevents the copying of files and directories that do not live on the same filesystem as the original source.



    For example, on a filesystem with mount points at /usr and /usr/local, using cp -xR /usr /some-dest would not copy the hierarchy under /usr/local.



    There are other utilities with an -x option with similar semantics, such as du and find (the flag is called -xdev for find), and rsync.






    share|improve this answer



























      up vote
      25
      down vote













      The -x flag to cp is a GNU extension. When copying a single file, this option will have no effect, but when copying a whole file hierarchy, the -x option prevents the copying of files and directories that do not live on the same filesystem as the original source.



      For example, on a filesystem with mount points at /usr and /usr/local, using cp -xR /usr /some-dest would not copy the hierarchy under /usr/local.



      There are other utilities with an -x option with similar semantics, such as du and find (the flag is called -xdev for find), and rsync.






      share|improve this answer

























        up vote
        25
        down vote










        up vote
        25
        down vote









        The -x flag to cp is a GNU extension. When copying a single file, this option will have no effect, but when copying a whole file hierarchy, the -x option prevents the copying of files and directories that do not live on the same filesystem as the original source.



        For example, on a filesystem with mount points at /usr and /usr/local, using cp -xR /usr /some-dest would not copy the hierarchy under /usr/local.



        There are other utilities with an -x option with similar semantics, such as du and find (the flag is called -xdev for find), and rsync.






        share|improve this answer














        The -x flag to cp is a GNU extension. When copying a single file, this option will have no effect, but when copying a whole file hierarchy, the -x option prevents the copying of files and directories that do not live on the same filesystem as the original source.



        For example, on a filesystem with mount points at /usr and /usr/local, using cp -xR /usr /some-dest would not copy the hierarchy under /usr/local.



        There are other utilities with an -x option with similar semantics, such as du and find (the flag is called -xdev for find), and rsync.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 29 at 9:05









        Sergiy Kolodyazhnyy

        8,12212151




        8,12212151










        answered Nov 28 at 13:08









        Kusalananda

        118k16223361




        118k16223361






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484655%2fpurpose-of-cp-x-stay-on-file-system%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AnyDesk - Fatal Program Failure

            How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

            QoS: MAC-Priority for clients behind a repeater