Build a Renaming Script [closed] Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Build a Renaming Script [closed] without wasting too much if your time.

The question is published on by Tutorial Guruji team.

write a script that will check each folder/directory and rename the folder title if it contains the word “section.” The folder should be renamed to use the word “chapter” instead of “section”;Your script should be recursive, executing on each directory, subdirectory, and lower subdirectory, until all child directories have been checked and renamed.

For example:

should become:

My attempt (from directory above supersectiondir):

find /c/Users/cmd2/supersection -type d -exec sed -i 's/section/chapter/g' {} ; 

$ sh

sed: couldn't edit /c/Users/cmd2/supersection: not a regular file
sed: couldn't edit /c/Users/cmd2/supersection/subsection: not a regular file
sed: couldn't edit /c/Users/cmd2/supersection/subsection/lowersubsection: not a regular file 


The rename tool is extremely non-portable; there is almost nothing in common between the RHEL/CentOS/Fedora family version of rename and the version found on Ubuntu or Debian.

I wrote an answer giving example usage for both versions of rename a while back.

You haven’t said what OS you’re using, so it’s hard to be very specific—and since this is homework, you should do some work on it yourself so I will not spell out the answer even if you say which OS.

However, a couple of tips:

  • sed operates on the contents of a text file; it does not change the name of a file and certainly not the name of a directory. It cannot be used for that, and that’s why you get errors from the command you wrote.
  • You are on the correct track with your find command.
  • I suggest you look up the -name and -iname operators for find as they may come in handy (you don’t need to try to rename files that don’t match the given pattern).
  • Using -exec with rename (the appropriate version for your OS) is probably the easiest/best solution for this.
We are here to answer your question about Build a Renaming Script [closed] - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji