changing multiple directory names

Hi guys,

I have lots of files that look like:

ABC.packed.dir
DEF.packed.dir
GHI.packed.dir

etc...

I would like them to have more of the usual naming convention

ABC
DEF
GHI

etc...

so I was thinking that I could:

for dirname in *.packed.dir 
do     
      rename $dirname.packed.dir $dirname *dirname.packed.dir 
done

but it doesn't work

can one of you guys help me,

Tabitha

Assuming you're using either Kshell or bash, this should work:

for dirname in *.packed.dir
do
      echo mv $dirname ${dirname%%.*}
done

When you run this and the output looks good, delete the echo from the line to actually do the rename.

The syntax ${dirname%%.*} removes the longest string starting with a dot (.) to the end of the string contained in dirname. This will chop everything from the first dot to the end of the original name resulting in something like:

mv foo.packed.dir foo

Hey there!
If you have the rename utility, which is a script written in Perl, you could do this:

rename 's/\.packed\.dir//' *.packed.dir