Copying [use of cp] issue

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












5















I have a couple of sub-folders mounted on /mnt. One is /mnt/data, and the other is /mnt/1804iso. The /data includes data folders and files mounted from another disk, and /1804iso includes a mounted ISO file whose contents I wanted to copy to folder /media/benny/0EB4-95E2/ which is a mounted flash-drive.



So I opened bash and typed sudo cp -Rn /mnt/1804iso/.* /media/benny/0EB4-95E2/. I would normally have omitted the period before wildcard asterisk /*/, but if I do that then a hidden file within the ISO does not copy over. So with this command one strange thing occurred. After copying over the ISO files correctly, then it started to copy over the /mnt/data folders and files as well. I cannot see why that can happen as there is no reference to that folder, unless my understanding of the command part /mnt/1804iso/.* is totally flawed.



Could someone kindly explain why my /mnt/data folder was included for copying?










share|improve this question



















  • 2





    Possibly related: command .* acts on the parent directory

    – steeldriver
    Feb 10 at 20:22






  • 1





    Yes there is a reference: every directory contains .. a reference to its parent directory.

    – ctrl-alt-delor
    Feb 10 at 20:22











  • See also the nice discussion at Linux command line: glob confusion

    – steeldriver
    Feb 10 at 20:25











  • shopt -s dotglob, will make * also match most files starting with a ., but not . and ...

    – ctrl-alt-delor
    Feb 10 at 20:26















5















I have a couple of sub-folders mounted on /mnt. One is /mnt/data, and the other is /mnt/1804iso. The /data includes data folders and files mounted from another disk, and /1804iso includes a mounted ISO file whose contents I wanted to copy to folder /media/benny/0EB4-95E2/ which is a mounted flash-drive.



So I opened bash and typed sudo cp -Rn /mnt/1804iso/.* /media/benny/0EB4-95E2/. I would normally have omitted the period before wildcard asterisk /*/, but if I do that then a hidden file within the ISO does not copy over. So with this command one strange thing occurred. After copying over the ISO files correctly, then it started to copy over the /mnt/data folders and files as well. I cannot see why that can happen as there is no reference to that folder, unless my understanding of the command part /mnt/1804iso/.* is totally flawed.



Could someone kindly explain why my /mnt/data folder was included for copying?










share|improve this question



















  • 2





    Possibly related: command .* acts on the parent directory

    – steeldriver
    Feb 10 at 20:22






  • 1





    Yes there is a reference: every directory contains .. a reference to its parent directory.

    – ctrl-alt-delor
    Feb 10 at 20:22











  • See also the nice discussion at Linux command line: glob confusion

    – steeldriver
    Feb 10 at 20:25











  • shopt -s dotglob, will make * also match most files starting with a ., but not . and ...

    – ctrl-alt-delor
    Feb 10 at 20:26













5












5








5








I have a couple of sub-folders mounted on /mnt. One is /mnt/data, and the other is /mnt/1804iso. The /data includes data folders and files mounted from another disk, and /1804iso includes a mounted ISO file whose contents I wanted to copy to folder /media/benny/0EB4-95E2/ which is a mounted flash-drive.



So I opened bash and typed sudo cp -Rn /mnt/1804iso/.* /media/benny/0EB4-95E2/. I would normally have omitted the period before wildcard asterisk /*/, but if I do that then a hidden file within the ISO does not copy over. So with this command one strange thing occurred. After copying over the ISO files correctly, then it started to copy over the /mnt/data folders and files as well. I cannot see why that can happen as there is no reference to that folder, unless my understanding of the command part /mnt/1804iso/.* is totally flawed.



Could someone kindly explain why my /mnt/data folder was included for copying?










share|improve this question
















I have a couple of sub-folders mounted on /mnt. One is /mnt/data, and the other is /mnt/1804iso. The /data includes data folders and files mounted from another disk, and /1804iso includes a mounted ISO file whose contents I wanted to copy to folder /media/benny/0EB4-95E2/ which is a mounted flash-drive.



So I opened bash and typed sudo cp -Rn /mnt/1804iso/.* /media/benny/0EB4-95E2/. I would normally have omitted the period before wildcard asterisk /*/, but if I do that then a hidden file within the ISO does not copy over. So with this command one strange thing occurred. After copying over the ISO files correctly, then it started to copy over the /mnt/data folders and files as well. I cannot see why that can happen as there is no reference to that folder, unless my understanding of the command part /mnt/1804iso/.* is totally flawed.



