Renaming many files to their parent directory name [duplicate]












1















This question already has an answer here:




  • Rename files in directory according to name of directory

    3 answers



  • Rename file by its folder name

    4 answers



  • Rename files depending on their parent directory

    3 answers




I want to recursively change many files named raw.tex to parent-directory-hw.tex. Is there a simple scripting solution to this problem?



For example, running the script on



.
`-- root
|-- baz
| `-- raw.tex
|-- foo
| `-- bar
| `-- raw.tex
`-- spam
|-- eggs
| `-- raw.tex
`-- raw.tex


should result in



.
`-- root
|-- baz
| `-- baz-hw.tex
|-- foo
| `-- bar
| `-- bar-hw.tex
`-- spam
|-- eggs
| `-- eggs-hw.tex
`-- spam-hw.tex









share|improve this question















marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Dec 19 '18 at 7:47


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















    1















    This question already has an answer here:




    • Rename files in directory according to name of directory

      3 answers



    • Rename file by its folder name

      4 answers



    • Rename files depending on their parent directory

      3 answers




    I want to recursively change many files named raw.tex to parent-directory-hw.tex. Is there a simple scripting solution to this problem?



    For example, running the script on



    .
    `-- root
    |-- baz
    | `-- raw.tex
    |-- foo
    | `-- bar
    | `-- raw.tex
    `-- spam
    |-- eggs
    | `-- raw.tex
    `-- raw.tex


    should result in



    .
    `-- root
    |-- baz
    | `-- baz-hw.tex
    |-- foo
    | `-- bar
    | `-- bar-hw.tex
    `-- spam
    |-- eggs
    | `-- eggs-hw.tex
    `-- spam-hw.tex









    share|improve this question















    marked as duplicate by Kusalananda bash
    Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Dec 19 '18 at 7:47


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















      1












      1








      1








      This question already has an answer here:




      • Rename files in directory according to name of directory

        3 answers



      • Rename file by its folder name

        4 answers



      • Rename files depending on their parent directory

        3 answers




      I want to recursively change many files named raw.tex to parent-directory-hw.tex. Is there a simple scripting solution to this problem?



      For example, running the script on



      .
      `-- root
      |-- baz
      | `-- raw.tex
      |-- foo
      | `-- bar
      | `-- raw.tex
      `-- spam
      |-- eggs
      | `-- raw.tex
      `-- raw.tex


      should result in



      .
      `-- root
      |-- baz
      | `-- baz-hw.tex
      |-- foo
      | `-- bar
      | `-- bar-hw.tex
      `-- spam
      |-- eggs
      | `-- eggs-hw.tex
      `-- spam-hw.tex









      share|improve this question
















      This question already has an answer here:




      • Rename files in directory according to name of directory

        3 answers



      • Rename file by its folder name

        4 answers



      • Rename files depending on their parent directory

        3 answers




      I want to recursively change many files named raw.tex to parent-directory-hw.tex. Is there a simple scripting solution to this problem?



      For example, running the script on



      .
      `-- root
      |-- baz
      | `-- raw.tex
      |-- foo
      | `-- bar
      | `-- raw.tex
      `-- spam
      |-- eggs
      | `-- raw.tex
      `-- raw.tex


      should result in



      .
      `-- root
      |-- baz
      | `-- baz-hw.tex
      |-- foo
      | `-- bar
      | `-- bar-hw.tex
      `-- spam
      |-- eggs
      | `-- eggs-hw.tex
      `-- spam-hw.tex




      This question already has an answer here:




      • Rename files in directory according to name of directory

        3 answers



      • Rename file by its folder name

        4 answers



      • Rename files depending on their parent directory

        3 answers








      bash shell-script find rename






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 19 '18 at 7:45

























      asked Dec 19 '18 at 7:40









      Brian Fitzpatrick

      80611123




      80611123




      marked as duplicate by Kusalananda bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 19 '18 at 7:47


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by Kusalananda bash
      Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Dec 19 '18 at 7:47


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





























          active

          oldest

          votes






















          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes

          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre