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

Why did the soldiers of the North disobey Jon?

Help understanding this line - usage of くれる

How do I adjust encounters to challenge my lycanthrope players without negating their cool new abilities?

Would life always name the light from their sun "white"

Extract the characters before last colon

Alias for root of a polynomial

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

How to make a not so good looking person more appealing?

Why did the metro bus stop at each railway crossing, despite no warning indicating a train was coming?

How to rename a files in a directory

is it correct to say "When it started to rain, I was in the open air."

Why weren't the bells paid heed to in S8E5?

How to add block near a product image in a product detail page in Magento 2

Is there any way to adjust the damage type of the Eldritch Blast cantrip so that it does fire damage?

Uh oh, the propeller fell off

Tube from Heathrow to King's Cross

Substring join or additional table, which is faster?

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

Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?

"The van's really booking"

Why didn't the Avengers use this object earlier?

Holding rent money for my friend which amounts to over $10k?

How about space ziplines

Is this possible when it comes to the relations of P, NP, NP-Hard and NP-Complete?



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;








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






























    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


























      1












      1








      1


      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 4 hours ago







      Rocky86

















      asked 4 hours ago









      Rocky86Rocky86

      7919




      7919




















          3 Answers
          3






          active

          oldest

          votes


















          2














          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






























            2














            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.


























              1














              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









                2














                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



























                  2














                  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

























                    2












                    2








                    2







                    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.3k5114129




                    49.3k5114129























                        2














                        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














                          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












                            2








                            2







                            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 3 hours ago









                            SHawardenSHawarden

                            312




                            312




                            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.























                                1














                                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.























                                  1














                                  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.





















                                    1












                                    1








                                    1







                                    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 3 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

                                    1215




                                    1215




                                    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

                                        Log på Navigationsmenu

                                        Wonderful Copenhagen (sang) Eksterne henvisninger | NavigationsmenurSide på frankloesser.comWonderful Copenhagen

                                        Detroit Tigers Spis treści Historia | Skład zespołu | Sukcesy | Członkowie Baseball Hall of Fame | Zastrzeżone numery | Przypisy | Menu nawigacyjneEncyclopedia of Detroit - Detroit TigersTigers Stadium, Detroit, MITigers Timeline 1900sDetroit Tigers Team History & EncyclopediaTigers Timeline 1910s1935 World Series1945 World Series1945 World Series1984 World SeriesComerica Park, Detroit, MI2006 World Series2012 World SeriesDetroit Tigers 40-Man RosterDetroit Tigers Coaching StaffTigers Hall of FamersTigers Retired Numberse