How to rename a files in a directoryHow to find the total number of occurrences of text and files with find commandHow can I rename all files in the current directory having a particular extension to another extension?How to rename files with sed and csvBatch renaming of filesHow do I copy multiple files by wildcard?Rename files depending on their parent directoryHow to zip files in a loop and move them to different directories?Rename files but retain files original time stamp in nameCommand to find and combine files matching a complex name patternUse scp to copy files of specific extension from directory

Can only the master initiate communication in SPI whereas in I2C the slave can also initiate the communication?

How about space ziplines

Generate ladder of integers using the least number of unique characters (in C++)

Why are BJTs common in output stages of power amplifiers?

Is it wrong to omit object pronouns in these sentences?

Tube from Heathrow to King's Cross

Why can't I share a one use code with anyone else?

What is this old US Air Force plane?

Should I communicate in my applications that I'm unemployed out of choice rather than because nobody will have me?

Why do the lights go out when someone enters the dining room on this ship?

Promotion comes with unexpected 24/7/365 on-call

Substring join or additional table, which is faster?

Was this seat-belt sign activation standard procedure?

Should generated documentation be stored in a Git repository?

Is there an academic word that means "to split hairs over"?

The meaning of the Middle English word “king”

Show solution to recurrence is never a square

How to redirect stdout to a file, and stdout+stderr to another one?

Do Grothendieck universes matter for an algebraic geometer?

How might a landlocked lake become a complete ecosystem?

What was the ring Varys took off?

Why was my Canon Speedlite 600EX triggering other flashes?

Single word that parallels "Recent" when discussing the near future

"The van's really booking"



How to rename a files in a directory


How to find the total number of occurrences of text and files with find commandHow can I rename all files in the current directory having a particular extension to another extension?How to rename files with sed and csvBatch renaming of filesHow do I copy multiple files by wildcard?Rename files depending on their parent directoryHow to zip files in a loop and move them to different directories?Rename files but retain files original time stamp in nameCommand to find and combine files matching a complex name patternUse scp to copy files of specific extension from directory






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I have directory say /var/tmp/abc which has 4 files as -



12345-ram-3e3r5-io9490-89adu9.csv

45434-dam-qwe35-to9490-43adu9.csv

11234-cam-yy3r5-ro9490-85adu9.csv

14423-sam-hh3r5-uo9490-869du9.csv



I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,



XXXXX-ram-3e3r5-io9490-89adu9.csv

XXXXX-dam-qwe35-to9490-43adu9.csv

XXXXX-cam-yy3r5-ro9490-85adu9.csv

XXXXX-sam-hh3r5-uo9490-869du9.csv









