Search code examples
linuxmacosbashshellrsync

rename subfolder to parentfolder, remove 'extra' folder


got this problem when i messed up with an rsync and forgot to add a trailing slash.

So now i've got an extra folder.

Current foldertree

/Volumes/hd/images1/images1/
/Volumes/hd/images2/images2/
/Volumes/hd/images3/images3/

I wanted to get this

/Volumes/hd/images1/
/Volumes/hd/images2/
/Volumes/hd/images3/

Is there a way to get rid of the extra folder to get what i wanted, i tried to

mv /Volumes/hd/images1/images1/ /Volumes/hd/images1/

But got an error saying that they were identical, i also tried some basic php scripting to do the job for me, without any luck.

I cant delete or really copy the content of the folders since its a massive amount of data, i could do it manually by changing the name of the parent folder, then drag the subfolder to /hd and then delete the old parent. But its alot of work, so if anyone got a tip on how to do this, i'd be more than happy.

Im using Mac OS X if its of any interest


Solution

  • You should learn how to use shell commands, perhaps something like

     for f in /volumes/hd/* ; do
        b=$(basename $f)
        d=$(dirname $f)
        mv $f $d/$b.dir
        mv $d/$b.dir/* $f
     done
    

    check first that it does what you want by replacing mv with echo mv

    You really should learn how to use basic Unix commands (inside a terminal) on your MacOSX