Could someone kindly explain why my /mnt/data folder was included for copying?







bash cp gnome-shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 10 at 20:07









Michael Homer

49.4k8133172




49.4k8133172










asked Feb 10 at 20:02









Paul BensonPaul Benson

1262




1262







  • 2





    Possibly related: command .* acts on the parent directory

    – steeldriver
    Feb 10 at 20:22






  • 1





    Yes there is a reference: every directory contains .. a reference to its parent directory.

    – ctrl-alt-delor
    Feb 10 at 20:22











  • See also the nice discussion at Linux command line: glob confusion

    – steeldriver
    Feb 10 at 20:25











  • shopt -s dotglob, will make * also match most files starting with a ., but not . and ...

    – ctrl-alt-delor
    Feb 10 at 20:26












  • 2





    Possibly related: command .* acts on the parent directory

    – steeldriver
    Feb 10 at 20:22






  • 1





    Yes there is a reference: every directory contains .. a reference to its parent directory.

    – ctrl-alt-delor
    Feb 10 at 20:22











  • See also the nice discussion at Linux command line: glob confusion

    – steeldriver
    Feb 10 at 20:25











  • shopt -s dotglob, will make * also match most files starting with a ., but not . and ...

    – ctrl-alt-delor
    Feb 10 at 20:26







2




2





Possibly related: command .* acts on the parent directory

– steeldriver
Feb 10 at 20:22





Possibly related: command .* acts on the parent directory

– steeldriver
Feb 10 at 20:22




1




1





Yes there is a reference: every directory contains .. a reference to its parent directory.

– ctrl-alt-delor
Feb 10 at 20:22





Yes there is a reference: every directory contains .. a reference to its parent directory.

– ctrl-alt-delor
Feb 10 at 20:22













See also the nice discussion at Linux command line: glob confusion

– steeldriver
Feb 10 at 20:25





See also the nice discussion at Linux command line: glob confusion

– steeldriver
Feb 10 at 20:25













shopt -s dotglob, will make * also match most files starting with a ., but not . and ...

– ctrl-alt-delor
Feb 10 at 20:26





shopt -s dotglob, will make * also match most files starting with a ., but not . and ...

– ctrl-alt-delor
Feb 10 at 20:26










2 Answers
2






active

oldest

votes


















9














.* will expand to your hidden file, ., and ... This is an unfortunate part of how Bash filename expansion works: there is a directory entry called .., which consists of an initial . and then any number of characters after it, so it's matched by .* and included.



You can see this happen by running e.g.:



echo /mnt/1804iso/.*


which will list out /mnt/1804iso/. and /mnt/1804iso/.. along with the rest.



../data is your data directory. You will end up with a directory structure in the destination like this:



.hidden
xyz
data/
data/...
1804iso/.hidden
1804iso/xyz
...


That is, you'll actually end up with two copies of everything you wanted to copy, plus all that stuff you didn't. If you use cp -Rnv you'll see what it's copying and where to as it goes.



