Bash script to convert filenames to lowercase and spaces in hypens
01 | #!/bin/bash |
02 |
03 | for 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 |
11 | done |
Bash script to capitalise filenames recursively
1 | #!/bin/bash |
2 | for i in /files/to/covert/directory/*.extension; |
3 | do new=` echo "$i" | sed -e 's/^./\U&/' `; |
4 | mv "$i" "$new" ; |
5 | done ; |
Perl script to rename LOT of files based on a list with the wanted filenames
01 | #!/usr/bin/perl |
02 |
03 | my $dir = '/path/to/imgs/directory' ; |
04 | my $names = '/path/to/file/with/the/wanted/names' ; |
05 | my $files = '/path/to/file/with/the/real/name' ; |
06 |
07 | chdir $dir or |
08 | die "Could not change dir to $dir: $!\n" ; |
09 |
10 | open NAMES, $names or die "Could not open $names: $!\n" ; |
11 |
12 | open FILES, $files or die "Could not open $files: $!\n" ; |
13 |
14 | my $name = <NAMES>; |
15 | chomp $name ; |
16 |
17 | my $file = <FILES>; |
18 | chomp $file ; |
19 |
20 | while ( $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 |
29 | close NAMES; |
30 | close FILES; |