Rimuovere Gli Spazi Dai Nomi Dei Files
Ecco alcuni script per rimuovere gli spazi dai nomi dei files:
questo e' il migliore, cerca ricorsivamente all'interno delle directory:
#! /usr/bin/perl
use File::Find;
finddepth sub { # finddepth so directories are done AFTER their contents
my $old = $_;
tr/ /_/ or return; # don't do anything if you don't have spaces
-e and return; # don't rename over an existing file!
rename $old, $_ or warn "cannot rename $old to $_: $!";
}, "."; # starting directory
altri ma non cosi' efficaci:
#!/bin/bash
#
# Writen by Mayuresh Phadke (mayuresh at gmail.com)# To change the names of all files in a directory including directory names
# run the command
#
# find . -depth -exec ~/rename.sh {} ;
#
# This command is pretty useful if you have a collection of songs or pictures transferred
# from your windows machine and you are finding it difficult to handle the
# spaces in the filenames on UNIX
#
#set -x
progname=`basename $0`
if [ $# != 1 ]
then
echo "Usage: $progname \"file name with spaces\""
echo
echo "This utility is useful for renaming files with spaces in the filename. Spaces in the filename are replaced with _"
echo "\"file name with spaces\" will be renamed to \"file_name_with_spaces\""
echo
exit 1
fi
old_name=$1
dir=`dirname "$1"`
file=`basename "$1"`
new_file=`echo $file|sed "s/ /_/g"`
new_name=$dir"/"$new_file
if [ "$old_name" != "$new_name" ]
then
mv "$old_name" "$new_name"
fi
exit 0
Ecco un altro modo che cerca anche nelle sottocartelle:
#!/bin/bash
for b in *
do
cd $b
for a in *
do
mv -v "$a" $(echo $a | sed 's/ /_/g')
done
done
