Results 1 to 4 of 4

Thread: Removing special characters from file names

  1. #1
    Join Date
    May 2009
    Location
    Fareham, UK
    Beans
    1,524
    Distro
    Ubuntu 16.04 Xenial Xerus

    Removing special characters from file names

    Trying to move all my music onto another hard drive to do a clean install (going back to jaunty) the only hard drive ive got big enough is my ipod, which works fine except that it work accept file names or directories with any of these characters in the name ? : ; *
    Im sure i can use the find command or something to find all these characters and replace them with . but i dont know the command.

    So i want to search ~/Music recursivley find all instances of :;*? and remove them, whats my command? im too dumb to figure it with the 'man find'
    Catch me on Freenode - imark

  2. #2
    Join Date
    Feb 2007
    Location
    perdita
    Beans
    1,625
    Distro
    Ubuntu

    Re: Removing special characters from file names

    This seems to work:
    Code:
    find ./Music/ \( -name "*\?*" -o -name "*:*" -o -name "*\;*" -o -name "*\**" \)
    After that, you can use "rename" to rename the files.
    I think there are a few renaming GUIs available too, but I don't know if they can search a directory recursively for patterns.

    edit:
    Renaming commands:
    Code:
    #replace "?" with ""
    find ./Music/ \( -name "*\?*" -o -name "*:*" -o -name "*\;*" -o -name "*\**" \) | xargs -n1 -I{} rename ? "" {}
    #replace ";" with ""
    find ./Music/ \( -name "*\?*" -o -name "*:*" -o -name "*\;*" -o -name "*\**" \) | xargs -n1 -I{} rename \; "" {}
    #replace ":" with ""
    find ./Music/ \( -name "*\?*" -o -name "*:*" -o -name "*\;*" -o -name "*\**" \) | xargs -n1 -I{} rename : "" {}
    #replace "*" with ""
    find ./Music/ \( -name "*\?*" -o -name "*:*" -o -name "*\;*" -o -name "*\**" \) | xargs -n1 -I{} rename \* "" {}
    WARNING: If you have for example "a?a" and "a:a" and use all of the above commands, both files will be renamed to "aa", so one of them will be overwritten!


    Removing command:
    Code:
    find ./Music/ \( -name "*\?*" -o -name "*:*" -o -name "*\;*" -o -name "*\**" \) | xargs -n1 -I{} rm -v {}
    Found the renaming apps I was thinking about again (and more):
    http://www.infinicode.org/code/pyrenamer/
    http://www.krename.net/
    http://thunar.xfce.org/pwiki/documentation/bulk_renamer
    http://linuxappfinder.com/package/mrename

    CLI info:
    http://tips.webdesign10.com/how-to-b...n-the-terminal
    http://www.devdaily.com/blog/post/li...lename-command
    http://www.softpanorama.org/Tools/Fi...tutorial.shtml
    Last edited by KIAaze; November 17th, 2009 at 10:20 PM.

  3. #3
    Join Date
    May 2009
    Location
    Fareham, UK
    Beans
    1,524
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Removing special characters from file names

    Thanks, solved
    Catch me on Freenode - imark

  4. #4
    Join Date
    Feb 2010
    Beans
    2

    Re: Removing special characters from file names

    I've looked around a lot for a tool that will do this, and found a few scripts, but nothing that would do exactly what I wanted.
    -Rename Directories and files
    -Output renames
    -Go recursively down a directory
    -If a file already exists by that name, append a number.

    After a bit I got frustrated, and wrote my own.
    http://code.google.com/p/archivemati...itizeNames.py?

    I hope someone else finds this useful.
    My co-worker should be making this into a package soonish.

    Other name for this is Name sanitization/sanitse filenames.

Bookmarks

Posting Permissions

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