[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] File migration quicky



Jay,

Quoting Jay Hannah <jhannah@omnihotels.com>:

Wrote this quick and dirty thing today.

*nix gods probably have a command-line way? I suppose I could Perl golf
it just for fun...

host:~ george$ cat move.sh
#!/bin/bash

if [ $# -ne 2 ]; then
  echo "Usage $0 <old> <new>"
  exit
fi

for entry in $1
do
  mv ${entry} ${entry/$1/$2}
done


host:~ george$ ls -ld /tmp/gg
drwxr-xr-x   4 george  wheel  136 Apr 16 01:40 /tmp/gg
host:~ george$ ./move.sh /tmp/gg/ /tmp/george/
host:~ george$ ls -ld /tmp/gg
ls: /tmp/gg: No such file or directory
host:~ george$ ls -ld /tmp/george
drwxr-xr-x   4 george  wheel  136 Apr 16 01:40 /tmp/george


... of course this script by itself doesn't do exactly what yours does, but it does show how nifty bash can be. I am sure you could 'find ... | xargs -n2 mv ...' to do the work of your .pl

Also, you might want to do a mkdir(dirname($new)) before your rename. Just incase your $dir2 doesn't have the same directory structure as $dir1 (unless, rename does that for you?)

Later,
George.