Changing a multiple file extension using single line command

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 some files whose names contain multiple extensions:



$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$


I want to rename them
to remove all the existing extensions and replace them with .txt. 
Output should be below:



$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt


Is it possible to use find and xargs command?










share|improve this question



















  • 1




    What happens in the situation of another file named File1_2345.R.1234? Why does the command need to be on a single line?
    – Jeff Schaller
    Aug 14 at 1:00














up vote
1
down vote

favorite












I have some files whose names contain multiple extensions:



$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$


I want to rename them
to remove all the existing extensions and replace them with .txt. 
Output should be below:



$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt


Is it possible to use find and xargs command?










share|improve this question



















  • 1




    What happens in the situation of another file named File1_2345.R.1234? Why does the command need to be on a single line?
    – Jeff Schaller
    Aug 14 at 1:00












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have some files whose names contain multiple extensions:



$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$


I want to rename them
to remove all the existing extensions and replace them with .txt. 
Output should be below:



$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt


Is it possible to use find and xargs command?










share|improve this question















I have some files whose names contain multiple extensions:



$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$


I want to rename them
to remove all the existing extensions and replace them with .txt. 
Output should be below:



$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt


Is it possible to use find and xargs command?







find filenames xargs mv






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Jeff Schaller

32.6k849110




32.6k849110










asked Aug 13 at 20:23









Aashish Raj

3516




3516







  • 1




    What happens in the situation of another file named File1_2345.R.1234? Why does the command need to be on a single line?
    – Jeff Schaller
    Aug 14 at 1:00












  • 1




    What happens in the situation of another file named File1_2345.R.1234? Why does the command need to be on a single line?
    – Jeff Schaller
    Aug 14 at 1:00







1




1




What happens in the situation of another file named File1_2345.R.1234? Why does the command need to be on a single line?
– Jeff Schaller
Aug 14 at 1:00




What happens in the situation of another file named File1_2345.R.1234? Why does the command need to be on a single line?
– Jeff Schaller
Aug 14 at 1:00










2 Answers
2






active

oldest

votes

















up vote
7
down vote













If you want to remove all extensions (everything after the first dot)
from each filename, do



$ for f in *
do
mv -- "$f" "$f%%.*.txt"
done


Of course, if you really want to do this in one line,
just collapse the above to



$ for f in *; do mv -- "$f" "$f%%.*.txt"; done





share|improve this answer





























    up vote
    1
    down vote













    You can do it with GNU Parallel:



    find ... | parallel mv '=s/..*//='.txt





    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%2f462380%2fchanging-a-multiple-file-extension-using-single-line-command%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      7
      down vote













      If you want to remove all extensions (everything after the first dot)
      from each filename, do



      $ for f in *
      do
      mv -- "$f" "$f%%.*.txt"
      done


      Of course, if you really want to do this in one line,
      just collapse the above to



      $ for f in *; do mv -- "$f" "$f%%.*.txt"; done





      share|improve this answer


























        up vote
        7
        down vote













        If you want to remove all extensions (everything after the first dot)
        from each filename, do



        $ for f in *
        do
        mv -- "$f" "$f%%.*.txt"
        done


        Of course, if you really want to do this in one line,
        just collapse the above to



        $ for f in *; do mv -- "$f" "$f%%.*.txt"; done





        share|improve this answer
























          up vote
          7
          down vote










          up vote
          7
          down vote









          If you want to remove all extensions (everything after the first dot)
          from each filename, do



          $ for f in *
          do
          mv -- "$f" "$f%%.*.txt"
          done


          Of course, if you really want to do this in one line,
          just collapse the above to



          $ for f in *; do mv -- "$f" "$f%%.*.txt"; done





          share|improve this answer














          If you want to remove all extensions (everything after the first dot)
          from each filename, do



          $ for f in *
          do
          mv -- "$f" "$f%%.*.txt"
          done


          Of course, if you really want to do this in one line,
          just collapse the above to



          $ for f in *; do mv -- "$f" "$f%%.*.txt"; done






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered Aug 13 at 21:20









          G-Man

          11.7k92658




          11.7k92658






















              up vote
              1
              down vote













              You can do it with GNU Parallel:



              find ... | parallel mv '=s/..*//='.txt





              share|improve this answer
























                up vote
                1
                down vote













                You can do it with GNU Parallel:



                find ... | parallel mv '=s/..*//='.txt





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  You can do it with GNU Parallel:



                  find ... | parallel mv '=s/..*//='.txt





                  share|improve this answer












                  You can do it with GNU Parallel:



                  find ... | parallel mv '=s/..*//='.txt






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 14 at 21:50









                  Ole Tange

                  11.4k1344103




                  11.4k1344103



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f462380%2fchanging-a-multiple-file-extension-using-single-line-command%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?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?