[plug] Mass moving files with a script
Timothy White
weirdit at gmail.com
Wed Dec 6 10:32:50 WST 2006
On 12/6/06, Michael Holland <myk at myk.id.au> wrote:
> On Wed, 6 Dec 2006, Ben Woods wrote:
>
> > in the filenames etc... anyone good at bash scripting that can help me
> > out? The bit I am struggling with is really the string recognition /
> > analysis at the start.
>
> You need "regular expressions", one of the more amazingly useful things in
> Unix.
Honestly, for something "simple" like this, I wouldn't bother with regex's.
Totally untested...
--
#!/bin/bash
NEW_ROOT="/home/bob/newstructure"
for dir in '*'
do pushd $dir
for files in '*'
do $newdir = `echo $files | cut -d - -f 1`
mkdir -p $NEW_ROOT/$newdir
mv -i $files $NEW_ROOT/$newdir/
done
done
--
So be in the directory that contains "C/ D/ Q/" etc etc, and run this
script, and the new structure will be created under NEW_ROOT. Once
that's done, confirm all dirs are empty, or do 'rmdir *' and all empty
dir's will be deleted.
Give that a try.
Tim
--
Linux Counter user #273956
Don't email joeblogs at scouts.org.au
More information about the plug
mailing list