Some other shells will be nicer about this. In zsh, it would have done closer to what you want: only the hidden file would have been copied. In Bash, you could use cp src/.[^.]* dest to almost match the zsh behaviour, and list two source locations. Alternatively, you can run shopt -s dotglob beforehand, and then src/* will expand to include the dotfiles, but exclude the . and .. entries (but this may lead to doing things you didn't mean to later on, so be careful).




For what you actually wanted to do, I suggest using rsync instead:



rsync -avx /mnt/1804iso/ /media/benny/0EB4-95E2/


This will copy the contents of the 1804iso directory to the destination (note final slash!), including any hidden files.






share|improve this answer




















  • 1





    I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

    – Paul Benson
    Feb 10 at 21:06












  • Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

    – Michael Homer
    Feb 10 at 21:09











  • Your bash example is not quite equivalent, since it would miss a file named ..foo

    – Nate Eldredge
    Feb 11 at 1:14











  • @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

    – Michael Homer
    Feb 11 at 1:16











  • I think .[^.]* ..?* would work.

    – Nate Eldredge
    Feb 11 at 1:32


















3














The pattern /mnt/1804iso/.* expands to, amongst possibly other things, the directory entry /mnt/1804iso/.., which is the same as /mnt. I'm geussing that's why it started copying /mnt/data.



In this case, I would just use rsync:



rsync -ai /mnt/1804iso/ /media/benny/0EB4-95E2


This would copy all of /mnt/1804iso, including hidden files, into /media/benny/0EB4-95E2. Leaving off the / at the end of the source directory would create a 1804iso directory below the target directory.



Alternatively, enable the dotglob shell option in bash with shopt -s dotglob to make * match hidden names as well as non-hidden names (but not . or ..). Then use



cp -Rn /mnt/1804iso/* /media/benny/0EB4-95E2/





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',
    autoActivateHeartbeat: false,
    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%2f499811%2fcopying-use-of-cp-issue%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









    9














    .* will expand to your hidden file, ., and ... This is an unfortunate part of how Bash filename expansion works: there is a directory entry called .., which consists of an initial . and then any number of characters after it, so it's matched by .* and included.



    You can see this happen by running e.g.:



    echo /mnt/1804iso/.*


    which will list out /mnt/1804iso/. and /mnt/1804iso/.. along with the rest.



    ../data is your data directory. You will end up with a directory structure in the destination like this:



    .hidden
    xyz
    data/
    data/...
    1804iso/.hidden
    1804iso/xyz
    ...


    That is, you'll actually end up with two copies of everything you wanted to copy, plus all that stuff you didn't. If you use cp -Rnv you'll see what it's copying and where to as it goes.



    Some other shells will be nicer about this. In zsh, it would have done closer to what you want: only the hidden file would have been copied. In Bash, you could use cp src/.[^.]* dest to almost match the zsh behaviour, and list two source locations. Alternatively, you can run shopt -s dotglob beforehand, and then src/* will expand to include the dotfiles, but exclude the . and .. entries (but this may lead to doing things you didn't mean to later on, so be careful).




    For what you actually wanted to do, I suggest using rsync instead:



    rsync -avx /mnt/1804iso/ /media/benny/0EB4-95E2/


    This will copy the contents of the 1804iso directory to the destination (note final slash!), including any hidden files.






    share|improve this answer




















    • 1





      I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

      – Paul Benson
      Feb 10 at 21:06












    • Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

      – Michael Homer
      Feb 10 at 21:09











    • Your bash example is not quite equivalent, since it would miss a file named ..foo

      – Nate Eldredge
      Feb 11 at 1:14











    • @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

      – Michael Homer
      Feb 11 at 1:16











    • I think .[^.]* ..?* would work.

      – Nate Eldredge
      Feb 11 at 1:32















    9














    .* will expand to your hidden file, ., and ... This is an unfortunate part of how Bash filename expansion works: there is a directory entry called .., which consists of an initial . and then any number of characters after it, so it's matched by .* and included.



    You can see this happen by running e.g.:



    echo /mnt/1804iso/.*


    which will list out /mnt/1804iso/. and /mnt/1804iso/.. along with the rest.



    ../data is your data directory. You will end up with a directory structure in the destination like this:



    .hidden
    xyz
    data/
    data/...
    1804iso/.hidden
    1804iso/xyz
    ...


    That is, you'll actually end up with two copies of everything you wanted to copy, plus all that stuff you didn't. If you use cp -Rnv you'll see what it's copying and where to as it goes.



    Some other shells will be nicer about this. In zsh, it would have done closer to what you want: only the hidden file would have been copied. In Bash, you could use cp src/.[^.]* dest to almost match the zsh behaviour, and list two source locations. Alternatively, you can run shopt -s dotglob beforehand, and then src/* will expand to include the dotfiles, but exclude the . and .. entries (but this may lead to doing things you didn't mean to later on, so be careful).




    For what you actually wanted to do, I suggest using rsync instead:



    rsync -avx /mnt/1804iso/ /media/benny/0EB4-95E2/


    This will copy the contents of the 1804iso directory to the destination (note final slash!), including any hidden files.






    share|improve this answer




















    • 1





      I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

      – Paul Benson
      Feb 10 at 21:06












    • Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

      – Michael Homer
      Feb 10 at 21:09











    • Your bash example is not quite equivalent, since it would miss a file named ..foo

      – Nate Eldredge
      Feb 11 at 1:14











    • @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

      – Michael Homer
      Feb 11 at 1:16











    • I think .[^.]* ..?* would work.

      – Nate Eldredge
      Feb 11 at 1:32













    9












    9








    9







    .* will expand to your hidden file, ., and ... This is an unfortunate part of how Bash filename expansion works: there is a directory entry called .., which consists of an initial . and then any number of characters after it, so it's matched by .* and included.



    You can see this happen by running e.g.:



    echo /mnt/1804iso/.*


    which will list out /mnt/1804iso/. and /mnt/1804iso/.. along with the rest.



    ../data is your data directory. You will end up with a directory structure in the destination like this:



    .hidden
    xyz
    data/
    data/...
    1804iso/.hidden
    1804iso/xyz
    ...


    That is, you'll actually end up with two copies of everything you wanted to copy, plus all that stuff you didn't. If you use cp -Rnv you'll see what it's copying and where to as it goes.



    Some other shells will be nicer about this. In zsh, it would have done closer to what you want: only the hidden file would have been copied. In Bash, you could use cp src/.[^.]* dest to almost match the zsh behaviour, and list two source locations. Alternatively, you can run shopt -s dotglob beforehand, and then src/* will expand to include the dotfiles, but exclude the . and .. entries (but this may lead to doing things you didn't mean to later on, so be careful).




    For what you actually wanted to do, I suggest using rsync instead:



    rsync -avx /mnt/1804iso/ /media/benny/0EB4-95E2/


    This will copy the contents of the 1804iso directory to the destination (note final slash!), including any hidden files.






    share|improve this answer















    .* will expand to your hidden file, ., and ... This is an unfortunate part of how Bash filename expansion works: there is a directory entry called .., which consists of an initial . and then any number of characters after it, so it's matched by .* and included.



    You can see this happen by running e.g.:



    echo /mnt/1804iso/.*


    which will list out /mnt/1804iso/. and /mnt/1804iso/.. along with the rest.



    ../data is your data directory. You will end up with a directory structure in the destination like this:



    .hidden
    xyz
    data/
    data/...
    1804iso/.hidden
    1804iso/xyz
    ...


    That is, you'll actually end up with two copies of everything you wanted to copy, plus all that stuff you didn't. If you use cp -Rnv you'll see what it's copying and where to as it goes.



    Some other shells will be nicer about this. In zsh, it would have done closer to what you want: only the hidden file would have been copied. In Bash, you could use cp src/.[^.]* dest to almost match the zsh behaviour, and list two source locations. Alternatively, you can run shopt -s dotglob beforehand, and then src/* will expand to include the dotfiles, but exclude the . and .. entries (but this may lead to doing things you didn't mean to later on, so be careful).




    For what you actually wanted to do, I suggest using rsync instead:



    rsync -avx /mnt/1804iso/ /media/benny/0EB4-95E2/


    This will copy the contents of the 1804iso directory to the destination (note final slash!), including any hidden files.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 11 at 1:17

























    answered Feb 10 at 20:23









    Michael HomerMichael Homer

    49.4k8133172




    49.4k8133172







    • 1





      I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

      – Paul Benson
      Feb 10 at 21:06












    • Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

      – Michael Homer
      Feb 10 at 21:09











    • Your bash example is not quite equivalent, since it would miss a file named ..foo

      – Nate Eldredge
      Feb 11 at 1:14











    • @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

      – Michael Homer
      Feb 11 at 1:16











    • I think .[^.]* ..?* would work.

      – Nate Eldredge
      Feb 11 at 1:32












    • 1





      I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

      – Paul Benson
      Feb 10 at 21:06












    • Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

      – Michael Homer
      Feb 10 at 21:09











    • Your bash example is not quite equivalent, since it would miss a file named ..foo

      – Nate Eldredge
      Feb 11 at 1:14











    • @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

      – Michael Homer
      Feb 11 at 1:16











    • I think .[^.]* ..?* would work.

      – Nate Eldredge
      Feb 11 at 1:32







    1




    1





    I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

    – Paul Benson
    Feb 10 at 21:06






    I think I follow you. Because of my use of .*, I end up with an option of /mnt/1804iso/.. which is the equivalent of my parent folder /mnt in this case. So, not only does /mnt/1804iso/ get copied but everything else within /mnt Is that right? I think rsync is safer, but I tend to use that for back-ups ratrher than simple file/folder copying.

    – Paul Benson
    Feb 10 at 21:06














    Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

    – Michael Homer
    Feb 10 at 21:09





    Probably. It may depend a little on exactly how your cp implementation works (some will fail early and stop trying), but you've definitely asked it to copy 1804iso's parent directory recursively.

    – Michael Homer
    Feb 10 at 21:09













    Your bash example is not quite equivalent, since it would miss a file named ..foo

    – Nate Eldredge
    Feb 11 at 1:14





    Your bash example is not quite equivalent, since it would miss a file named ..foo

    – Nate Eldredge
    Feb 11 at 1:14













    @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

    – Michael Homer
    Feb 11 at 1:16





    @NateEldredge Good point! I... don't think that's worth fixing, but I'll note that it's not fully equivalent.

    – Michael Homer
    Feb 11 at 1:16













    I think .[^.]* ..?* would work.

    – Nate Eldredge
    Feb 11 at 1:32





    I think .[^.]* ..?* would work.

    – Nate Eldredge
    Feb 11 at 1:32













    3














    The pattern /mnt/1804iso/.* expands to, amongst possibly other things, the directory entry /mnt/1804iso/.., which is the same as /mnt. I'm geussing that's why it started copying /mnt/data.



    In this case, I would just use rsync:



    rsync -ai /mnt/1804iso/ /media/benny/0EB4-95E2


    This would copy all of /mnt/1804iso, including hidden files, into /media/benny/0EB4-95E2. Leaving off the / at the end of the source directory would create a 1804iso directory below the target directory.



    Alternatively, enable the dotglob shell option in bash with shopt -s dotglob to make * match hidden names as well as non-hidden names (but not . or ..). Then use



    cp -Rn /mnt/1804iso/* /media/benny/0EB4-95E2/





    share|improve this answer





























      3














      The pattern /mnt/1804iso/.* expands to, amongst possibly other things, the directory entry /mnt/1804iso/.., which is the same as /mnt. I'm geussing that's why it started copying /mnt/data.



      In this case, I would just use rsync:



      rsync -ai /mnt/1804iso/ /media/benny/0EB4-95E2


      This would copy all of /mnt/1804iso, including hidden files, into /media/benny/0EB4-95E2. Leaving off the / at the end of the source directory would create a 1804iso directory below the target directory.



      Alternatively, enable the dotglob shell option in bash with shopt -s dotglob to make * match hidden names as well as non-hidden names (but not . or ..). Then use



      cp -Rn /mnt/1804iso/* /media/benny/0EB4-95E2/





      share|improve this answer



























        3












        3








        3







        The pattern /mnt/1804iso/.* expands to, amongst possibly other things, the directory entry /mnt/1804iso/.., which is the same as /mnt. I'm geussing that's why it started copying /mnt/data.



        In this case, I would just use rsync:



        rsync -ai /mnt/1804iso/ /media/benny/0EB4-95E2


        This would copy all of /mnt/1804iso, including hidden files, into /media/benny/0EB4-95E2. Leaving off the / at the end of the source directory would create a 1804iso directory below the target directory.



        Alternatively, enable the dotglob shell option in bash with shopt -s dotglob to make * match hidden names as well as non-hidden names (but not . or ..). Then use



        cp -Rn /mnt/1804iso/* /media/benny/0EB4-95E2/





        share|improve this answer















        The pattern /mnt/1804iso/.* expands to, amongst possibly other things, the directory entry /mnt/1804iso/.., which is the same as /mnt. I'm geussing that's why it started copying /mnt/data.



        In this case, I would just use rsync:



        rsync -ai /mnt/1804iso/ /media/benny/0EB4-95E2


        This would copy all of /mnt/1804iso, including hidden files, into /media/benny/0EB4-95E2. Leaving off the / at the end of the source directory would create a 1804iso directory below the target directory.



        Alternatively, enable the dotglob shell option in bash with shopt -s dotglob to make * match hidden names as well as non-hidden names (but not . or ..). Then use



        cp -Rn /mnt/1804iso/* /media/benny/0EB4-95E2/






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 10 at 20:28

























        answered Feb 10 at 20:22









        KusalanandaKusalananda

        134k17254418




        134k17254418



























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f499811%2fcopying-use-of-cp-issue%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

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?