Logo supple-pixels.net @ bash scripts

Welcome to supple-pixels.net

chnames.sh

This bash script I originally wrote when I wanted to rename lots of files which contained not only spaces, umlauts, and accented characters, but also all sorts of adventurous characters such as () [] {} <> ; : ' & + and several more. You can use chnames.sh with any file and directory names as long as they are encoded in UTF-8, ISO-8859-1 or ASCII.

chnames.sh can ...

  • rename files and directories by substituting certain characters and character strings according to predefined rules. This can be done for single files, whole directories, or also recursively.
  • perform pure test runs, which only tell you what the names looked like if they would be renamed.
  • create log files containing the names before and after renaming.
  • generate an undo script which enables you to undo all the changes.
  • simply check whether there are undesirable characters in any names (= all except: A-Z a-z 0-9 ~._-).

Substitution rules

On renaming chnames.sh performs the following substitutions:

Character Becomes
() [] {} <> -
space _
Ä Ö Ü ä ö ü ß Ae Oe Ue ae oe ue ss
+ & _and_ (= default), or: _und_ (with -g)
° _deg_ (= default), or: _Grad_ (with -g)
: ; .
, If followed by space: _
Else: .
' " ` ´ ? ! ^ # * ¿ ¡ , Are removed.
accented characters Become characters without accent:
ÀÁÂÃÅ-A àáâãå-a
Æ-AE æ-ae
ÇĆĈĊČ-C çćĉċč-c
ÈÉÊË-E èéêë-e
ÌÍÎÏ-I ìíîï-i
Ñ-N ñ-n
ÒÓÔÕØ-O òóôõø-o
ŚŜ ŞŠ-S śŝşš-s
ÙÚÛ-U ùúû-u
Ý-Y ýÿ-y
ŹŻ Ž-Z ź żž-z
several of: space - _ . ~ Are reduced to one character.
- at the beginning Is removed.

Important note

chnames.sh will only work correctly when run in a UTF-8 shell. The script itself contains characters outside of the ISO-8859-1 range, and therefore has to remain UTF-8 encoded!

If your system does not use UTF-8 yet but you would like to make use of chnames.sh anyway, here you will find some brief information.

Dependencies

  • sed
  • iconv
  • less
  • UTF-8 terminal
  • bash (at least version 3)

Downloads

chnames.sh is licensed under the GNU General Public License. It is placed to your free disposal according to the terms of the GPL. More detailed information you can find on http://www.gnu.org/copyleft/gpl.html, or in the file COPYING enclosed with the script.

» Download chnames_070427.tar.gz

MD5 Sum: 399ca37ed0cfe782525022b17bccdcdf

Incidentally, the German version of this script you can find here.

For testing purposes here you can also download an archive containing weird but possible file names:

» Download chnames_testfilenames.tar.gz

MD5 Sum: b1249ea2182682a1cccb45ebdfec4f5d

Screenshots

   

Short information on UTF-8

  • Provided that the locale you intend to use is installed, you canstart an xterm using a command like

    LANG=de_US.UTF-8 xterm or
    LANG=de_GB.UTF-8 xterm

    For the unicode characters to be displayed correctly, of course an appropriate unicode font has to be installed (ISO-10646). If even so an xterm does not display all of the characters contained in the substitution table, using another terminal might be a solution. I really like working with urxvt (= rxvt-unicode).
    The above-mentioned command works fine for other programmes such as konsole, or gnome-terminal too.

  • The command "locale" shows you the current locale environment.
    With "locale -a" you get a list of all locales installed.

  • Useful tools:

    • convmv
      With this you can conveniently convert filenames to UTF-8, even recursively through many directories.
    • iconv, recode
      Both of these programmes are designed to convert file contents from and to various encodings.
    • file
      This programme most times is able to recognize file encodings properly.
  • Links:


If you'd like to give me feedback or make suggestions, just drop me an e-mail.

Conny

freshmeat.net
linuxlinks.com