Find, rename and copy files to a new directory

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








up vote
1
down vote

favorite












I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.



enter image description here



Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.



For instance,



14:58:31 > ycut2.gif -----(rename)--> 00.gif
15:21:39 > ycut2.gif -----(rename)--> 01.gif
15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...






share|improve this question
























    up vote
    1
    down vote

    favorite












    I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.



    enter image description here



    Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.



    For instance,



    14:58:31 > ycut2.gif -----(rename)--> 00.gif
    15:21:39 > ycut2.gif -----(rename)--> 01.gif
    15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...






    share|improve this question






















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.



      enter image description here



      Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.



      For instance,



      14:58:31 > ycut2.gif -----(rename)--> 00.gif
      15:21:39 > ycut2.gif -----(rename)--> 01.gif
      15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...






      share|improve this question












      I have 3 files under a directory that represents the time which is under a directory that represents a date. Each time directory has similar files. I'm basically saving earth's magnetosphere measurements.



      enter image description here



      Now what I'm trying to do is grab all ycut2.gif files, rename them sequentially with respect to the time and copy it to a directory ycut2 which will be located under the date directory, so I can combine them to create a gif for each day.



      For instance,



      14:58:31 > ycut2.gif -----(rename)--> 00.gif
      15:21:39 > ycut2.gif -----(rename)--> 01.gif
      15:52:30 > ycut2.gif -----(rename)--> 02.gif and so on...








      share|improve this question











      share|improve this question




      share|improve this question










      asked May 13 at 23:07









      chipChocolate.py

      1461213




      1461213




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          It's easy! You can count in bash and produce/read a list of filenames:



          declare -i num=0
          destination="$PWD" # set to destination of files
          find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
          num=$(($num + 1 ))
          # following line assumes no more than 99 files
          j=printf "%02d" $num
          cp "$fn" "$destination/$j.gif"
          done





          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "89"
            ;
            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: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2faskubuntu.com%2fquestions%2f1035886%2ffind-rename-and-copy-files-to-a-new-directory%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
            2
            down vote



            accepted










            It's easy! You can count in bash and produce/read a list of filenames:



            declare -i num=0
            destination="$PWD" # set to destination of files
            find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
            num=$(($num + 1 ))
            # following line assumes no more than 99 files
            j=printf "%02d" $num
            cp "$fn" "$destination/$j.gif"
            done





            share|improve this answer


























              up vote
              2
              down vote



              accepted










              It's easy! You can count in bash and produce/read a list of filenames:



              declare -i num=0
              destination="$PWD" # set to destination of files
              find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
              num=$(($num + 1 ))
              # following line assumes no more than 99 files
              j=printf "%02d" $num
              cp "$fn" "$destination/$j.gif"
              done





              share|improve this answer
























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                It's easy! You can count in bash and produce/read a list of filenames:



                declare -i num=0
                destination="$PWD" # set to destination of files
                find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
                num=$(($num + 1 ))
                # following line assumes no more than 99 files
                j=printf "%02d" $num
                cp "$fn" "$destination/$j.gif"
                done





                share|improve this answer














                It's easy! You can count in bash and produce/read a list of filenames:



                declare -i num=0
                destination="$PWD" # set to destination of files
                find . -type f -name 'ycut2.gif` -print | sort | while read fn ; do
                num=$(($num + 1 ))
                # following line assumes no more than 99 files
                j=printf "%02d" $num
                cp "$fn" "$destination/$j.gif"
                done






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 14 at 15:13

























                answered May 14 at 0:21









                waltinator

                20.3k73968




                20.3k73968






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1035886%2ffind-rename-and-copy-files-to-a-new-directory%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How do so many people here on Academia.SE, and in general, afford lavish higher education programs?

                    Trouble downloading packages list due to a “Hash sum mismatch” error

                    How do I move numbers in filenames, in a batch renaming operation?