Filename manipulation scripts

Bash script to convert filenames to lowercase and spaces in hypens

01#!/bin/bash
02 
03for x in ./*; do
04  if [ -f "$x" ]; then
05    lc=${x,,}            # convert all letters to lowercase
06    y=${lc// /-}         # replace spaces by hyphens
07    if [ "$x" != "$y" ]; then
08      mv "$x" "$y"
09    fi
10  fi
11done

Bash script to capitalise filenames recursively

1#!/bin/bash
2for i in /files/to/covert/directory/*.extension;
3    do new=`echo "$i" | sed -e 's/^./\U&/'`;
4    mv "$i" "$new";
5done;

Perl script to rename LOT of files based on a list with the wanted filenames

01#!/usr/bin/perl
02 
03my $dir = '/path/to/imgs/directory';
04my $names = '/path/to/file/with/the/wanted/names';
05my $files = '/path/to/file/with/the/real/name';
06 
07chdir $dir or
08    die "Could not change dir to $dir: $!\n";
09 
10open NAMES, $names or die "Could not open $names: $!\n";
11 
12open FILES, $files or die "Could not open $files: $!\n";
13 
14my $name = <NAMES>;
15chomp $name;
16 
17my $file = <FILES>;
18chomp $file;
19 
20while($name && $file) {
21    print "renaming $file to $name...\n";
22    rename $file, $name;
23    $name = <NAMES>;
24    chomp $name;
25    $file = <FILES>;
26    chomp $file;
27}
28 
29close NAMES;
30close FILES;

Tags: