[Gllug] Mass renaming of files

Ian Norton bredroll at atari.org
Wed May 7 18:30:40 UTC 2003


heres my attempt :-) you can even give it a target directory :-)

cd $1;while [ `ls -Q|grep -c :` -gt 0 ];do
name=`ls|grep :|head -n 1`
mv -f $name `echo $name|sed -e 's/:/_/g'`
done

bredroll

On Wed, May 07, 2003 at 05:46:48PM +0100, Richard Jones wrote:
> On Wed, May 07, 2003 at 05:32:42PM +0100, Simon Morris wrote:
> > Hi GLLUGers,
> > 
> > I have a IRIX server at work providing file access for UNIX,Linux, MAC
> > OS 9 and various versions of Windows.
> > 
> > We have a problem where there are many filenames including colons :
> > 
> > Theses files are readable using Macs and UNIX OS's but the Windows
> > machines won't copy them from the server.
> > 
> > What is the best way to:
> > 
> > a) Find all the files under a certain directory where the filename
> > includes a :
> > 
> > b) Rename these files to replace the : with a - or possibly remove the
> > colon altogether.
> 
> Sounds like another shortest script challenge to me! Hmmmm ... I came
> up with the following rather crufy solution. It doesn't work if filenames
> contain double quotes.
> 
> find -name '*:*' | perl -e 'while(<>){chomp;print "mv \"$_\" "; $_ =~ tr/:/-/; print "\"$_\"\n"}' | less
> 
> Replace 'less' with 'sh' when you want to run the commands.
> 
> Rich.
> 
> -- 
> Richard Jones, Red Hat Inc. (London) and Merjis Ltd. http://www.merjis.com/
> http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
> PTHRLIB is a library for writing small, efficient and fast servers in C.
> HTTP, CGI, DBI, lightweight threads: http://www.annexia.org/freeware/pthrlib/
> 
> 
> -- 
> Gllug mailing list  -  Gllug at linux.co.uk
> http://list.ftech.net/mailman/listinfo/gllug

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS dpu s--: a-- C++++ UL++ P+++ L+++ E--- W-- N+ o K w---
O M-- V-- PS++ PE-- Y+ PGP+ t+++ 5++ X++ R+++ !tv b DI D----
G++ e+ h++ r++ y+++
------END GEEK CODE BLOCK------
----- Message of the Hour ------
Moooo :-)


-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list