Copy a file to a folder, which has the same name as the original

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











up vote
-1
down vote

favorite












Hopefully, this should be an easy question for the experienced.



I have a list of folders (x1,x2, ..., xn) in a folder called "origin" (i.e. /origin/x1, /origin/x2 etc).



I want to take a particular file (im1.tif in my case) from each folder x1,x2, ..., xn in /origin and copy it to a folder in a destination folder called 'dest', which has the same name (i.e. /dest/x1, /dest/x2 etc).



Could someone help me with this?



Thank you!







share|improve this question




















  • idownvotedbecau.se/noattempt
    – Murphy
    Dec 22 '17 at 13:03














up vote
-1
down vote

favorite












Hopefully, this should be an easy question for the experienced.



I have a list of folders (x1,x2, ..., xn) in a folder called "origin" (i.e. /origin/x1, /origin/x2 etc).



I want to take a particular file (im1.tif in my case) from each folder x1,x2, ..., xn in /origin and copy it to a folder in a destination folder called 'dest', which has the same name (i.e. /dest/x1, /dest/x2 etc).



Could someone help me with this?



Thank you!







share|improve this question




















  • idownvotedbecau.se/noattempt
    – Murphy
    Dec 22 '17 at 13:03












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











Hopefully, this should be an easy question for the experienced.



I have a list of folders (x1,x2, ..., xn) in a folder called "origin" (i.e. /origin/x1, /origin/x2 etc).



I want to take a particular file (im1.tif in my case) from each folder x1,x2, ..., xn in /origin and copy it to a folder in a destination folder called 'dest', which has the same name (i.e. /dest/x1, /dest/x2 etc).



Could someone help me with this?



Thank you!







share|improve this question












Hopefully, this should be an easy question for the experienced.



I have a list of folders (x1,x2, ..., xn) in a folder called "origin" (i.e. /origin/x1, /origin/x2 etc).



I want to take a particular file (im1.tif in my case) from each folder x1,x2, ..., xn in /origin and copy it to a folder in a destination folder called 'dest', which has the same name (i.e. /dest/x1, /dest/x2 etc).



Could someone help me with this?



Thank you!









share|improve this question











share|improve this question




share|improve this question










asked Dec 22 '17 at 12:24









Adam Gosztolai

30036




30036











  • idownvotedbecau.se/noattempt
    – Murphy
    Dec 22 '17 at 13:03
















  • idownvotedbecau.se/noattempt
    – Murphy
    Dec 22 '17 at 13:03















idownvotedbecau.se/noattempt
– Murphy
Dec 22 '17 at 13:03




idownvotedbecau.se/noattempt
– Murphy
Dec 22 '17 at 13:03










1 Answer
1






active

oldest

votes

















up vote
0
down vote













find + bash solution:



find /origin -type f -name "*.tif" -exec bash -c 
'd="$(dirname $1)"; d=$d##*/; fn=$1##*/;
[ -d "/dest/$d" ] && cp "$1" "/dest/$d/$fn"; ' _ ;





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: 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%2f412494%2fcopy-a-file-to-a-folder-which-has-the-same-name-as-the-original%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    find + bash solution:



    find /origin -type f -name "*.tif" -exec bash -c 
    'd="$(dirname $1)"; d=$d##*/; fn=$1##*/;
    [ -d "/dest/$d" ] && cp "$1" "/dest/$d/$fn"; ' _ ;





    share|improve this answer
























      up vote
      0
      down vote













      find + bash solution:



      find /origin -type f -name "*.tif" -exec bash -c 
      'd="$(dirname $1)"; d=$d##*/; fn=$1##*/;
      [ -d "/dest/$d" ] && cp "$1" "/dest/$d/$fn"; ' _ ;





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        find + bash solution:



        find /origin -type f -name "*.tif" -exec bash -c 
        'd="$(dirname $1)"; d=$d##*/; fn=$1##*/;
        [ -d "/dest/$d" ] && cp "$1" "/dest/$d/$fn"; ' _ ;





        share|improve this answer












        find + bash solution:



        find /origin -type f -name "*.tif" -exec bash -c 
        'd="$(dirname $1)"; d=$d##*/; fn=$1##*/;
        [ -d "/dest/$d" ] && cp "$1" "/dest/$d/$fn"; ' _ ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 22 '17 at 13:03









        RomanPerekhrest

        22.4k12145




        22.4k12145






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f412494%2fcopy-a-file-to-a-folder-which-has-the-same-name-as-the-original%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

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

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay