Find the answer to your Linux question:
Results 1 to 4 of 4
Well, I was researching and trying to batch rename files, text fonts, I got the exploit of leaving them with the following name standard: What was ignoring the quotes, "fontname.ttf" ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Nov 2012
    Posts
    2

    Arrow Rename files in batch, considering only parts of their names.


    Well, I was researching and trying to batch rename files, text fonts, I got the exploit of leaving them with the following name standard:

    What was ignoring the quotes, "fontname.ttf" became "'echo nomedafonte.ttf | tr [AZ] [az]'." Dozens of font files became on this horrible thing: |

    I wish to return to "fontname.ttf." My primary goal was to make all files in lowercase, including extensions "*. TTF" to "*. Ttf". So, just who can solve the initial problem would also help in the matter of lowercase letters.

    As a suggestion, the process can be in stages: first deleting of all names the words "'echo" and then "| tr [AZ] [az]'"

    OBS.: In my research which certainly confirmed for the error was that many colleagues and in their eagerness to help beginners not explain what each command informed. I ask please that you inform the explanations, even if briefly, what each command.

    Thanks in advance, for all of us newbies, any help.
    A hug to everyone.

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Hello and welcome!

    Here is a short Bash script that will hopefully do what you want. Comments are provided in-line, to show what the code is doing.

    Code:
    #!/bin/bash
    
    # a Bash "while" loop which will iterate over the output of the find command
    # the "read" Bash built-in reads the lines of output line-by-line
    # the "file" is the name of the Bash variable the stores one line
    while read file; do
    
      # just echo to the screen what the current file name is, and that it will be named
      echo -en "\nRenaming file $file to "
    
      # the "new" variable will store the new filename
      # the first "sed" command strips off everything from the beginning of the line to "'echo "
      # the "cut" command will split the rest of the line on the "|" character and take everything to the left of it
      # the second "sed" command will strip off trailing white space
      new=$(echo $file|sed -e "s|^'echo[[:space:]]||"|cut -f1 -d'|'|sed -e 's|[[:space:]]$||')
    
      # echo the new filename to the screen
      echo "'$new'"
    
      # now rename (the "mv" command is basically a "rename") the old file with the new file name
      /bin/mv -v "$file" "$new"
    
    # the "done" just closed the "while" loop
    # the "find" command looks for all files in the current working dir (.), 
    # case-insensitive (-iname) with the string "'echo *.ttf*" in them
    # and prints juts the file name, without the parent directory 
    done < <(find . -type f -iname "'echo *.ttf*" -printf "%f\n")
    you'll want to run this script in the directory where your screwed up font files live.

  3. #3
    Just Joined!
    Join Date
    Nov 2012
    Posts
    2
    Dear Atreyu, WORKS!!
    I made a point to read each explanation before running the script. I confess I do not understand all the logic employed but was amazed to see all the running bash commands. I was watching the executions of each line as if seeing an action movie I know that your help will benefit many others. Thank you for your kindness.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Excellent! I wasn't sure...but glad it's sorted.

    I'll mark this thread as Solved for you. Do come back if/when you have more Linux questions!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •