How do I copy all the files containing “t_1” in the name to a different directory using one command?












0















How do I copy all the files with "t_1" in the name to a different directory using one command?










share|improve this question
















bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    cp "*t_1*" /target/dir/...

    – jasonwryan
    Sep 24 '16 at 0:58













  • @jasonwryan it is saying "cp: cannot stat ‘t_1’: No such file or directory"

    – Jarhead
    Sep 24 '16 at 1:05











  • Are you in a directory that includes at least one file with t_1 in the name?

    – jasonwryan
    Sep 24 '16 at 1:15











  • Yes because I can do ls | grep "t_1" and files show up. There are 4.

    – Jarhead
    Sep 24 '16 at 1:22






  • 2





    Remove the quotes: *t_1*...

    – jasonwryan
    Sep 24 '16 at 1:26
















0















How do I copy all the files with "t_1" in the name to a different directory using one command?










share|improve this question
















bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    cp "*t_1*" /target/dir/...

    – jasonwryan
    Sep 24 '16 at 0:58













  • @jasonwryan it is saying "cp: cannot stat ‘t_1’: No such file or directory"

    – Jarhead
    Sep 24 '16 at 1:05











  • Are you in a directory that includes at least one file with t_1 in the name?

    – jasonwryan
    Sep 24 '16 at 1:15











  • Yes because I can do ls | grep "t_1" and files show up. There are 4.

    – Jarhead
    Sep 24 '16 at 1:22






  • 2





    Remove the quotes: *t_1*...

    – jasonwryan
    Sep 24 '16 at 1:26














0












0








0








How do I copy all the files with "t_1" in the name to a different directory using one command?










share|improve this question
















How do I copy all the files with "t_1" in the name to a different directory using one command?







files wildcards cp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 20 '18 at 7:16









Rui F Ribeiro

40.3k1479137




40.3k1479137










asked Sep 24 '16 at 0:46









JarheadJarhead

61




61





bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 37 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 2





    cp "*t_1*" /target/dir/...

    – jasonwryan
    Sep 24 '16 at 0:58













  • @jasonwryan it is saying "cp: cannot stat ‘t_1’: No such file or directory"

    – Jarhead
    Sep 24 '16 at 1:05











  • Are you in a directory that includes at least one file with t_1 in the name?

    – jasonwryan
    Sep 24 '16 at 1:15











  • Yes because I can do ls | grep "t_1" and files show up. There are 4.

    – Jarhead
    Sep 24 '16 at 1:22






  • 2





    Remove the quotes: *t_1*...

    – jasonwryan
    Sep 24 '16 at 1:26














  • 2





    cp "*t_1*" /target/dir/...

    – jasonwryan
    Sep 24 '16 at 0:58













  • @jasonwryan it is saying "cp: cannot stat ‘t_1’: No such file or directory"

    – Jarhead
    Sep 24 '16 at 1:05











  • Are you in a directory that includes at least one file with t_1 in the name?

    – jasonwryan
    Sep 24 '16 at 1:15











  • Yes because I can do ls | grep "t_1" and files show up. There are 4.

    – Jarhead
    Sep 24 '16 at 1:22






  • 2





    Remove the quotes: *t_1*...

    – jasonwryan
    Sep 24 '16 at 1:26








2




2





cp "*t_1*" /target/dir/...

– jasonwryan
Sep 24 '16 at 0:58







cp "*t_1*" /target/dir/...

– jasonwryan
Sep 24 '16 at 0:58















@jasonwryan it is saying "cp: cannot stat ‘t_1’: No such file or directory"

– Jarhead
Sep 24 '16 at 1:05





@jasonwryan it is saying "cp: cannot stat ‘t_1’: No such file or directory"

– Jarhead
Sep 24 '16 at 1:05













Are you in a directory that includes at least one file with t_1 in the name?

– jasonwryan
Sep 24 '16 at 1:15





Are you in a directory that includes at least one file with t_1 in the name?

– jasonwryan
Sep 24 '16 at 1:15













Yes because I can do ls | grep "t_1" and files show up. There are 4.

– Jarhead
Sep 24 '16 at 1:22





Yes because I can do ls | grep "t_1" and files show up. There are 4.

– Jarhead
Sep 24 '16 at 1:22




2




2





Remove the quotes: *t_1*...

– jasonwryan
Sep 24 '16 at 1:26





Remove the quotes: *t_1*...

– jasonwryan
Sep 24 '16 at 1:26










2 Answers
2






active

oldest

votes


















0














Here is a quick fix..



find ./ -name '*t_1*' -exec mv '{}' ./ ;


This code will move all the files (containing the search pattern in the file name) one level up the hierarchy.



For example, Let's say that all your 't_1' files are stored in /Home/Desktop/ directory. Then just go to /Home/ from terminal and execute this command. All the 't_1' files will be moved from /home/Desktop/ to /home/ directory.



All the files irrespective of the position of t_1 in the filename will be copied.






share|improve this answer
























  • just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

    – Upendra Pratap Singh
    Sep 24 '16 at 6:03













  • once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

    – Upendra Pratap Singh
    Sep 24 '16 at 6:09



















-1














Try cp /path/to/files/*t_1* /path/to/destination
That should work.



Or:
for f in ./*t_1*; do
cp "$f" /path/to/destination
done



That should work for sure.






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%2f311984%2fhow-do-i-copy-all-the-files-containing-t-1-in-the-name-to-a-different-director%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









    0














    Here is a quick fix..



    find ./ -name '*t_1*' -exec mv '{}' ./ ;


    This code will move all the files (containing the search pattern in the file name) one level up the hierarchy.



    For example, Let's say that all your 't_1' files are stored in /Home/Desktop/ directory. Then just go to /Home/ from terminal and execute this command. All the 't_1' files will be moved from /home/Desktop/ to /home/ directory.



    All the files irrespective of the position of t_1 in the filename will be copied.






    share|improve this answer
























    • just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

      – Upendra Pratap Singh
      Sep 24 '16 at 6:03













    • once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

      – Upendra Pratap Singh
      Sep 24 '16 at 6:09
















    0














    Here is a quick fix..



    find ./ -name '*t_1*' -exec mv '{}' ./ ;


    This code will move all the files (containing the search pattern in the file name) one level up the hierarchy.



    For example, Let's say that all your 't_1' files are stored in /Home/Desktop/ directory. Then just go to /Home/ from terminal and execute this command. All the 't_1' files will be moved from /home/Desktop/ to /home/ directory.



    All the files irrespective of the position of t_1 in the filename will be copied.






    share|improve this answer
























    • just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

      – Upendra Pratap Singh
      Sep 24 '16 at 6:03













    • once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

      – Upendra Pratap Singh
      Sep 24 '16 at 6:09














    0












    0








    0







    Here is a quick fix..



    find ./ -name '*t_1*' -exec mv '{}' ./ ;


    This code will move all the files (containing the search pattern in the file name) one level up the hierarchy.



    For example, Let's say that all your 't_1' files are stored in /Home/Desktop/ directory. Then just go to /Home/ from terminal and execute this command. All the 't_1' files will be moved from /home/Desktop/ to /home/ directory.



    All the files irrespective of the position of t_1 in the filename will be copied.






    share|improve this answer













    Here is a quick fix..



    find ./ -name '*t_1*' -exec mv '{}' ./ ;


    This code will move all the files (containing the search pattern in the file name) one level up the hierarchy.



    For example, Let's say that all your 't_1' files are stored in /Home/Desktop/ directory. Then just go to /Home/ from terminal and execute this command. All the 't_1' files will be moved from /home/Desktop/ to /home/ directory.



    All the files irrespective of the position of t_1 in the filename will be copied.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Sep 24 '16 at 6:01









    Upendra Pratap SinghUpendra Pratap Singh

    2311211




    2311211













    • just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

      – Upendra Pratap Singh
      Sep 24 '16 at 6:03













    • once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

      – Upendra Pratap Singh
      Sep 24 '16 at 6:09



















    • just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

      – Upendra Pratap Singh
      Sep 24 '16 at 6:03













    • once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

      – Upendra Pratap Singh
      Sep 24 '16 at 6:09

















    just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

    – Upendra Pratap Singh
    Sep 24 '16 at 6:03







    just copy the command as it is....presence or absence of a whitespace will affect the results. I have tried and tested this command before posting this answer

    – Upendra Pratap Singh
    Sep 24 '16 at 6:03















    once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

    – Upendra Pratap Singh
    Sep 24 '16 at 6:09





    once you have all your files in the parent folder, you can move the entire parent folder wherever you wish

    – Upendra Pratap Singh
    Sep 24 '16 at 6:09













    -1














    Try cp /path/to/files/*t_1* /path/to/destination
    That should work.



    Or:
    for f in ./*t_1*; do
    cp "$f" /path/to/destination
    done



    That should work for sure.






    share|improve this answer






























      -1














      Try cp /path/to/files/*t_1* /path/to/destination
      That should work.



      Or:
      for f in ./*t_1*; do
      cp "$f" /path/to/destination
      done



      That should work for sure.






      share|improve this answer




























        -1












        -1








        -1







        Try cp /path/to/files/*t_1* /path/to/destination
        That should work.



        Or:
        for f in ./*t_1*; do
        cp "$f" /path/to/destination
        done



        That should work for sure.






        share|improve this answer















        Try cp /path/to/files/*t_1* /path/to/destination
        That should work.



        Or:
        for f in ./*t_1*; do
        cp "$f" /path/to/destination
        done



        That should work for sure.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Sep 24 '16 at 4:45

























        answered Sep 24 '16 at 4:36









        NapoleonTheCakeNapoleonTheCake

        7218




        7218






























            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%2f311984%2fhow-do-i-copy-all-the-files-containing-t-1-in-the-name-to-a-different-director%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

            Histoire des bourses de valeurs

            Why is there Russian traffic in my log files?

            Rename multiple files to decrement number in file name?