Name

lowercase - perform various file rename actions on multiple files

Synopsis


lowercase        [options] file(s)

mv_lowercase    ...
mv_uppercase    ...
mv_capitalize    ...
mv_spaces2underscore ...
mv_spaces2null ...
mv_underscore2hyphen ...
mv_number        ...
mv_number.ext    ...

mv_chars2underscore    [options] CHARS file(s)
mv_chars2null        ...

mv_prefix            [options] PREFIX file(s)
mv_suffix            ...

mv_sed            [options] SCRIPT file(s)

Options

-t    Test. Do not actually rename files.

-r    Recursively descend directories.

-f    Force. Forces renaming of non-unique files (backups made).

--    Signals the end of options.

-h    Help.

Description

Lowercase is a bash script that renames files and directories to their all lowercase equivalents. A log is printed to stdout, (and errors now go to stderr). Similarly, aliases perform ’like’ file renames.

mv_chars2null takes a list of chars and removes any occurence thereof from the filenames. (Similarly mv_chars2underscore translates these chars to underscores). Special characters should be enclosed in single quotes or preceded by a backslash. (See below for examples). Character classes can be specified within [: and :] where classes are one of the following: {alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit}. Other special character sequences are accepted (notably character ranges ’N-M’). For more info see the tr man and info pages.

mv_sed applies a sed script to every filename. By using an expression of the form ’s/target/replacement/’ substitutions can be made.
For more info see the sed man and info pages.

mv_prefix prepends text to the filename(s).
mv_suffix appends text to the filename(s).

mv_number renames files to sequential numbers.
mv_number.ext renames files to numbers but maintains the file’s extension.

Examples

Recursively lowercase all filenames in a directory:
   lowercase -r SomeDirectory

Rename all graphics files sequentially
   mv_number.ext *jpg *gif *png

Test replacing all spaces and tabs with underscores, supressing the output and only showing any rename failures:
   mv_spaces2underscore -t * >/dev/null

Remove all vfat illegal characters:
   mv_chars2null ’*?"<>|:\\’ File(s)

(note extra backslash for backslash)

Remove all digits:
   mv_chars2null ’[:digit:]’ File(s)

Replace all "jpeg" suffixes with "jpg":
   mv_sed ’s/\.jpeg/.jpg/’ *

Surround all digits with tildas (i.e. file.1 -> file.~1~):
   mv_sed ’s/[[:digit:]]/~&~/g’ *

(mv_sed classes need to be enclosed in double square brackets)

Notes

If in doubt, use the test option "-t" before actually renaming files.

Symbolic links are renamed, but not derefenced.

Lowercase works with vfat filesystems, space-embedded filenames, and remote directories (e.g. lowercase SomeDir/SomeFile).

The way short filenames on vfat file-systems (8.3 characters) are displayed varies according to the "shortname=" option of the mounted file-system. See the mount manpage for more info.

The force option [-f] now uses "mv --backup=numbered" to make backups of non-unique files. This is not applicable when the source or destination is a directory, in which case the file(s) are left unchanged.
- Earlier versions of gnu "mv" do not support this feature.

For programs that take an extra arg, a simple check is made that this arg is not a filename. The force option also causes this test to be skipped.

The test option [-t] is not comprehensive.
It reports inaccurately in two cases:

1. vfat filesystems will report fail on every
successful case-sensitive rename.
2. In cases where two distinct filenames map to a common (third) filename (e.g. lowercase Alpha alphA ) test will not report this conflict.

Files which don’t trigger the search criteria (e.g. all-lowercase,
or don’t match the pattern) are ignored and not reported in the log.

Bugs

The test feature is not fully implemented.
- No others known.

While this program has been written with care - and tested on an i386 linux, kernel 2.4.19 - no guarantee is made.

If anyone finds any bugs, or incompatibilities with versions of bash > 2.05b, please report such to the author, thanks.

Author

Steven Atkinson (stevenaaus (at) yahoo (dot) com)