share






























    3















    I have directory say /var/tmp/abc which has 4 files as -



    12345-ram-3e3r5-io9490-89adu9.csv

    45434-dam-qwe35-to9490-43adu9.csv

    11234-cam-yy3r5-ro9490-85adu9.csv

    14423-sam-hh3r5-uo9490-869du9.csv



    I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,



    XXXXX-ram-3e3r5-io9490-89adu9.csv

    XXXXX-dam-qwe35-to9490-43adu9.csv

    XXXXX-cam-yy3r5-ro9490-85adu9.csv

    XXXXX-sam-hh3r5-uo9490-869du9.csv









    share


























      3












      3








      3


      1






      I have directory say /var/tmp/abc which has 4 files as -



      12345-ram-3e3r5-io9490-89adu9.csv

      45434-dam-qwe35-to9490-43adu9.csv

      11234-cam-yy3r5-ro9490-85adu9.csv

      14423-sam-hh3r5-uo9490-869du9.csv



      I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,



      XXXXX-ram-3e3r5-io9490-89adu9.csv

      XXXXX-dam-qwe35-to9490-43adu9.csv

      XXXXX-cam-yy3r5-ro9490-85adu9.csv

      XXXXX-sam-hh3r5-uo9490-869du9.csv









      share
















      I have directory say /var/tmp/abc which has 4 files as -



      12345-ram-3e3r5-io9490-89adu9.csv

      45434-dam-qwe35-to9490-43adu9.csv

      11234-cam-yy3r5-ro9490-85adu9.csv

      14423-sam-hh3r5-uo9490-869du9.csv



      I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,



      XXXXX-ram-3e3r5-io9490-89adu9.csv

      XXXXX-dam-qwe35-to9490-43adu9.csv

      XXXXX-cam-yy3r5-ro9490-85adu9.csv

      XXXXX-sam-hh3r5-uo9490-869du9.csv







      bash shell ksh





      share














      share












      share



      share








      edited 5 hours ago







      Rocky86

















      asked 5 hours ago









      Rocky86Rocky86

      8919




      8919




















          3 Answers
          3






          active

          oldest

          votes


















          4














          Try:



          for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done


          How it works:




          • for f in *.csv; do



            This starts a loop over all *.csv files.




          • mv -i -- "$f" "XXXXX-$f#*-"



            This renames the files as you want, asking interactively before overwriting any file.




          • done



            This marks the end of the loop.



          Example:



          $ ls -1
          11234-cam-yy3r5-ro9490-85adu9.csv
          12345-ram-3e3r5-io9490-89adu9.csv
          14423-sam-hh3r5-uo9490-869du9.csv
          45434-dam-qwe35-to9490-43adu9.csv
          $ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
          $ ls -1
          XXXXX-cam-yy3r5-ro9490-85adu9.csv
          XXXXX-dam-qwe35-to9490-43adu9.csv
          XXXXX-ram-3e3r5-io9490-89adu9.csv
          XXXXX-sam-hh3r5-uo9490-869du9.csv





          share|improve this answer






























            3














            rename -n 's/(w+)/XXXXX/' *.csv



            remove the -n when happy.






            share|improve this answer








            New contributor



            SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


























              2














              I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".



              Below, the files before the command.



              -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
              -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
              -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml


              Below, the one liner command.



              for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;


              Below, the files after the command.



              -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
              -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
              -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv


              Is that what you're looking for? :)



              References:



              Looping through command output in bash



              Substrings in bash






              share|improve this answer










              New contributor



              danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.



















                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%2f518800%2fhow-to-rename-a-files-in-a-directory%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                4














                Try:



                for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done


                How it works:




                • for f in *.csv; do



                  This starts a loop over all *.csv files.




                • mv -i -- "$f" "XXXXX-$f#*-"



                  This renames the files as you want, asking interactively before overwriting any file.




                • done



                  This marks the end of the loop.



                Example:



                $ ls -1
                11234-cam-yy3r5-ro9490-85adu9.csv
                12345-ram-3e3r5-io9490-89adu9.csv
                14423-sam-hh3r5-uo9490-869du9.csv
                45434-dam-qwe35-to9490-43adu9.csv
                $ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
                $ ls -1
                XXXXX-cam-yy3r5-ro9490-85adu9.csv
                XXXXX-dam-qwe35-to9490-43adu9.csv
                XXXXX-ram-3e3r5-io9490-89adu9.csv
                XXXXX-sam-hh3r5-uo9490-869du9.csv





                share|improve this answer



























                  4














                  Try:



                  for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done


                  How it works:




                  • for f in *.csv; do



                    This starts a loop over all *.csv files.




                  • mv -i -- "$f" "XXXXX-$f#*-"



                    This renames the files as you want, asking interactively before overwriting any file.




                  • done



                    This marks the end of the loop.



                  Example:



                  $ ls -1
                  11234-cam-yy3r5-ro9490-85adu9.csv
                  12345-ram-3e3r5-io9490-89adu9.csv
                  14423-sam-hh3r5-uo9490-869du9.csv
                  45434-dam-qwe35-to9490-43adu9.csv
                  $ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
                  $ ls -1
                  XXXXX-cam-yy3r5-ro9490-85adu9.csv
                  XXXXX-dam-qwe35-to9490-43adu9.csv
                  XXXXX-ram-3e3r5-io9490-89adu9.csv
                  XXXXX-sam-hh3r5-uo9490-869du9.csv





                  share|improve this answer

























                    4












                    4








                    4







                    Try:



                    for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done


                    How it works:




                    • for f in *.csv; do



                      This starts a loop over all *.csv files.




                    • mv -i -- "$f" "XXXXX-$f#*-"



                      This renames the files as you want, asking interactively before overwriting any file.




                    • done



                      This marks the end of the loop.



                    Example:



                    $ ls -1
                    11234-cam-yy3r5-ro9490-85adu9.csv
                    12345-ram-3e3r5-io9490-89adu9.csv
                    14423-sam-hh3r5-uo9490-869du9.csv
                    45434-dam-qwe35-to9490-43adu9.csv
                    $ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
                    $ ls -1
                    XXXXX-cam-yy3r5-ro9490-85adu9.csv
                    XXXXX-dam-qwe35-to9490-43adu9.csv
                    XXXXX-ram-3e3r5-io9490-89adu9.csv
                    XXXXX-sam-hh3r5-uo9490-869du9.csv





                    share|improve this answer













                    Try:



                    for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done


                    How it works:




                    • for f in *.csv; do



                      This starts a loop over all *.csv files.




                    • mv -i -- "$f" "XXXXX-$f#*-"



                      This renames the files as you want, asking interactively before overwriting any file.




                    • done



                      This marks the end of the loop.



                    Example:



                    $ ls -1
                    11234-cam-yy3r5-ro9490-85adu9.csv
                    12345-ram-3e3r5-io9490-89adu9.csv
                    14423-sam-hh3r5-uo9490-869du9.csv
                    45434-dam-qwe35-to9490-43adu9.csv
                    $ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
                    $ ls -1
                    XXXXX-cam-yy3r5-ro9490-85adu9.csv
                    XXXXX-dam-qwe35-to9490-43adu9.csv
                    XXXXX-ram-3e3r5-io9490-89adu9.csv
                    XXXXX-sam-hh3r5-uo9490-869du9.csv






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 4 hours ago









                    John1024John1024

                    49.4k5114129




                    49.4k5114129























                        3














                        rename -n 's/(w+)/XXXXX/' *.csv



                        remove the -n when happy.






                        share|improve this answer








                        New contributor



                        SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.























                          3














                          rename -n 's/(w+)/XXXXX/' *.csv



                          remove the -n when happy.






                          share|improve this answer








                          New contributor



                          SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





















                            3












                            3








                            3







                            rename -n 's/(w+)/XXXXX/' *.csv



                            remove the -n when happy.






                            share|improve this answer








                            New contributor



                            SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.









                            rename -n 's/(w+)/XXXXX/' *.csv



                            remove the -n when happy.







                            share|improve this answer








                            New contributor



                            SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.








                            share|improve this answer



                            share|improve this answer






                            New contributor



                            SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.








                            answered 4 hours ago









                            SHawardenSHawarden

                            412




                            412




                            New contributor



                            SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.




                            New contributor




                            SHawarden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                            Check out our Code of Conduct.























                                2














                                I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".



                                Below, the files before the command.



                                -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
                                -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
                                -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml


                                Below, the one liner command.



                                for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;


                                Below, the files after the command.



                                -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
                                -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
                                -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv


                                Is that what you're looking for? :)



                                References:



                                Looping through command output in bash



                                Substrings in bash






                                share|improve this answer










                                New contributor



                                danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.























                                  2














                                  I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".



                                  Below, the files before the command.



                                  -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
                                  -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
                                  -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml


                                  Below, the one liner command.



                                  for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;


                                  Below, the files after the command.



                                  -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
                                  -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
                                  -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv


                                  Is that what you're looking for? :)



                                  References:



                                  Looping through command output in bash



                                  Substrings in bash






                                  share|improve this answer










                                  New contributor



                                  danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.





















                                    2












                                    2








                                    2







                                    I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".



                                    Below, the files before the command.



                                    -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml


                                    Below, the one liner command.



                                    for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;


                                    Below, the files after the command.



                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv


                                    Is that what you're looking for? :)



                                    References:



                                    Looping through command output in bash



                                    Substrings in bash






                                    share|improve this answer










                                    New contributor



                                    danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.









                                    I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".



                                    Below, the files before the command.



                                    -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml


                                    Below, the one liner command.



                                    for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;


                                    Below, the files after the command.



                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
                                    -rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv


                                    Is that what you're looking for? :)



                                    References:



                                    Looping through command output in bash



                                    Substrings in bash







                                    share|improve this answer










                                    New contributor



                                    danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.








                                    share|improve this answer



                                    share|improve this answer








                                    edited 4 hours ago





















                                    New contributor



                                    danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.








                                    answered 4 hours ago









                                    danieldeveloper001danieldeveloper001

                                    1315




                                    1315




                                    New contributor



                                    danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.




                                    New contributor




                                    danieldeveloper001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.





























                                        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%2f518800%2fhow-to-rename-a-files-in-a-directory%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

                                        Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                        Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                        199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單